diff --git a/app/models/parser/youtube_item.rb b/app/models/parser/youtube_item.rb index 63108680..8e56fad5 100644 --- a/app/models/parser/youtube_item.rb +++ b/app/models/parser/youtube_item.rb @@ -2,7 +2,7 @@ module Parser class YoutubeItem < Base include ProviderYoutube - YOUTUBE_ITEM_URL = /^https?:\/\/(www\.)?youtube\.com\/watch\?.*&?v=(?[^&]+)&?/ + YOUTUBE_ITEM_URL = /^https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|embed\/|v\/|shorts\/|playlist\?list=)?(?[a-zA-Z0-9_-]{9,11})(\S+)?$/ DIRECT_ATTRIBUTES = %w[ description diff --git a/test/models/parser/youtube_item_test.rb b/test/models/parser/youtube_item_test.rb index 3725398e..f105c4e5 100644 --- a/test/models/parser/youtube_item_test.rb +++ b/test/models/parser/youtube_item_test.rb @@ -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