]>
Commit | Line | Data |
---|---|---|
5c86bfe7 S |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
30a074c2 | 4 | from ..compat import compat_HTTPError |
5c86bfe7 S |
5 | from ..utils import ( |
6 | determine_ext, | |
30a074c2 | 7 | ExtractorError, |
8 | float_or_none, | |
9 | int_or_none, | |
34921b43 | 10 | join_nonempty, |
30a074c2 | 11 | parse_iso8601, |
5c86bfe7 S |
12 | ) |
13 | ||
14 | ||
15 | class ThreeQSDNIE(InfoExtractor): | |
16 | IE_NAME = '3qsdn' | |
17 | IE_DESC = '3Q SDN' | |
18 | _VALID_URL = r'https?://playout\.3qsdn\.com/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})' | |
19 | _TESTS = [{ | |
30a074c2 | 20 | # https://player.3qsdn.com/demo.html |
21 | 'url': 'https://playout.3qsdn.com/7201c779-6b3c-11e7-a40e-002590c750be', | |
22 | 'md5': '64a57396b16fa011b15e0ea60edce918', | |
5c86bfe7 | 23 | 'info_dict': { |
30a074c2 | 24 | 'id': '7201c779-6b3c-11e7-a40e-002590c750be', |
5c86bfe7 | 25 | 'ext': 'mp4', |
30a074c2 | 26 | 'title': 'Video Ads', |
5c86bfe7 | 27 | 'is_live': False, |
30a074c2 | 28 | 'description': 'Video Ads Demo', |
29 | 'timestamp': 1500334803, | |
30 | 'upload_date': '20170717', | |
31 | 'duration': 888.032, | |
32 | 'subtitles': { | |
33 | 'eng': 'count:1', | |
34 | }, | |
5c86bfe7 | 35 | }, |
30a074c2 | 36 | 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'], |
5c86bfe7 S |
37 | }, { |
38 | # live video stream | |
30a074c2 | 39 | 'url': 'https://playout.3qsdn.com/66e68995-11ca-11e8-9273-002590c750be', |
5c86bfe7 | 40 | 'info_dict': { |
30a074c2 | 41 | 'id': '66e68995-11ca-11e8-9273-002590c750be', |
5c86bfe7 | 42 | 'ext': 'mp4', |
30a074c2 | 43 | 'title': 're:^66e68995-11ca-11e8-9273-002590c750be [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', |
7b0d333a NP |
44 | 'is_live': True, |
45 | }, | |
46 | 'params': { | |
47 | 'skip_download': True, # m3u8 downloads | |
5c86bfe7 S |
48 | }, |
49 | }, { | |
50 | # live audio stream | |
51 | 'url': 'http://playout.3qsdn.com/9edf36e0-6bf2-11e2-a16a-9acf09e2db48', | |
52 | 'only_matching': True, | |
53 | }, { | |
54 | # live audio stream with some 404 URLs | |
55 | 'url': 'http://playout.3qsdn.com/ac5c3186-777a-11e2-9c30-9acf09e2db48', | |
56 | 'only_matching': True, | |
57 | }, { | |
58 | # geo restricted with 'This content is not available in your country' | |
59 | 'url': 'http://playout.3qsdn.com/d63a3ffe-75e8-11e2-9c30-9acf09e2db48', | |
60 | 'only_matching': True, | |
61 | }, { | |
62 | # geo restricted with 'playout.3qsdn.com/forbidden' | |
63 | 'url': 'http://playout.3qsdn.com/8e330f26-6ae2-11e2-a16a-9acf09e2db48', | |
64 | 'only_matching': True, | |
65 | }, { | |
66 | # live video with rtmp link | |
67 | 'url': 'https://playout.3qsdn.com/6092bb9e-8f72-11e4-a173-002590c750be', | |
68 | 'only_matching': True, | |
30a074c2 | 69 | }, { |
70 | # ondemand from http://www.philharmonie.tv/veranstaltung/26/ | |
71 | 'url': 'http://playout.3qsdn.com/0280d6b9-1215-11e6-b427-0cc47a188158?protocol=http', | |
72 | 'only_matching': True, | |
73 | }, { | |
74 | # live video stream | |
75 | 'url': 'https://playout.3qsdn.com/d755d94b-4ab9-11e3-9162-0025907ad44f?js=true', | |
76 | 'only_matching': True, | |
5c86bfe7 S |
77 | }] |
78 | ||
5d39176f S |
79 | @staticmethod |
80 | def _extract_url(webpage): | |
81 | mobj = re.search( | |
82 | r'<iframe[^>]+\b(?:data-)?src=(["\'])(?P<url>%s.*?)\1' % ThreeQSDNIE._VALID_URL, webpage) | |
83 | if mobj: | |
84 | return mobj.group('url') | |
85 | ||
5c86bfe7 S |
86 | def _real_extract(self, url): |
87 | video_id = self._match_id(url) | |
88 | ||
30a074c2 | 89 | try: |
90 | config = self._download_json( | |
91 | url.replace('://playout.3qsdn.com/', '://playout.3qsdn.com/config/'), video_id) | |
92 | except ExtractorError as e: | |
93 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401: | |
94 | self.raise_geo_restricted() | |
95 | raise | |
5c86bfe7 | 96 | |
30a074c2 | 97 | live = config.get('streamContent') == 'live' |
98 | aspect = float_or_none(config.get('aspect')) | |
5c86bfe7 S |
99 | |
100 | formats = [] | |
e8f834cd | 101 | subtitles = {} |
30a074c2 | 102 | for source_type, source in (config.get('sources') or {}).items(): |
103 | if not source: | |
104 | continue | |
105 | if source_type == 'dash': | |
e8f834cd F |
106 | fmts, subs = self._extract_mpd_formats_and_subtitles( |
107 | source, video_id, mpd_id='mpd', fatal=False) | |
108 | formats.extend(fmts) | |
109 | subtitles = self._merge_subtitles(subtitles, subs) | |
30a074c2 | 110 | elif source_type == 'hls': |
e8f834cd | 111 | fmts, subs = self._extract_m3u8_formats_and_subtitles( |
a5c0c202 | 112 | source, video_id, 'mp4', live=live, m3u8_id='hls', fatal=False) |
e8f834cd F |
113 | formats.extend(fmts) |
114 | subtitles = self._merge_subtitles(subtitles, subs) | |
30a074c2 | 115 | elif source_type == 'progressive': |
116 | for s in source: | |
117 | src = s.get('src') | |
118 | if not (src and self._is_valid_url(src, video_id)): | |
119 | continue | |
30a074c2 | 120 | ext = determine_ext(src) |
30a074c2 | 121 | height = int_or_none(s.get('height')) |
30a074c2 | 122 | formats.append({ |
123 | 'ext': ext, | |
34921b43 | 124 | 'format_id': join_nonempty('http', ext, height and '%dp' % height), |
30a074c2 | 125 | 'height': height, |
126 | 'source_preference': 0, | |
127 | 'url': src, | |
128 | 'vcodec': 'none' if height == 0 else None, | |
34921b43 | 129 | 'width': int(height * aspect) if height and aspect else None, |
30a074c2 | 130 | }) |
54f37eea | 131 | # It seems like this would be correctly handled by default |
132 | # However, unless someone can confirm this, the old | |
133 | # behaviour is being kept as-is | |
134 | self._sort_formats(formats, ('res', 'source_preference')) | |
30a074c2 | 135 | |
30a074c2 | 136 | for subtitle in (config.get('subtitles') or []): |
137 | src = subtitle.get('src') | |
138 | if not src: | |
5c86bfe7 | 139 | continue |
30a074c2 | 140 | subtitles.setdefault(subtitle.get('label') or 'eng', []).append({ |
141 | 'url': src, | |
142 | }) | |
5c86bfe7 | 143 | |
30a074c2 | 144 | title = config.get('title') or video_id |
5c86bfe7 S |
145 | |
146 | return { | |
147 | 'id': video_id, | |
39ca3b5c | 148 | 'title': title, |
30a074c2 | 149 | 'thumbnail': config.get('poster') or None, |
150 | 'description': config.get('description') or None, | |
151 | 'timestamp': parse_iso8601(config.get('upload_date')), | |
152 | 'duration': float_or_none(config.get('vlength')) or None, | |
5c86bfe7 S |
153 | 'is_live': live, |
154 | 'formats': formats, | |
30a074c2 | 155 | 'subtitles': subtitles, |
5c86bfe7 | 156 | } |