diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_download.py | 20 | ||||
-rw-r--r-- | test/test_write_info_json.py | 12 | ||||
-rw-r--r-- | test/test_youtube_lists.py | 22 | ||||
-rw-r--r-- | test/test_youtube_subtitles.py | 22 | ||||
-rw-r--r-- | test/tests.json | 37 |
5 files changed, 76 insertions, 37 deletions
diff --git a/test/test_download.py b/test/test_download.py index 8d8698478..067bde4bb 100644 --- a/test/test_download.py +++ b/test/test_download.py @@ -13,7 +13,7 @@ import binascii # Allow direct execution sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import youtube_dl.FileDownloader +import youtube_dl.YoutubeDL import youtube_dl.extractor from youtube_dl.utils import * @@ -40,17 +40,17 @@ def _try_rm(filename): md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest() -class FileDownloader(youtube_dl.FileDownloader): +class YoutubeDL(youtube_dl.YoutubeDL): def __init__(self, *args, **kwargs): self.to_stderr = self.to_screen self.processed_info_dicts = [] - return youtube_dl.FileDownloader.__init__(self, *args, **kwargs) + super(YoutubeDL, self).__init__(*args, **kwargs) def report_warning(self, message): # Don't accept warnings during tests raise ExtractorError(message) def process_info(self, info_dict): self.processed_info_dicts.append(info_dict) - return youtube_dl.FileDownloader.process_info(self, info_dict) + return super(YoutubeDL, self).process_info(info_dict) def _file_md5(fn): with open(fn, 'rb') as f: @@ -86,14 +86,14 @@ def generator(test_case): params = self.parameters.copy() params.update(test_case.get('params', {})) - fd = FileDownloader(params) + ydl = YoutubeDL(params) for ie in youtube_dl.extractor.gen_extractors(): - fd.add_info_extractor(ie) + ydl.add_info_extractor(ie) finished_hook_called = set() def _hook(status): if status['status'] == 'finished': finished_hook_called.add(status['filename']) - fd.add_progress_hook(_hook) + ydl.fd.add_progress_hook(_hook) test_cases = test_case.get('playlist', [test_case]) for tc in test_cases: @@ -103,7 +103,7 @@ def generator(test_case): try: for retry in range(1, RETRIES + 1): try: - fd.download([test_case['url']]) + ydl.download([test_case['url']]) except (DownloadError, ExtractorError) as err: if retry == RETRIES: raise @@ -153,9 +153,11 @@ def generator(test_case): return test_template ### And add them to TestDownload -for test_case in defs: +for n, test_case in enumerate(defs): test_method = generator(test_case) test_method.__name__ = "test_{0}".format(test_case["name"]) + if getattr(TestDownload, test_method.__name__, False): + test_method.__name__ = "test_{0}_{1}".format(test_case["name"], n) setattr(TestDownload, test_method.__name__, test_method) del test_method diff --git a/test/test_write_info_json.py b/test/test_write_info_json.py index b5eca7649..de6d5180f 100644 --- a/test/test_write_info_json.py +++ b/test/test_write_info_json.py @@ -9,7 +9,7 @@ import unittest # Allow direct execution sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import youtube_dl.FileDownloader +import youtube_dl.YoutubeDL import youtube_dl.extractor from youtube_dl.utils import * @@ -22,9 +22,9 @@ proxy_handler = compat_urllib_request.ProxyHandler() opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) compat_urllib_request.install_opener(opener) -class FileDownloader(youtube_dl.FileDownloader): +class YoutubeDL(youtube_dl.YoutubeDL): def __init__(self, *args, **kwargs): - youtube_dl.FileDownloader.__init__(self, *args, **kwargs) + super(YoutubeDL, self).__init__(*args, **kwargs) self.to_stderr = self.to_screen with io.open(PARAMETERS_FILE, encoding='utf-8') as pf: @@ -49,9 +49,9 @@ class TestInfoJSON(unittest.TestCase): def test_info_json(self): ie = youtube_dl.extractor.YoutubeIE() - fd = FileDownloader(params) - fd.add_info_extractor(ie) - fd.download([TEST_ID]) + ydl = YoutubeDL(params) + ydl.add_info_extractor(ie) + ydl.download([TEST_ID]) self.assertTrue(os.path.exists(INFO_JSON_FILE)) with io.open(INFO_JSON_FILE, 'r', encoding='utf-8') as jsonf: jd = json.load(jsonf) diff --git a/test/test_youtube_lists.py b/test/test_youtube_lists.py index 2c46edfa6..320b44082 100644 --- a/test/test_youtube_lists.py +++ b/test/test_youtube_lists.py @@ -10,7 +10,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from youtube_dl.extractor import YoutubeUserIE, YoutubePlaylistIE, YoutubeIE, YoutubeChannelIE from youtube_dl.utils import * -from youtube_dl.FileDownloader import FileDownloader +from youtube_dl import YoutubeDL PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json") with io.open(PARAMETERS_FILE, encoding='utf-8') as pf: @@ -23,7 +23,7 @@ proxy_handler = compat_urllib_request.ProxyHandler() opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) compat_urllib_request.install_opener(opener) -class FakeDownloader(FileDownloader): +class FakeYDL(YoutubeDL): def __init__(self): self.result = [] self.params = parameters @@ -41,7 +41,7 @@ class TestYoutubeLists(unittest.TestCase): self.assertEqual(info['_type'], 'playlist') def test_youtube_playlist(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')[0] self.assertIsPlaylist(result) @@ -50,13 +50,13 @@ class TestYoutubeLists(unittest.TestCase): self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE']) def test_issue_673(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) result = ie.extract('PLBB231211A4F62143')[0] self.assertTrue(len(result['entries']) > 25) def test_youtube_playlist_long(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')[0] self.assertIsPlaylist(result) @@ -64,7 +64,7 @@ class TestYoutubeLists(unittest.TestCase): def test_youtube_playlist_with_deleted(self): #651 - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')[0] ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']] @@ -72,14 +72,14 @@ class TestYoutubeLists(unittest.TestCase): self.assertFalse('KdPEApIVdWM' in ytie_results) def test_youtube_playlist_empty(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')[0] self.assertIsPlaylist(result) self.assertEqual(len(result['entries']), 0) def test_youtube_course(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) # TODO find a > 100 (paginating?) videos course result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')[0] @@ -89,7 +89,7 @@ class TestYoutubeLists(unittest.TestCase): self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0') def test_youtube_channel(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubeChannelIE(dl) #test paginated channel result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0] @@ -99,13 +99,13 @@ class TestYoutubeLists(unittest.TestCase): self.assertTrue(len(result['entries']) >= 18) def test_youtube_user(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubeUserIE(dl) result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')[0] self.assertTrue(len(result['entries']) >= 320) def test_youtube_safe_search(self): - dl = FakeDownloader() + dl = FakeYDL() ie = YoutubePlaylistIE(dl) result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')[0] self.assertEqual(len(result['entries']), 2) diff --git a/test/test_youtube_subtitles.py b/test/test_youtube_subtitles.py index 129e23963..e8f5e4ae7 100644 --- a/test/test_youtube_subtitles.py +++ b/test/test_youtube_subtitles.py @@ -12,7 +12,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from youtube_dl.extractor import YoutubeIE from youtube_dl.utils import * -from youtube_dl import FileDownloader +from youtube_dl import YoutubeDL PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json") with io.open(PARAMETERS_FILE, encoding='utf-8') as pf: @@ -25,7 +25,7 @@ proxy_handler = compat_urllib_request.ProxyHandler() opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler()) compat_urllib_request.install_opener(opener) -class FakeDownloader(FileDownloader): +class FakeYDL(YoutubeDL): def __init__(self): self.result = [] # Different instances of the downloader can't share the same dictionary @@ -42,27 +42,27 @@ md5 = lambda s: hashlib.md5(s.encode('utf-8')).hexdigest() class TestYoutubeSubtitles(unittest.TestCase): def setUp(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['allsubtitles'] = False DL.params['writesubtitles'] = False DL.params['subtitlesformat'] = 'srt' DL.params['listsubtitles'] = False def test_youtube_no_subtitles(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['writesubtitles'] = False IE = YoutubeIE(DL) info_dict = IE.extract('QRS8MkLhQmM') subtitles = info_dict[0]['subtitles'] self.assertEqual(subtitles, None) def test_youtube_subtitles(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['writesubtitles'] = True IE = YoutubeIE(DL) info_dict = IE.extract('QRS8MkLhQmM') sub = info_dict[0]['subtitles'][0] self.assertEqual(md5(sub[2]), '4cd9278a35ba2305f47354ee13472260') def test_youtube_subtitles_it(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['writesubtitles'] = True DL.params['subtitleslang'] = 'it' IE = YoutubeIE(DL) @@ -70,7 +70,7 @@ class TestYoutubeSubtitles(unittest.TestCase): sub = info_dict[0]['subtitles'][0] self.assertEqual(md5(sub[2]), '164a51f16f260476a05b50fe4c2f161d') def test_youtube_onlysubtitles(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['writesubtitles'] = True DL.params['onlysubtitles'] = True IE = YoutubeIE(DL) @@ -78,14 +78,14 @@ class TestYoutubeSubtitles(unittest.TestCase): sub = info_dict[0]['subtitles'][0] self.assertEqual(md5(sub[2]), '4cd9278a35ba2305f47354ee13472260') def test_youtube_allsubtitles(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['allsubtitles'] = True IE = YoutubeIE(DL) info_dict = IE.extract('QRS8MkLhQmM') subtitles = info_dict[0]['subtitles'] self.assertEqual(len(subtitles), 13) def test_youtube_subtitles_format(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['writesubtitles'] = True DL.params['subtitlesformat'] = 'sbv' IE = YoutubeIE(DL) @@ -93,13 +93,13 @@ class TestYoutubeSubtitles(unittest.TestCase): sub = info_dict[0]['subtitles'][0] self.assertEqual(md5(sub[2]), '13aeaa0c245a8bed9a451cb643e3ad8b') def test_youtube_list_subtitles(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['listsubtitles'] = True IE = YoutubeIE(DL) info_dict = IE.extract('QRS8MkLhQmM') self.assertEqual(info_dict, None) def test_youtube_automatic_captions(self): - DL = FakeDownloader() + DL = FakeYDL() DL.params['writesubtitles'] = True DL.params['subtitleslang'] = 'it' IE = YoutubeIE(DL) diff --git a/test/tests.json b/test/tests.json index 01367b0fb..f6a70f153 100644 --- a/test/tests.json +++ b/test/tests.json @@ -12,6 +12,32 @@ } }, { + "name": "Youtube", + "url": "http://www.youtube.com/watch?v=1ltcDfZMA3U", + "file": "1ltcDfZMA3U.flv", + "note": "Test VEVO video (#897)", + "info_dict": { + "upload_date": "20070518", + "title": "Maps - It Will Find You", + "description": "Music video by Maps performing It Will Find You.", + "uploader": "MuteUSA", + "uploader_id": "MuteUSA" + } + }, + { + "name": "Youtube", + "url": "http://www.youtube.com/watch?v=UxxajLWwzqY", + "file": "UxxajLWwzqY.mp4", + "note": "Test generic use_cipher_signature video (#897)", + "info_dict": { + "upload_date": "20120506", + "title": "Icona Pop - I Love It (feat. Charli XCX) [OFFICIAL VIDEO]", + "description": "md5:b085c9804f5ab69f4adea963a2dceb3c", + "uploader": "IconaPop", + "uploader_id": "IconaPop" + } + }, + { "name": "Dailymotion", "md5": "392c4b85a60a90dc4792da41ce3144eb", "url": "http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech", @@ -649,5 +675,16 @@ "info_dict": { "title": "When Girls Act Like D-Bags" } + }, + { + "name": "Vevo", + "url": "http://www.vevo.com/watch/hurts/somebody-to-die-for/GB1101300280", + "file": "GB1101300280.mp4", + "md5": "06bea460acb744eab74a9d7dcb4bfd61", + "info_dict": { + "title": "Somebody To Die For", + "upload_date": "20130624", + "uploader": "Hurts" + } } ] |