test_all_urls.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/env python3
  2. # Allow direct execution
  3. import os
  4. import sys
  5. import unittest
  6. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. import collections
  8. from test.helper import gettestcases
  9. from yt_dlp.extractor import FacebookIE, YoutubeIE, gen_extractors
  10. class TestAllURLsMatching(unittest.TestCase):
  11. def setUp(self):
  12. self.ies = gen_extractors()
  13. def matching_ies(self, url):
  14. return [ie.IE_NAME for ie in self.ies if ie.suitable(url) and ie.IE_NAME != 'generic']
  15. def assertMatch(self, url, ie_list):
  16. self.assertEqual(self.matching_ies(url), ie_list)
  17. def test_youtube_playlist_matching(self):
  18. assertPlaylist = lambda url: self.assertMatch(url, ['youtube:playlist'])
  19. assertTab = lambda url: self.assertMatch(url, ['youtube:tab'])
  20. assertPlaylist('ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
  21. assertPlaylist('UUBABnxM4Ar9ten8Mdjj1j0Q') # 585
  22. assertPlaylist('PL63F0C78739B09958')
  23. assertTab('https://www.youtube.com/AsapSCIENCE')
  24. assertTab('https://www.youtube.com/embedded')
  25. assertTab('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
  26. assertTab('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
  27. assertTab('https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012') # 668
  28. self.assertFalse('youtube:playlist' in self.matching_ies('PLtS2H6bU1M'))
  29. # Top tracks
  30. assertTab('https://www.youtube.com/playlist?list=MCUS.20142101')
  31. def test_youtube_matching(self):
  32. self.assertTrue(YoutubeIE.suitable('PLtS2H6bU1M'))
  33. self.assertFalse(YoutubeIE.suitable('https://www.youtube.com/watch?v=AV6J6_AeFEQ&playnext=1&list=PL4023E734DA416012')) # 668
  34. self.assertMatch('http://youtu.be/BaW_jenozKc', ['youtube'])
  35. # self.assertMatch('http://www.youtube.com/v/BaW_jenozKc', ['youtube']) # /v/ is no longer valid
  36. self.assertMatch('https://youtube.googleapis.com/v/BaW_jenozKc', ['youtube'])
  37. self.assertMatch('http://www.cleanvideosearch.com/media/action/yt/watch?videoId=8v_4O44sfjM', ['youtube'])
  38. def test_youtube_channel_matching(self):
  39. assertChannel = lambda url: self.assertMatch(url, ['youtube:tab'])
  40. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM')
  41. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM?feature=gb_ch_rec')
  42. assertChannel('https://www.youtube.com/channel/HCtnHdj3df7iM/videos')
  43. def test_youtube_user_matching(self):
  44. self.assertMatch('http://www.youtube.com/NASAgovVideo/videos', ['youtube:tab'])
  45. def test_youtube_feeds(self):
  46. self.assertMatch('https://www.youtube.com/feed/library', ['youtube:tab'])
  47. self.assertMatch('https://www.youtube.com/feed/history', ['youtube:tab'])
  48. self.assertMatch('https://www.youtube.com/feed/watch_later', ['youtube:tab'])
  49. self.assertMatch('https://www.youtube.com/feed/subscriptions', ['youtube:tab'])
  50. def test_youtube_search_matching(self):
  51. self.assertMatch('http://www.youtube.com/results?search_query=making+mustard', ['youtube:search_url'])
  52. self.assertMatch('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video', ['youtube:search_url'])
  53. def test_facebook_matching(self):
  54. self.assertTrue(FacebookIE.suitable('https://www.facebook.com/Shiniknoh#!/photo.php?v=10153317450565268'))
  55. self.assertTrue(FacebookIE.suitable('https://www.facebook.com/cindyweather?fref=ts#!/photo.php?v=10152183998945793'))
  56. def test_no_duplicates(self):
  57. ies = gen_extractors()
  58. for tc in gettestcases(include_onlymatching=True):
  59. url = tc['url']
  60. for ie in ies:
  61. if type(ie).__name__ in ('GenericIE', tc['name'] + 'IE'):
  62. self.assertTrue(ie.suitable(url), f'{type(ie).__name__} should match URL {url!r}')
  63. else:
  64. self.assertFalse(
  65. ie.suitable(url),
  66. f'{type(ie).__name__} should not match URL {url!r} . That URL belongs to {tc["name"]}.')
  67. def test_keywords(self):
  68. self.assertMatch(':ytsubs', ['youtube:subscriptions'])
  69. self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
  70. self.assertMatch(':ythistory', ['youtube:history'])
  71. def test_vimeo_matching(self):
  72. self.assertMatch('https://vimeo.com/channels/tributes', ['vimeo:channel'])
  73. self.assertMatch('https://vimeo.com/channels/31259', ['vimeo:channel'])
  74. self.assertMatch('https://vimeo.com/channels/31259/53576664', ['vimeo'])
  75. self.assertMatch('https://vimeo.com/user7108434', ['vimeo:user'])
  76. self.assertMatch('https://vimeo.com/user7108434/videos', ['vimeo:user'])
  77. self.assertMatch('https://vimeo.com/user21297594/review/75524534/3c257a1b5d', ['vimeo:review'])
  78. # https://github.com/ytdl-org/youtube-dl/issues/1930
  79. def test_soundcloud_not_matching_sets(self):
  80. self.assertMatch('http://soundcloud.com/floex/sets/gone-ep', ['soundcloud:set'])
  81. def test_tumblr(self):
  82. self.assertMatch('http://tatianamaslanydaily.tumblr.com/post/54196191430/orphan-black-dvd-extra-behind-the-scenes', ['Tumblr'])
  83. self.assertMatch('http://tatianamaslanydaily.tumblr.com/post/54196191430', ['Tumblr'])
  84. def test_pbs(self):
  85. # https://github.com/ytdl-org/youtube-dl/issues/2350
  86. self.assertMatch('http://video.pbs.org/viralplayer/2365173446/', ['pbs'])
  87. self.assertMatch('http://video.pbs.org/widget/partnerplayer/980042464/', ['pbs'])
  88. def test_no_duplicated_ie_names(self):
  89. name_accu = collections.defaultdict(list)
  90. for ie in self.ies:
  91. name_accu[ie.IE_NAME.lower()].append(type(ie).__name__)
  92. for (ie_name, ie_list) in name_accu.items():
  93. self.assertEqual(
  94. len(ie_list), 1,
  95. f'Multiple extractors with the same IE_NAME "{ie_name}" ({", ".join(ie_list)})')
  96. if __name__ == '__main__':
  97. unittest.main()