]>
jfr.im git - yt-dlp.git/blob - test/test_post_hooks.py
5 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
7 from test
.helper
import get_params
, try_rm
, is_download_test
8 import yt_dlp
.YoutubeDL
9 from yt_dlp
.utils
import DownloadError
12 class YoutubeDL(yt_dlp
.YoutubeDL
):
13 def __init__(self
, *args
, **kwargs
):
14 super().__init
__(*args
, **kwargs
)
15 self
.to_stderr
= self
.to_screen
18 TEST_ID
= 'gr51aVj-mLg'
19 EXPECTED_NAME
= 'gr51aVj-mLg'
23 class TestPostHooks(unittest
.TestCase
):
25 self
.stored_name_1
= None
26 self
.stored_name_2
= None
27 self
.params
= get_params({
28 'skip_download': False,
29 'writeinfojson': False,
36 def test_post_hooks(self
):
37 self
.params
['post_hooks'] = [self
.hook_one
, self
.hook_two
]
38 ydl
= YoutubeDL(self
.params
)
39 ydl
.download([TEST_ID
])
40 self
.assertEqual(self
.stored_name_1
, EXPECTED_NAME
, 'Not the expected name from hook 1')
41 self
.assertEqual(self
.stored_name_2
, EXPECTED_NAME
, 'Not the expected name from hook 2')
43 def test_post_hook_exception(self
):
44 self
.params
['post_hooks'] = [self
.hook_three
]
45 ydl
= YoutubeDL(self
.params
)
46 self
.assertRaises(DownloadError
, ydl
.download
, [TEST_ID
])
48 def hook_one(self
, filename
):
49 self
.stored_name_1
, _
= os
.path
.splitext(os
.path
.basename(filename
))
50 self
.files
.append(filename
)
52 def hook_two(self
, filename
):
53 self
.stored_name_2
, _
= os
.path
.splitext(os
.path
.basename(filename
))
54 self
.files
.append(filename
)
56 def hook_three(self
, filename
):
57 self
.files
.append(filename
)
58 raise Exception('Test exception for \'%s\'' % filename
)
65 if __name__
== '__main__':