def test_list_videos(config): youtube.Entry.api = youtube.scrAPI(proxy, headers) videos = youtube.scrAPI.list_videos(['_mTRvJ9fugM', 'h_uyq8oGDvU']) assert len(videos['items']) == 2
def on_start(self): proxy = httpclient.format_proxy(self.config['proxy']) youtube.Video.proxy = proxy headers = { 'user-agent': httpclient.format_user_agent(self.user_agent), 'Cookie': 'PREF=hl=en;', 'Accept-Language': 'en;q=0.8' } if youtube.api_enabled is True: if youtube.API.youtube_api_key is None: logger.error('No YouTube API key provided, disabling API') youtube.api_enabled = False else: youtube.Entry.api = youtube.API(proxy, headers) if youtube.Entry.search(q='test') is None: logger.error( 'Failed to verify YouTube API key, disabling API') youtube.api_enabled = False else: logger.info('YouTube API key verified') if youtube.api_enabled is False: logger.info('Using scrAPI') youtube.Entry.api = youtube.scrAPI(proxy, headers)
def test_audio_url_fail(youtube_dl_mock): youtube.Entry.api = youtube.scrAPI(proxy, headers) youtube_dl_mock.YoutubeDL.side_effect = Exception('Removed') video = youtube.Video.get('unknown') assert not video.audio_url.get()
def test_list_playlists(config): youtube.Entry.api = youtube.scrAPI(proxy, headers) playlists = youtube.scrAPI.list_playlists([ 'PLfGibfZATlGq6zF72No5BZaScBiWWb6U1', 'PLRHAVCbqFwJBkRupIhuGW3_XEIWc-ZYER' ]) assert len(playlists['items']) == 2
def test_get_video(config): youtube.Entry.api = youtube.scrAPI(proxy, headers) video = youtube.Video.get('e1YqueG2gtQ') assert video.length.get() # get again, should fetch from cache, _length should be ready video2 = youtube.Video.get('e1YqueG2gtQ') assert video2 is video assert video2._length
def test_search(config): youtube.Entry.api = youtube.scrAPI(proxy, headers) videos = youtube.Entry.search('chvrches') assert len(videos) == 30 assert videos[0]._title # should be ready assert videos[0]._channel # should be ready assert videos[0]._length # should be ready (scrAPI) video = youtube.Video.get('BZyzX4c1vIs') assert video in videos # cached
def test_get_playlist(config): youtube.Entry.api = youtube.scrAPI(proxy, headers) pl = youtube.Playlist.get('PLvdVG7oER2eFutjd4xl3TGNDui9ELvY4D') assert len(pl.videos.get()) == 20 assert pl.videos.get()[0].title.get() # Playlist.videos starts loading video info in the background video = pl.videos.get()[0] assert video._length # should be ready assert video.length.get() == 213 pl2 = youtube.Playlist.get('PLvdVG7oER2eFutjd4xl3TGNDui9ELvY4D') assert pl2 is pl # fetch from cache assert pl._videos # should be ready
def test_audio_url(youtube_dl_mock_with_video): youtube.Entry.api = youtube.scrAPI(proxy, headers) video = youtube.Video.get('e1YqueG2gtQ') assert video.audio_url.get()