ignore formats with falsy filesizes, add tests

This commit is contained in:
grqx_wsl 2024-10-04 17:39:53 +13:00
parent 56ae6a975b
commit 13b92fe1a3

View File

@ -59,20 +59,35 @@ class NZOnScreenIE(InfoExtractor):
'title': 'Flatmates - 1, First Episode', 'title': 'Flatmates - 1, First Episode',
}, },
'playlist_count': 5, 'playlist_count': 5,
}, {
# hd format not present
'url': 'https://www.nzonscreen.com/title/reluctant-hero-2008',
'info_dict': {
'id': '847f5c91af65d44b',
'ext': 'mp4',
'format_id': 'hi',
'title': 'Reluctant Hero (clip 1)',
'description': 'Part one of four from this full length documentary.',
'display_id': 'reluctant-hero-2008',
'duration': 1108.0,
'thumbnail': r're:https://www\.nzonscreen\.com/content/images/.+\.jpg',
},
'params': {'skip_download': 'm3u8'},
}] }]
def _extract_formats(self, playlist): def _extract_formats(self, playlist):
for quality, (id_, url) in enumerate(traverse_obj( for quality, (id_, url) in enumerate(traverse_obj(
playlist, ('h264', {'lo': 'lo_res', 'hi': 'hi_res', 'hd': 'hd_res'}), expected_type=url_or_none).items()): playlist, ('h264', {'lo': 'lo_res', 'hi': 'hi_res', 'hd': 'hd_res'}), expected_type=url_or_none).items()):
yield { if traverse_obj(playlist, ('h264', f'{id_}_res_mb', {float_or_none})):
'url': url, yield {
'format_id': id_, 'url': url,
'ext': 'mp4', 'format_id': id_,
'quality': quality, 'ext': 'mp4',
'height': int_or_none(playlist.get('height')) if id_ == 'hd' else None, 'quality': quality,
'width': int_or_none(playlist.get('width')) if id_ == 'hd' else None, 'height': int_or_none(playlist.get('height')) if id_ == 'hd' else None,
'filesize_approx': float_or_none(traverse_obj(playlist, ('h264', f'{id_}_res_mb')), invscale=1024**2), 'width': int_or_none(playlist.get('width')) if id_ == 'hd' else None,
} 'filesize_approx': float_or_none(traverse_obj(playlist, ('h264', f'{id_}_res_mb')), invscale=1024**2),
}
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
@ -83,6 +98,7 @@ def _real_extract(self, url):
playlist = self._download_json( playlist = self._download_json(
f'https://www.nzonscreen.com/html5/video_data/{video_id}', video_id, 'media data') f'https://www.nzonscreen.com/html5/video_data/{video_id}', video_id, 'media data')
# TODO: extract subtitles
if len(playlist) == 1: if len(playlist) == 1:
playinfo = playlist[0] playinfo = playlist[0]
return { return {