]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/fusion.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / fusion.py
CommitLineData
bb08101e 1from .common import InfoExtractor
509bcec3
RA
2from ..utils import (
3 determine_ext,
4 int_or_none,
5 mimetype2ext,
6 parse_iso8601,
7)
bb08101e
T
8
9
10class FusionIE(InfoExtractor):
509bcec3 11 _VALID_URL = r'https?://(?:www\.)?fusion\.(?:net|tv)/(?:video/|show/.+?\bvideo=)(?P<id>\d+)'
14ff6baa 12 _TESTS = [{
38662dfe 13 'url': 'http://fusion.tv/video/201781/u-s-and-panamanian-forces-work-together-to-stop-a-vessel-smuggling-drugs/',
bb08101e 14 'info_dict': {
509bcec3 15 'id': '3145868',
bb08101e
T
16 'ext': 'mp4',
17 'title': 'U.S. and Panamanian forces work together to stop a vessel smuggling drugs',
18 'description': 'md5:0cc84a9943c064c0f46b128b41b1b0d7',
19 'duration': 140.0,
509bcec3
RA
20 'timestamp': 1442589635,
21 'uploader': 'UNIVISON',
22 'upload_date': '20150918',
bb08101e 23 },
14ff6baa
S
24 'params': {
25 'skip_download': True,
26 },
509bcec3 27 'add_ie': ['Anvato'],
14ff6baa 28 }, {
38662dfe 29 'url': 'http://fusion.tv/video/201781',
14ff6baa 30 'only_matching': True,
509bcec3
RA
31 }, {
32 'url': 'https://fusion.tv/show/food-exposed-with-nelufar-hedayat/?ancla=full-episodes&video=588644',
33 'only_matching': True,
14ff6baa 34 }]
bb08101e
T
35
36 def _real_extract(self, url):
509bcec3
RA
37 video_id = self._match_id(url)
38 video = self._download_json(
39 'https://platform.fusion.net/wp-json/fusiondotnet/v1/video/' + video_id, video_id)
40
41 info = {
42 'id': video_id,
43 'title': video['title'],
44 'description': video.get('excerpt'),
45 'timestamp': parse_iso8601(video.get('published')),
46 'series': video.get('show'),
47 }
bb08101e 48
509bcec3
RA
49 formats = []
50 src = video.get('src') or {}
51 for f_id, f in src.items():
52 for q_id, q in f.items():
53 q_url = q.get('url')
54 if not q_url:
55 continue
56 ext = determine_ext(q_url, mimetype2ext(q.get('type')))
57 if ext == 'smil':
58 formats.extend(self._extract_smil_formats(q_url, video_id, fatal=False))
59 elif f_id == 'm3u8-variant' or (ext == 'm3u8' and q_id == 'Variant'):
60 formats.extend(self._extract_m3u8_formats(
61 q_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
62 else:
63 formats.append({
64 'format_id': '-'.join([f_id, q_id]),
65 'url': q_url,
66 'width': int_or_none(q.get('width')),
67 'height': int_or_none(q.get('height')),
68 'tbr': int_or_none(self._search_regex(r'_(\d+)\.m(?:p4|3u8)', q_url, 'bitrate')),
69 'ext': 'mp4' if ext == 'm3u8' else ext,
70 'protocol': 'm3u8_native' if ext == 'm3u8' else 'https',
71 })
72 if formats:
509bcec3
RA
73 info['formats'] = formats
74 else:
75 info.update({
76 '_type': 'url',
77 'url': 'anvato:uni:' + video['video_ids']['anvato'],
78 'ie_key': 'Anvato',
79 })
bb08101e 80
509bcec3 81 return info