3 # Allow direct execution
8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
12 from test
.helper
import FakeYDL
13 from yt_dlp
.downloader
.external
import (
27 'port_specified': False,
28 'domain': '.example.com',
29 'domain_specified': True,
30 'domain_initial_dot': False,
32 'path_specified': True,
41 TEST_INFO
= {'url': 'http://www.example.com/'}
44 class TestHttpieFD(unittest
.TestCase
):
45 def test_make_cmd(self
):
46 with FakeYDL() as ydl
:
47 downloader
= HttpieFD(ydl
, {})
49 downloader
._make
_cmd
('test', TEST_INFO
),
50 ['http', '--download', '--output', 'test', 'http://www.example.com/'])
52 # Test cookie header is added
53 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
55 downloader
._make
_cmd
('test', TEST_INFO
),
56 ['http', '--download', '--output', 'test', 'http://www.example.com/', 'Cookie:test=ytdlp'])
59 class TestAxelFD(unittest
.TestCase
):
60 def test_make_cmd(self
):
61 with FakeYDL() as ydl
:
62 downloader
= AxelFD(ydl
, {})
64 downloader
._make
_cmd
('test', TEST_INFO
),
65 ['axel', '-o', 'test', '--', 'http://www.example.com/'])
67 # Test cookie header is added
68 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
70 downloader
._make
_cmd
('test', TEST_INFO
),
71 ['axel', '-o', 'test', 'Cookie: test=ytdlp', '--max-redirect=0', '--', 'http://www.example.com/'])
74 class TestWgetFD(unittest
.TestCase
):
75 def test_make_cmd(self
):
76 with FakeYDL() as ydl
:
77 downloader
= WgetFD(ydl
, {})
78 self
.assertNotIn('--load-cookies', downloader
._make
_cmd
('test', TEST_INFO
))
79 # Test cookiejar tempfile arg is added
80 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
81 self
.assertIn('--load-cookies', downloader
._make
_cmd
('test', TEST_INFO
))
84 class TestCurlFD(unittest
.TestCase
):
85 def test_make_cmd(self
):
86 with FakeYDL() as ydl
:
87 downloader
= CurlFD(ydl
, {})
88 self
.assertNotIn('--cookie-jar', downloader
._make
_cmd
('test', TEST_INFO
))
89 # Test cookiejar tempfile arg is added
90 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
91 self
.assertIn('--cookie-jar', downloader
._make
_cmd
('test', TEST_INFO
))
94 class TestAria2cFD(unittest
.TestCase
):
95 def test_make_cmd(self
):
96 with FakeYDL() as ydl
:
97 downloader
= Aria2cFD(ydl
, {})
98 downloader
._make
_cmd
('test', TEST_INFO
)
99 self
.assertFalse(hasattr(downloader
, '_cookies_tempfile'))
101 # Test cookiejar tempfile arg is added
102 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
103 cmd
= downloader
._make
_cmd
('test', TEST_INFO
)
104 self
.assertIn(f
'--load-cookies={downloader._cookies_tempfile}', cmd
)
107 @unittest.skipUnless(FFmpegFD
.available(), 'ffmpeg not found')
108 class TestFFmpegFD(unittest
.TestCase
):
111 def _test_cmd(self
, args
):
114 def test_make_cmd(self
):
115 with FakeYDL() as ydl
:
116 downloader
= FFmpegFD(ydl
, {})
117 downloader
._debug
_cmd
= self
._test
_cmd
119 downloader
._call
_downloader
('test', {**TEST_INFO, 'ext': 'mp4'}
)
120 self
.assertEqual(self
._args
, [
121 'ffmpeg', '-y', '-hide_banner', '-i', 'http://www.example.com/',
122 '-c', 'copy', '-f', 'mp4', 'file:test'])
124 # Test cookies arg is added
125 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
126 downloader
._call
_downloader
('test', {**TEST_INFO, 'ext': 'mp4'}
)
127 self
.assertEqual(self
._args
, [
128 'ffmpeg', '-y', '-hide_banner', '-cookies', 'test=ytdlp; path=/; domain=.example.com;\r\n',
129 '-i', 'http://www.example.com/', '-c', 'copy', '-f', 'mp4', 'file:test'])
132 if __name__
== '__main__':