Exemplo n.º 1
0
    def test_search_only_channels_20_results(self):
        html_code = read_in_file('tests/htmls/search_channels_20_results.txt')
        found_channels = YoutubeApi(FakeFetcher(html_code)).search_channels('')
        self.assertEqual(len(found_channels), 20)
        for channel in found_channels:
            self.assertIsInstance(channel, ChannelSignature)

        signature = ChannelSignature(
            'UC3N5y6UWKJaKqoU2b_0MfTQ', 'LanaDelReyVEVO', '31', '3 947 232',
            'https://yt3.ggpht.com/-JXK6ocQ08J8/AAAAAAAAAAI/' +
            'AAAAAAAAAAA/aGPAhXfQpMw/s176-c-k-no/photo.jpg')

        self.assertTrue(signature in found_channels)
        invalid_signature = ChannelSignature(' ', ' ', ' ', ' ', ' ')
        self.assertTrue(invalid_signature not in found_channels)
Exemplo n.º 2
0
 def test_search_17_results(self):
     html_code = read_in_file('tests/htmls/search_mixed_17_results.txt')
     found_videos = YoutubeApi(FakeFetcher(html_code)).search_videos('')
     self.assertEqual(len(found_videos), 17)
     for video in found_videos:
         self.assertIsInstance(video, VideoSignature)
     signature = VideoSignature('JRWox-i6aAk', 'Lana Del Rey - Blue Jeans',
                                'LanaDelReyVEVO', '146576399', '4:21')
     self.assertTrue(signature in found_videos)
     invalid_signature = VideoSignature(' ', ' ', ' ', ' ', ' ')
     self.assertTrue(invalid_signature not in found_videos)
     self.assertEqual(
         found_videos[0].get_thumbnail_url(),
         "https://i.ytimg.com/vi/{}/mqdefault.jpg".format(
             found_videos[0].get_id()))
Exemplo n.º 3
0
 def test_api_search(self):
     html_code = read_in_file('tests/htmls/search_mixed_17_results.txt')
     found_items = YoutubeApi(FakeFetcher(html_code)).search('')
     self.assertEqual(len(found_items), 20)
     videos = [
         item for item in found_items if isinstance(item, VideoSignature)
     ]
     playlists = [
         item for item in found_items if isinstance(item, PlaylistSignature)
     ]
     channels = [
         item for item in found_items if isinstance(item, ChannelSignature)
     ]
     self.assertEqual(len(videos), 17)
     self.assertEqual(len(playlists), 1)
     self.assertEqual(len(channels), 2)
Exemplo n.º 4
0
 def test_api_get_video(self):
     html_code = read_in_file('tests/htmls/video_sample_source.txt')
     video = YoutubeApi(FakeFetcher(html_code)).get_video('nVjsGKrE6E8')
     self.assertEqual(video.get_id(), 'nVjsGKrE6E8')
     self.assertEqual(video.get_url(), 'https://www.youtube.com/watch?v=nVjsGKrE6E8')
     self.assertEqual(video.get_title(), 'Lana Del Rey - Summertime Sadness')
     self.assertEqual(video.get_author(), 'UCqk3CdGN_j8IR9z4uBbVPSg')
     self.assertEqual(video.get_views(), '247990936')
     self.assertTrue(video.get_length(), '4:43')
     self.assertEqual(video.get_length_in_seconds(), 283)
     self.assertIsInstance(video.get_next_video(), VideoSignature)
     self.assertEqual(len(video.get_related_videos()), 17)
     self.assertEqual(video.get_thumbnail_url(),
                      "https://i.ytimg.com/vi/{}/mqdefault.jpg".format(
                       video.get_id()))
     for video in video.get_related_videos():
         self.assertIsInstance(video, VideoSignature)
Exemplo n.º 5
0
    def test_search_only_playlists_20_results(self):
        html_code = read_in_file('tests/htmls/search_playlists_20_results.txt')
        found_playlists = YoutubeApi(
                                 FakeFetcher(html_code)).search_playlists('')
        self.assertEqual(len(found_playlists), 20)
        for playlist in found_playlists:
            self.assertIsInstance(playlist, PlaylistSignature)

        signature = PlaylistSignature('PLLUYFDT7vPkqBZQsTGBpGCjIoePETnOxi',
                                      'Lana Del Rey - All songs playlist',
                                      '119', 'juluatanaya',
                            'https://i.ytimg.com/vi/nVjsGKrE6E8/mqdefault.jpg',
                                      'nVjsGKrE6E8')

        self.assertTrue(signature in found_playlists)
        invalid_signature = PlaylistSignature(' ', ' ', ' ', ' ', ' ', ' ')
        self.assertTrue(invalid_signature not in found_playlists)
Exemplo n.º 6
0
 def test_api_get_playlist(self):
     html_code = read_in_file('tests/htmls/playlist_sample_source.txt')
     playlist = YoutubeApi(FakeFetcher(html_code)).get_playlist(
         'PLLUYFDT7vPkqBZQsTGBpGCjIoePETnOxi')
     self.assertEqual(playlist.get_id(),
                      'PLLUYFDT7vPkqBZQsTGBpGCjIoePETnOxi')
     self.assertEqual(playlist.get_name(),
                      'Lana Del Rey - All songs playlist')
     self.assertEqual(playlist.get_author(), 'juluatanaya')
     self.assertEqual(int(playlist.get_length()), 118)
     self.assertEqual(
         playlist.get_url(), 'https://www.youtube.com/playlist?list=' +
         'PLLUYFDT7vPkqBZQsTGBpGCjIoePETnOxi')
     self.assertEqual(playlist.get_thumbnail_url(),
                      'https://i.ytimg.com/vi/cE6wxDqdOV0/mqdefault.jpg')
     video = playlist.get_video(0)
     self.assertEqual(video.get_id(), 'nVjsGKrE6E8')
     self.assertEqual(video.get_title(),
                      'Lana Del Rey - Summertime Sadness')
     self.assertEqual(video.get_author(), 'LanaDelRey')
     self.assertTrue(video.get_length(), '4:43')
     for video in playlist.get_videos():
         self.assertIsInstance(video, VideoSignature)
Exemplo n.º 7
0
 def test_youtubevideo_constructor(self):
     html_code = read_in_file('tests/htmls/video_sample_source.txt')
     video = YoutubeApi(FakeFetcher(html_code)).get_video('           ')
     self.assertTrue(video is not None)
Exemplo n.º 8
0
 def test_api_search_no_results(self):
     html_code = read_in_file('tests/htmls/search_no_results.txt')
     found_items = YoutubeApi(FakeFetcher(html_code)).search('')
     self.assertEqual(len(found_items), 0)
Exemplo n.º 9
0
 def test_youtubeplaylist_constructor(self):
     html_code = read_in_file('tests/htmls/playlist_sample_source.txt')
     playlist = YoutubeApi(
         FakeFetcher(html_code)).get_playlist('PL        ')
     self.assertTrue(playlist is not None)
Exemplo n.º 10
0
 def test_search_only_videos_20_results(self):
     html_code = read_in_file('tests/htmls/search_videos_20_results.txt')
     found_videos = YoutubeApi(FakeFetcher(html_code)).search_videos('')
     self.assertEqual(len(found_videos), 20)
     for video in found_videos:
         self.assertIsInstance(video, VideoSignature)