class BaseTestSubtitles(unittest.TestCase): url = None IE = None def setUp(self): self.DL = FakeYDL() self.ie = self.IE() self.DL.add_info_extractor(self.ie) if not self.IE.working(): print('Skipping: %s marked as not _WORKING' % self.IE.ie_key()) self.skipTest('IE marked as not _WORKING') def getInfoDict(self): info_dict = self.DL.extract_info(self.url, download=False) return info_dict def getSubtitles(self): info_dict = self.getInfoDict() subtitles = info_dict['requested_subtitles'] if not subtitles: return subtitles for sub_info in subtitles.values(): if sub_info.get('data') is None: uf = self.DL.urlopen(sub_info['url']) sub_info['data'] = uf.read().decode('utf-8') return dict((l, sub_info['data']) for l, sub_info in subtitles.items())
def test_youtube_playlist_noplaylist(self): dl = FakeYDL() dl.params['noplaylist'] = True dl.params['format'] = 'best' ie = YoutubePlaylistIE(dl) result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re') self.assertEqual(result['_type'], 'url') result = dl.extract_info(result['url'], download=False, ie_key=result.get('ie_key'), process=False) self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
def test_youtube_mix(self): dl = FakeYDL() dl.params['format'] = 'best' ie = YoutubeTabIE(dl) result = dl.extract_info('https://www.youtube.com/watch?v=uVJ0Il5WvbE&list=PLhQjrBD2T381k8ul4WQ8SQ165XqY149WW', download=False, ie_key=ie.ie_key(), process=True) entries = (result or {}).get('entries', [{'id': 'not_found', }]) self.assertTrue(len(entries) >= 50) original_video = entries[0] self.assertEqual(original_video['id'], 'uVJ0Il5WvbE')
def test_youtube_mix(self): dl = FakeYDL() dl.params['format'] = 'best' ie = YoutubeTabIE(dl) result = dl.extract_info( 'https://www.youtube.com/watch?v=tyITL_exICo&list=RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8', download=False, ie_key=ie.ie_key(), process=True) entries = (result or {}).get('entries', [{ 'id': 'not_found', }]) self.assertTrue(len(entries) >= 25) original_video = entries[0] self.assertEqual(original_video['id'], 'tyITL_exICo')
class BaseTestSubtitles(unittest.TestCase): url = None IE = None def setUp(self): self.DL = FakeYDL() self.ie = self.IE() self.DL.add_info_extractor(self.ie) def getInfoDict(self): info_dict = self.DL.extract_info(self.url, download=False) return info_dict def getSubtitles(self): info_dict = self.getInfoDict() subtitles = info_dict['requested_subtitles'] if not subtitles: return subtitles for sub_info in subtitles.values(): if sub_info.get('data') is None: uf = self.DL.urlopen(sub_info['url']) sub_info['data'] = uf.read().decode('utf-8') return {l: sub_info['data'] for l, sub_info in subtitles.items()}
class BaseTestSubtitles(unittest.TestCase): url = None IE = None def setUp(self): self.DL = FakeYDL() self.ie = self.IE() self.DL.add_info_extractor(self.ie) def getInfoDict(self): info_dict = self.DL.extract_info(self.url, download=False) return info_dict def getSubtitles(self): info_dict = self.getInfoDict() subtitles = info_dict['requested_subtitles'] if not subtitles: return subtitles for sub_info in subtitles.values(): if sub_info.get('data') is None: uf = self.DL.urlopen(sub_info['url']) sub_info['data'] = uf.read().decode('utf-8') return dict((l, sub_info['data']) for l, sub_info in subtitles.items())
class testSubtitles(unittest.TestCase): url = None IE = None #set up the youtube download download the video def setUp(self): self.DL = FakeYDL() self.ie = self.IE() self.DL.add_info_extractor(self.ie) #extract the info from the download def getInfoDict(self): info_dict = self.DL.extract_info(self.url, download=False) return info_dict #finally get the subtitles from the video def getSubtitles(self): info_dict = self.getInfoDict() subtitles = info_dict['requested_subtitles'] if not subtitles: return subtitles for sub_info in subtitles.values(): if sub_info.get('data') is None: uf = self.DL.urlopen(sub_info['url']) sub_info['data'] = uf.read().decode('utf-8') return dict((l, sub_info['data']) for l, sub_info in subtitles.items()) #--------------------------- test cases ---------------------------------- #final configuration of youtube page url = 'QRS8MkLhQmM' IE = YoutubeIE #-------test1: test that the subtitles have been extracted-------- def test_extraction(self): #get all the subtites in a variable self.DL.params['writesubtitles'] = True self.DL.params['allsubtitles'] = True subtitles = self.getSubtitles() #test that the subtitles are in english and proper format self.assertEqual(md5(subtitles['en']), 'ae1bd34126571a77aabd4d276b28044d') self.assertEqual(md5(subtitles['it']), '0e0b667ba68411d88fd1c5f4f4eab2f9') #-------test2: test that the subtitles are correct language-------- def test_language(self): #get all the subtites in a variable self.DL.params['writesubtitles'] = True self.DL.params['allsubtitles'] = True subtitles = self.getSubtitles() #test that the subtitles are not in any other language for lang in ['fr', 'de']: self.assertTrue(subtitles.get(lang) is not None, 'Subtitles for \'%s\' not extracted' % lang) #-------test3: test the auto captions-------- def test_auto_captions(self): #get all the subtitiles inthe variable self.DL.params['writeautomaticsub'] = True self.DL.params['subtitleslangs'] = ['it'] subtitles = self.getSubtitles() #test the automic capitions #self.assertTrue(subtitles['it'] is not None) #-------test4: test that chaning the format works properly-------- def test_format(self): #get all the subtitles in a variable self.DL.params['writesubtitles'] = True self.DL.params['subtitlesformat'] = 'ttml' subtitles = self.getSubtitles() #assert that the format is still correct self.assertEqual(md5(subtitles['en']), 'c97ddf1217390906fa9fbd34901f3da2') #get all the subtitles in a variable self.DL.params['writesubtitles'] = True self.DL.params['subtitlesformat'] = 'vtt' subtitles = self.getSubtitles() #assert that the format is still correct for vtt self.assertEqual(md5(subtitles['en']), 'c97dadgadf1217390906fa9fbd34901f3da2')