]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_youtube_lists.py
debian/watch: Update to track github tags.
[youtubedl] / test / test_youtube_lists.py
1 #!/usr/bin/env python
2
3 import sys
4 import unittest
5 import socket
6
7 # Allow direct execution
8 import os
9 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
11 from youtube_dl.InfoExtractors import YoutubePlaylistIE
12 from youtube_dl.utils import *
13
14 # General configuration (from __init__, not very elegant...)
15 jar = compat_cookiejar.CookieJar()
16 cookie_processor = compat_urllib_request.HTTPCookieProcessor(jar)
17 proxy_handler = compat_urllib_request.ProxyHandler()
18 opener = compat_urllib_request.build_opener(proxy_handler, cookie_processor, YoutubeDLHandler())
19 compat_urllib_request.install_opener(opener)
20 socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
21
22 class FakeDownloader(object):
23 def __init__(self):
24 self.result = []
25 self.params = {}
26 def to_screen(self, s):
27 print(s)
28 def trouble(self, s):
29 raise Exception(s)
30 def download(self, x):
31 self.result.append(x)
32
33 class TestYoutubeLists(unittest.TestCase):
34 def test_youtube_playlist(self):
35 DL = FakeDownloader()
36 IE = YoutubePlaylistIE(DL)
37 IE.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
38 self.assertEqual(DL.result, [
39 ['http://www.youtube.com/watch?v=bV9L5Ht9LgY'],
40 ['http://www.youtube.com/watch?v=FXxLjLQi3Fg'],
41 ['http://www.youtube.com/watch?v=tU3Bgo5qJZE']
42 ])
43
44 def test_youtube_playlist_long(self):
45 DL = FakeDownloader()
46 IE = YoutubePlaylistIE(DL)
47 IE.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
48 self.assertTrue(len(DL.result) >= 799)
49
50 def test_youtube_course(self):
51 DL = FakeDownloader()
52 IE = YoutubePlaylistIE(DL)
53 # TODO find a > 100 (paginating?) videos course
54 IE.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
55 self.assertEqual(DL.result[0], ['http://www.youtube.com/watch?v=j9WZyLZCBzs'])
56 self.assertEqual(len(DL.result), 25)
57 self.assertEqual(DL.result[-1], ['http://www.youtube.com/watch?v=rYefUsYuEp0'])
58
59 def test_youtube_channel(self):
60 """I give up, please find a channel that does paginate and test this like test_youtube_playlist_long"""
61 pass # TODO
62
63 def test_youtube_user(self):
64 DL = FakeDownloader()
65 IE = YoutubePlaylistIE(DL)
66 IE.extract('https://www.youtube.com/user/TheLinuxFoundation')
67 self.assertTrue(len(DL.result) >= 320)
68
69 if __name__ == '__main__':
70 unittest.main()