Skip to content

Commit

Permalink
Support more YouTube URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jun 14, 2021
1 parent 03eba7a commit 90f78ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@
# https://www.youtube.com/playlist?list=PL0QrZvg7QIgpoLdNFnEePRrU-YJfr9Be7
elsif /youtube\.com\/(?<user>[^\/?#]+)/ =~ params[:q]
# https://www.youtube.com/khanacademy
elsif /youtu\.be\/(?<video_id>[^?#]+)/ =~ params[:q]
elsif /(?:youtu\.be|youtube\.com\/(?:embed|v))\/(?<video_id>[^?#]+)/ =~ params[:q]
# https://youtu.be/vVXbgbMp0oY?t=1s
# https://www.youtube.com/embed/vVXbgbMp0oY
# https://www.youtube.com/v/vVXbgbMp0oY
elsif /\b(?<channel_id>(?:UC[^\/?#]{22,}|S[^\/?#]{12,}))/ =~ params[:q]
# it's a channel id
else
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/05-string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def embed_html(request=nil)
<iframe width="1280" height="720" src="https://www.facebook.com/video/embed?video_id=#{id}" frameborder="0" scrolling="no" allowfullscreen referrerpolicy="no-referrer"></iframe>
<a href="https://www.facebook.com/video/embed?video_id=#{id}" rel="noreferrer">Open embed</a>
EOF
elsif %r{^https?://(?:www\.|m\.)youtube\.com/(?:.*?[?&#](v=(?<id>[^&#]+)|list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))+} =~ self || %r{^https?://(?:youtu\.be|(?:www\.)?youtube\.com/embed)/(?<id>[^?&#]+)(?:.*?[?&#](list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))*} =~ self
elsif %r{^https?://(?:www\.|m\.)youtube\.com/(?:.*?[?&#](v=(?<id>[^&#]+)|list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))+} =~ self || %r{^https?://(?:youtu\.be|(?:www\.)?youtube\.com/(?:embed|v))/(?<id>[^?&#]+)(?:.*?[?&#](?:list=(?<list>[^&#]+)|(?:t|time_continue)=(?<t>[^&#]+)))*} =~ self
# https://www.youtube.com/watch?v=z5OGD5_9cA0&list=PL0QrZvg7QIgpoLdNFnEePRrU-YJfr9Be7&index=3&t=30s
url = "https://www.youtube.com/embed/#{id}?rel=0"
url += "&list=#{list}" if list
Expand Down

0 comments on commit 90f78ab

Please sign in to comment.