Skip to content

Commit

Permalink
Improve YouTube embed regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Nov 21, 2021
1 parent 4abc26f commit eb01d24
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion config/initializers/05-string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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|v))/(?<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\.|m\.)?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 eb01d24

Please sign in to comment.