Use the new class in the tests
This commit is contained in:
parent
8222d8de88
commit
8bf8b5a577
@ -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.extractor import YoutubeUserIE, YoutubePlaylistIE, YoutubeIE, YoutubeChannelIE
|
||||||
from youtube_dl.utils import *
|
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")
|
PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
|
||||||
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
|
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())
|
opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
|
||||||
compat_urllib_request.install_opener(opener)
|
compat_urllib_request.install_opener(opener)
|
||||||
|
|
||||||
class FakeDownloader(FileDownloader):
|
class FakeYDL(YoutubeDL):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.result = []
|
self.result = []
|
||||||
self.params = parameters
|
self.params = parameters
|
||||||
@ -41,7 +41,7 @@ class TestYoutubeLists(unittest.TestCase):
|
|||||||
self.assertEqual(info['_type'], 'playlist')
|
self.assertEqual(info['_type'], 'playlist')
|
||||||
|
|
||||||
def test_youtube_playlist(self):
|
def test_youtube_playlist(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')[0]
|
result = ie.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')[0]
|
||||||
self.assertIsPlaylist(result)
|
self.assertIsPlaylist(result)
|
||||||
@ -50,13 +50,13 @@ class TestYoutubeLists(unittest.TestCase):
|
|||||||
self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
|
self.assertEqual(ytie_results, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
|
||||||
|
|
||||||
def test_issue_673(self):
|
def test_issue_673(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
result = ie.extract('PLBB231211A4F62143')[0]
|
result = ie.extract('PLBB231211A4F62143')[0]
|
||||||
self.assertTrue(len(result['entries']) > 25)
|
self.assertTrue(len(result['entries']) > 25)
|
||||||
|
|
||||||
def test_youtube_playlist_long(self):
|
def test_youtube_playlist_long(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')[0]
|
result = ie.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')[0]
|
||||||
self.assertIsPlaylist(result)
|
self.assertIsPlaylist(result)
|
||||||
@ -64,7 +64,7 @@ class TestYoutubeLists(unittest.TestCase):
|
|||||||
|
|
||||||
def test_youtube_playlist_with_deleted(self):
|
def test_youtube_playlist_with_deleted(self):
|
||||||
#651
|
#651
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')[0]
|
result = ie.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')[0]
|
||||||
ytie_results = [YoutubeIE()._extract_id(url['url']) for url in result['entries']]
|
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)
|
self.assertFalse('KdPEApIVdWM' in ytie_results)
|
||||||
|
|
||||||
def test_youtube_playlist_empty(self):
|
def test_youtube_playlist_empty(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')[0]
|
result = ie.extract('https://www.youtube.com/playlist?list=PLtPgu7CB4gbZDA7i_euNxn75ISqxwZPYx')[0]
|
||||||
self.assertIsPlaylist(result)
|
self.assertIsPlaylist(result)
|
||||||
self.assertEqual(len(result['entries']), 0)
|
self.assertEqual(len(result['entries']), 0)
|
||||||
|
|
||||||
def test_youtube_course(self):
|
def test_youtube_course(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
# TODO find a > 100 (paginating?) videos course
|
# TODO find a > 100 (paginating?) videos course
|
||||||
result = ie.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')[0]
|
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')
|
self.assertEqual(YoutubeIE()._extract_id(entries[-1]['url']), 'rYefUsYuEp0')
|
||||||
|
|
||||||
def test_youtube_channel(self):
|
def test_youtube_channel(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubeChannelIE(dl)
|
ie = YoutubeChannelIE(dl)
|
||||||
#test paginated channel
|
#test paginated channel
|
||||||
result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0]
|
result = ie.extract('https://www.youtube.com/channel/UCKfVa3S1e4PHvxWcwyMMg8w')[0]
|
||||||
@ -99,13 +99,13 @@ class TestYoutubeLists(unittest.TestCase):
|
|||||||
self.assertTrue(len(result['entries']) >= 18)
|
self.assertTrue(len(result['entries']) >= 18)
|
||||||
|
|
||||||
def test_youtube_user(self):
|
def test_youtube_user(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubeUserIE(dl)
|
ie = YoutubeUserIE(dl)
|
||||||
result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')[0]
|
result = ie.extract('https://www.youtube.com/user/TheLinuxFoundation')[0]
|
||||||
self.assertTrue(len(result['entries']) >= 320)
|
self.assertTrue(len(result['entries']) >= 320)
|
||||||
|
|
||||||
def test_youtube_safe_search(self):
|
def test_youtube_safe_search(self):
|
||||||
dl = FakeDownloader()
|
dl = FakeYDL()
|
||||||
ie = YoutubePlaylistIE(dl)
|
ie = YoutubePlaylistIE(dl)
|
||||||
result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')[0]
|
result = ie.extract('PLtPgu7CB4gbY9oDN3drwC3cMbJggS7dKl')[0]
|
||||||
self.assertEqual(len(result['entries']), 2)
|
self.assertEqual(len(result['entries']), 2)
|
||||||
|
@ -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.extractor import YoutubeIE
|
||||||
from youtube_dl.utils import *
|
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")
|
PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json")
|
||||||
with io.open(PARAMETERS_FILE, encoding='utf-8') as pf:
|
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())
|
opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
|
||||||
compat_urllib_request.install_opener(opener)
|
compat_urllib_request.install_opener(opener)
|
||||||
|
|
||||||
class FakeDownloader(FileDownloader):
|
class FakeYDL(YoutubeDL):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.result = []
|
self.result = []
|
||||||
# Different instances of the downloader can't share the same dictionary
|
# 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):
|
class TestYoutubeSubtitles(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['allsubtitles'] = False
|
DL.params['allsubtitles'] = False
|
||||||
DL.params['writesubtitles'] = False
|
DL.params['writesubtitles'] = False
|
||||||
DL.params['subtitlesformat'] = 'srt'
|
DL.params['subtitlesformat'] = 'srt'
|
||||||
DL.params['listsubtitles'] = False
|
DL.params['listsubtitles'] = False
|
||||||
def test_youtube_no_subtitles(self):
|
def test_youtube_no_subtitles(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['writesubtitles'] = False
|
DL.params['writesubtitles'] = False
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
info_dict = IE.extract('QRS8MkLhQmM')
|
info_dict = IE.extract('QRS8MkLhQmM')
|
||||||
subtitles = info_dict[0]['subtitles']
|
subtitles = info_dict[0]['subtitles']
|
||||||
self.assertEqual(subtitles, None)
|
self.assertEqual(subtitles, None)
|
||||||
def test_youtube_subtitles(self):
|
def test_youtube_subtitles(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['writesubtitles'] = True
|
DL.params['writesubtitles'] = True
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
info_dict = IE.extract('QRS8MkLhQmM')
|
info_dict = IE.extract('QRS8MkLhQmM')
|
||||||
sub = info_dict[0]['subtitles'][0]
|
sub = info_dict[0]['subtitles'][0]
|
||||||
self.assertEqual(md5(sub[2]), '4cd9278a35ba2305f47354ee13472260')
|
self.assertEqual(md5(sub[2]), '4cd9278a35ba2305f47354ee13472260')
|
||||||
def test_youtube_subtitles_it(self):
|
def test_youtube_subtitles_it(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['writesubtitles'] = True
|
DL.params['writesubtitles'] = True
|
||||||
DL.params['subtitleslang'] = 'it'
|
DL.params['subtitleslang'] = 'it'
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
@ -70,7 +70,7 @@ class TestYoutubeSubtitles(unittest.TestCase):
|
|||||||
sub = info_dict[0]['subtitles'][0]
|
sub = info_dict[0]['subtitles'][0]
|
||||||
self.assertEqual(md5(sub[2]), '164a51f16f260476a05b50fe4c2f161d')
|
self.assertEqual(md5(sub[2]), '164a51f16f260476a05b50fe4c2f161d')
|
||||||
def test_youtube_onlysubtitles(self):
|
def test_youtube_onlysubtitles(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['writesubtitles'] = True
|
DL.params['writesubtitles'] = True
|
||||||
DL.params['onlysubtitles'] = True
|
DL.params['onlysubtitles'] = True
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
@ -78,14 +78,14 @@ class TestYoutubeSubtitles(unittest.TestCase):
|
|||||||
sub = info_dict[0]['subtitles'][0]
|
sub = info_dict[0]['subtitles'][0]
|
||||||
self.assertEqual(md5(sub[2]), '4cd9278a35ba2305f47354ee13472260')
|
self.assertEqual(md5(sub[2]), '4cd9278a35ba2305f47354ee13472260')
|
||||||
def test_youtube_allsubtitles(self):
|
def test_youtube_allsubtitles(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['allsubtitles'] = True
|
DL.params['allsubtitles'] = True
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
info_dict = IE.extract('QRS8MkLhQmM')
|
info_dict = IE.extract('QRS8MkLhQmM')
|
||||||
subtitles = info_dict[0]['subtitles']
|
subtitles = info_dict[0]['subtitles']
|
||||||
self.assertEqual(len(subtitles), 13)
|
self.assertEqual(len(subtitles), 13)
|
||||||
def test_youtube_subtitles_format(self):
|
def test_youtube_subtitles_format(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['writesubtitles'] = True
|
DL.params['writesubtitles'] = True
|
||||||
DL.params['subtitlesformat'] = 'sbv'
|
DL.params['subtitlesformat'] = 'sbv'
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
@ -93,13 +93,13 @@ class TestYoutubeSubtitles(unittest.TestCase):
|
|||||||
sub = info_dict[0]['subtitles'][0]
|
sub = info_dict[0]['subtitles'][0]
|
||||||
self.assertEqual(md5(sub[2]), '13aeaa0c245a8bed9a451cb643e3ad8b')
|
self.assertEqual(md5(sub[2]), '13aeaa0c245a8bed9a451cb643e3ad8b')
|
||||||
def test_youtube_list_subtitles(self):
|
def test_youtube_list_subtitles(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['listsubtitles'] = True
|
DL.params['listsubtitles'] = True
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
info_dict = IE.extract('QRS8MkLhQmM')
|
info_dict = IE.extract('QRS8MkLhQmM')
|
||||||
self.assertEqual(info_dict, None)
|
self.assertEqual(info_dict, None)
|
||||||
def test_youtube_automatic_captions(self):
|
def test_youtube_automatic_captions(self):
|
||||||
DL = FakeDownloader()
|
DL = FakeYDL()
|
||||||
DL.params['writesubtitles'] = True
|
DL.params['writesubtitles'] = True
|
||||||
DL.params['subtitleslang'] = 'it'
|
DL.params['subtitleslang'] = 'it'
|
||||||
IE = YoutubeIE(DL)
|
IE = YoutubeIE(DL)
|
||||||
|
Loading…
Reference in New Issue
Block a user