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