mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-19 01:16:40 +00:00
[test:download] Support playlist_maxcount
(#13433)
Authored by: InvalidUsernameException
This commit is contained in:
parent
99093e96fd
commit
fd36b8f31b
@ -14,6 +14,7 @@ import json
|
|||||||
|
|
||||||
from test.helper import (
|
from test.helper import (
|
||||||
assertGreaterEqual,
|
assertGreaterEqual,
|
||||||
|
assertLessEqual,
|
||||||
expect_info_dict,
|
expect_info_dict,
|
||||||
expect_warnings,
|
expect_warnings,
|
||||||
get_params,
|
get_params,
|
||||||
@ -121,10 +122,13 @@ def generator(test_case, tname):
|
|||||||
params = get_params(test_case.get('params', {}))
|
params = get_params(test_case.get('params', {}))
|
||||||
params['outtmpl'] = tname + '_' + params['outtmpl']
|
params['outtmpl'] = tname + '_' + params['outtmpl']
|
||||||
if is_playlist and 'playlist' not in test_case:
|
if is_playlist and 'playlist' not in test_case:
|
||||||
params.setdefault('extract_flat', 'in_playlist')
|
params.setdefault('playlistend', max(
|
||||||
params.setdefault('playlistend', test_case.get(
|
test_case.get('playlist_mincount', -1),
|
||||||
'playlist_mincount', test_case.get('playlist_count', -2) + 1))
|
test_case.get('playlist_count', -2) + 1,
|
||||||
|
test_case.get('playlist_maxcount', -2) + 1))
|
||||||
params.setdefault('skip_download', True)
|
params.setdefault('skip_download', True)
|
||||||
|
if 'playlist_duration_sum' not in test_case:
|
||||||
|
params.setdefault('extract_flat', 'in_playlist')
|
||||||
|
|
||||||
ydl = YoutubeDL(params, auto_init=False)
|
ydl = YoutubeDL(params, auto_init=False)
|
||||||
ydl.add_default_info_extractors()
|
ydl.add_default_info_extractors()
|
||||||
@ -159,6 +163,7 @@ def generator(test_case, tname):
|
|||||||
try_rm(os.path.splitext(tc_filename)[0] + '.info.json')
|
try_rm(os.path.splitext(tc_filename)[0] + '.info.json')
|
||||||
try_rm_tcs_files()
|
try_rm_tcs_files()
|
||||||
try:
|
try:
|
||||||
|
test_url = test_case['url']
|
||||||
try_num = 1
|
try_num = 1
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -166,7 +171,7 @@ def generator(test_case, tname):
|
|||||||
# for outside error handling, and returns the exit code
|
# for outside error handling, and returns the exit code
|
||||||
# instead of the result dict.
|
# instead of the result dict.
|
||||||
res_dict = ydl.extract_info(
|
res_dict = ydl.extract_info(
|
||||||
test_case['url'],
|
test_url,
|
||||||
force_generic_extractor=params.get('force_generic_extractor', False))
|
force_generic_extractor=params.get('force_generic_extractor', False))
|
||||||
except (DownloadError, ExtractorError) as err:
|
except (DownloadError, ExtractorError) as err:
|
||||||
# Check if the exception is not a network related one
|
# Check if the exception is not a network related one
|
||||||
@ -194,23 +199,23 @@ def generator(test_case, tname):
|
|||||||
self.assertTrue('entries' in res_dict)
|
self.assertTrue('entries' in res_dict)
|
||||||
expect_info_dict(self, res_dict, test_case.get('info_dict', {}))
|
expect_info_dict(self, res_dict, test_case.get('info_dict', {}))
|
||||||
|
|
||||||
|
num_entries = len(res_dict.get('entries', []))
|
||||||
if 'playlist_mincount' in test_case:
|
if 'playlist_mincount' in test_case:
|
||||||
|
mincount = test_case['playlist_mincount']
|
||||||
assertGreaterEqual(
|
assertGreaterEqual(
|
||||||
self,
|
self, num_entries, mincount,
|
||||||
len(res_dict['entries']),
|
f'Expected at least {mincount} entries in playlist {test_url}, but got only {num_entries}')
|
||||||
test_case['playlist_mincount'],
|
|
||||||
'Expected at least %d in playlist %s, but got only %d' % (
|
|
||||||
test_case['playlist_mincount'], test_case['url'],
|
|
||||||
len(res_dict['entries'])))
|
|
||||||
if 'playlist_count' in test_case:
|
if 'playlist_count' in test_case:
|
||||||
|
count = test_case['playlist_count']
|
||||||
|
got = num_entries if num_entries <= count else 'more'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(res_dict['entries']),
|
num_entries, count,
|
||||||
test_case['playlist_count'],
|
f'Expected exactly {count} entries in playlist {test_url}, but got {got}')
|
||||||
'Expected %d entries in playlist %s, but got %d.' % (
|
if 'playlist_maxcount' in test_case:
|
||||||
test_case['playlist_count'],
|
maxcount = test_case['playlist_maxcount']
|
||||||
test_case['url'],
|
assertLessEqual(
|
||||||
len(res_dict['entries']),
|
self, num_entries, maxcount,
|
||||||
))
|
f'Expected at most {maxcount} entries in playlist {test_url}, but got more')
|
||||||
if 'playlist_duration_sum' in test_case:
|
if 'playlist_duration_sum' in test_case:
|
||||||
got_duration = sum(e['duration'] for e in res_dict['entries'])
|
got_duration = sum(e['duration'] for e in res_dict['entries'])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user