Skip to content

Commit

Permalink
Parse youtu.be and reel URLs using YouTube parser (#470)
Browse files Browse the repository at this point in the history
We are currently not using the YouTube parser when  parsing youtu.be
URLs and links to youtube reels. They are being parsed as normal URLs.
  • Loading branch information
jayjay-w authored Sep 13, 2024
1 parent a81c485 commit 8f057ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/parser/youtube_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Parser
class YoutubeItem < Base
include ProviderYoutube

YOUTUBE_ITEM_URL = /^https?:\/\/(www\.)?youtube\.com\/watch\?.*&?v=(?<id>[^&]+)&?/
YOUTUBE_ITEM_URL = /^https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|embed\/|v\/|shorts\/|playlist\?list=)?(?<id>[a-zA-Z0-9_-]{9,11})(\S+)?$/

DIRECT_ATTRIBUTES = %w[
description
Expand Down
5 changes: 5 additions & 0 deletions test/models/parser/youtube_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ def doc
assert_nil Parser::YoutubeItem.match?('https://www.youtube.com/user/portadosfundos')

match_one = Parser::YoutubeItem.match?('https://www.youtube.com/watch?v=mtLxD7r4BZQ')
match_two = Parser::YoutubeItem.match?('https://www.youtube.com/shorts/uZG3Y-ulMsc?si=yAE7bJpPPbsevBO7')
match_three = Parser::YoutubeItem.match?('https://youtu.be/cMQuVvFvSIA?si=JpFRMHlGMiQ6aMJO')

assert_equal true, match_one.is_a?(Parser::YoutubeItem)
assert_equal true, match_two.is_a?(Parser::YoutubeItem)
assert_equal true, match_three.is_a?(Parser::YoutubeItem)
end

test "should selectively assign YouTube fields to raw api data" do
Expand Down

0 comments on commit 8f057ca

Please sign in to comment.