]>
jfr.im git - yt-dlp.git/blob - test/test_youtube_lists.py
7 # Allow direct execution
9 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from youtube_dl
.InfoExtractors
import YoutubeUserIE
, YoutubePlaylistIE
, YoutubeIE
12 from youtube_dl
.utils
import *
13 from youtube_dl
.FileDownloader
import FileDownloader
15 PARAMETERS_FILE
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "parameters.json")
16 with io
.open(PARAMETERS_FILE
, encoding
='utf-8') as pf
:
17 parameters
= json
.load(pf
)
19 # General configuration (from __init__, not very elegant...)
20 jar
= compat_cookiejar
.CookieJar()
21 cookie_processor
= compat_urllib_request
.HTTPCookieProcessor(jar
)
22 proxy_handler
= compat_urllib_request
.ProxyHandler()
23 opener
= compat_urllib_request
.build_opener(proxy_handler
, cookie_processor
, YoutubeDLHandler())
24 compat_urllib_request
.install_opener(opener
)
26 class FakeDownloader(FileDownloader
):
29 self
.params
= parameters
30 def to_screen(self
, s
):
34 def extract_info(self
, url
):
35 self
.result
.append(url
)
38 class TestYoutubeLists(unittest
.TestCase
):
39 def test_youtube_playlist(self
):
41 ie
= YoutubePlaylistIE(dl
)
42 ie
.extract('https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
43 ytie_results
= [YoutubeIE()._extract
_id
(url
) for url
in dl
.result
]
44 self
.assertEqual(ytie_results
, [ 'bV9L5Ht9LgY', 'FXxLjLQi3Fg', 'tU3Bgo5qJZE'])
46 def test_issue_673(self
):
48 ie
= YoutubePlaylistIE(dl
)
49 ie
.extract('PLBB231211A4F62143')
50 self
.assertTrue(len(dl
.result
) > 40)
52 def test_youtube_playlist_long(self
):
54 ie
= YoutubePlaylistIE(dl
)
55 ie
.extract('https://www.youtube.com/playlist?list=UUBABnxM4Ar9ten8Mdjj1j0Q')
56 self
.assertTrue(len(dl
.result
) >= 799)
58 def test_youtube_playlist_with_deleted(self
):
61 ie
= YoutubePlaylistIE(dl
)
62 ie
.extract('https://www.youtube.com/playlist?list=PLwP_SiAcdui0KVebT0mU9Apz359a4ubsC')
63 ytie_results
= [YoutubeIE()._extract
_id
(url
) for url
in dl
.result
]
64 self
.assertFalse('pElCt5oNDuI' in ytie_results
)
65 self
.assertFalse('KdPEApIVdWM' in ytie_results
)
67 def test_youtube_course(self
):
69 ie
= YoutubePlaylistIE(dl
)
70 # TODO find a > 100 (paginating?) videos course
71 ie
.extract('https://www.youtube.com/course?list=ECUl4u3cNGP61MdtwGTqZA0MreSaDybji8')
72 self
.assertEqual(YoutubeIE()._extract
_id
(dl
.result
[0]), 'j9WZyLZCBzs')
73 self
.assertEqual(len(dl
.result
), 25)
74 self
.assertEqual(YoutubeIE()._extract
_id
(dl
.result
[-1]), 'rYefUsYuEp0')
76 def test_youtube_channel(self
):
77 # I give up, please find a channel that does paginate and test this like test_youtube_playlist_long
80 def test_youtube_user(self
):
82 ie
= YoutubeUserIE(dl
)
83 ie
.extract('https://www.youtube.com/user/TheLinuxFoundation')
84 self
.assertTrue(len(dl
.result
) >= 320)
86 if __name__
== '__main__':