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', '-H', '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', downloader
._make
_cmd
('test', TEST_INFO
))
89 # Test cookie header is added
90 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
91 self
.assertIn('--cookie', downloader
._make
_cmd
('test', TEST_INFO
))
92 self
.assertIn('test=ytdlp', downloader
._make
_cmd
('test', TEST_INFO
))
95 class TestAria2cFD(unittest
.TestCase
):
96 def test_make_cmd(self
):
97 with
FakeYDL() as ydl
:
98 downloader
= Aria2cFD(ydl
, {})
99 downloader
._make
_cmd
('test', TEST_INFO
)
100 self
.assertFalse(hasattr(downloader
, '_cookies_tempfile'))
102 # Test cookiejar tempfile arg is added
103 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
104 cmd
= downloader
._make
_cmd
('test', TEST_INFO
)
105 self
.assertIn(f
'--load-cookies={downloader._cookies_tempfile}', cmd
)
108 @unittest.skipUnless(FFmpegFD
.available(), 'ffmpeg not found')
109 class TestFFmpegFD(unittest
.TestCase
):
112 def _test_cmd(self
, args
):
115 def test_make_cmd(self
):
116 with
FakeYDL() as ydl
:
117 downloader
= FFmpegFD(ydl
, {})
118 downloader
._debug
_cmd
= self
._test
_cmd
120 downloader
._call
_downloader
('test', {**TEST_INFO
, 'ext': 'mp4'})
121 self
.assertEqual(self
._args
, [
122 'ffmpeg', '-y', '-hide_banner', '-i', 'http://www.example.com/',
123 '-c', 'copy', '-f', 'mp4', 'file:test'])
125 # Test cookies arg is added
126 ydl
.cookiejar
.set_cookie(http
.cookiejar
.Cookie(**TEST_COOKIE
))
127 downloader
._call
_downloader
('test', {**TEST_INFO
, 'ext': 'mp4'})
128 self
.assertEqual(self
._args
, [
129 'ffmpeg', '-y', '-hide_banner', '-cookies', 'test=ytdlp; path=/; domain=.example.com;\r\n',
130 '-i', 'http://www.example.com/', '-c', 'copy', '-f', 'mp4', 'file:test'])
132 # Test with non-url input (ffmpeg reads from stdin '-' for websockets)
133 downloader
._call
_downloader
('test', {'url': 'x', 'ext': 'mp4'})
134 self
.assertEqual(self
._args
, [
135 'ffmpeg', '-y', '-hide_banner', '-i', 'x', '-c', 'copy', '-f', 'mp4', 'file:test'])
138 if __name__
== '__main__':