]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/fusion.py
689422fca49e81af7b631beadd97fbc844e3b022
[yt-dlp.git] / yt_dlp / extractor / fusion.py
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 mimetype2ext,
6 parse_iso8601,
7 )
8
9
10 class FusionIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?fusion\.(?:net|tv)/(?:video/|show/.+?\bvideo=)(?P<id>\d+)'
12 _TESTS = [{
13 'url': 'http://fusion.tv/video/201781/u-s-and-panamanian-forces-work-together-to-stop-a-vessel-smuggling-drugs/',
14 'info_dict': {
15 'id': '3145868',
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,
20 'timestamp': 1442589635,
21 'uploader': 'UNIVISON',
22 'upload_date': '20150918',
23 },
24 'params': {
25 'skip_download': True,
26 },
27 'add_ie': ['Anvato'],
28 }, {
29 'url': 'http://fusion.tv/video/201781',
30 'only_matching': True,
31 }, {
32 'url': 'https://fusion.tv/show/food-exposed-with-nelufar-hedayat/?ancla=full-episodes&video=588644',
33 'only_matching': True,
34 }]
35
36 def _real_extract(self, url):
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 }
48
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:
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 })
80
81 return info