]>
Commit | Line | Data |
---|---|---|
5f627b44 | 1 | # coding: utf-8 |
5f627b44 PK |
2 | from __future__ import unicode_literals |
3 | ||
1d4247f6 PK |
4 | import re |
5 | ||
5f627b44 PK |
6 | from .common import InfoExtractor |
7 | from ..utils import ( | |
4d9fc401 S |
8 | determine_ext, |
9 | ExtractorError, | |
10 | int_or_none, | |
b9465395 | 11 | js_to_json, |
4d9fc401 | 12 | mimetype2ext, |
1d4247f6 | 13 | unescapeHTML, |
5f627b44 PK |
14 | ) |
15 | ||
16 | ||
17 | class DVTVIE(InfoExtractor): | |
b9465395 | 18 | IE_NAME = 'dvtv' |
1d4247f6 | 19 | IE_DESC = 'http://video.aktualne.cz/' |
b9465395 | 20 | |
5886b38d | 21 | _VALID_URL = r'https?://video\.aktualne\.cz/(?:[^/]+/)+r~(?P<id>[0-9a-f]{32})' |
b9465395 PH |
22 | |
23 | _TESTS = [{ | |
24 | 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/', | |
1d4247f6 | 25 | 'md5': '67cb83e4a955d36e1b5d31993134a0c2', |
b9465395 | 26 | 'info_dict': { |
1d4247f6 PK |
27 | 'id': 'dc0768de855511e49e4b0025900fea04', |
28 | 'ext': 'mp4', | |
081d6e47 | 29 | 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně', |
4d9fc401 | 30 | 'duration': 1484, |
b9465395 | 31 | } |
1d4247f6 PK |
32 | }, { |
33 | 'url': 'http://video.aktualne.cz/dvtv/dvtv-16-12-2014-utok-talibanu-boj-o-kliniku-uprchlici/r~973eb3bc854e11e498be002590604f2e/', | |
34 | 'info_dict': { | |
35 | 'title': 'DVTV 16. 12. 2014: útok Talibanu, boj o kliniku, uprchlíci', | |
081d6e47 | 36 | 'id': '973eb3bc854e11e498be002590604f2e', |
1d4247f6 PK |
37 | }, |
38 | 'playlist': [{ | |
39 | 'md5': 'da7ca6be4935532241fa9520b3ad91e4', | |
40 | 'info_dict': { | |
41 | 'id': 'b0b40906854d11e4bdad0025900fea04', | |
42 | 'ext': 'mp4', | |
4d9fc401 S |
43 | 'title': 'Drtinová Veselovský TV 16. 12. 2014: Témata dne', |
44 | 'description': 'md5:0916925dea8e30fe84222582280b47a0', | |
45 | 'timestamp': 1418760010, | |
46 | 'upload_date': '20141216', | |
1d4247f6 PK |
47 | } |
48 | }, { | |
49 | 'md5': '5f7652a08b05009c1292317b449ffea2', | |
50 | 'info_dict': { | |
51 | 'id': '420ad9ec854a11e4bdad0025900fea04', | |
52 | 'ext': 'mp4', | |
4d9fc401 S |
53 | 'title': 'Školní masakr možná změní boj s Talibanem, říká novinářka', |
54 | 'description': 'md5:ff2f9f6de73c73d7cef4f756c1c1af42', | |
55 | 'timestamp': 1418760010, | |
56 | 'upload_date': '20141216', | |
1d4247f6 PK |
57 | } |
58 | }, { | |
59 | 'md5': '498eb9dfa97169f409126c617e2a3d64', | |
60 | 'info_dict': { | |
61 | 'id': '95d35580846a11e4b6d20025900fea04', | |
62 | 'ext': 'mp4', | |
4d9fc401 S |
63 | 'title': 'Boj o kliniku: Veřejný zájem, nebo právo na majetek?', |
64 | 'description': 'md5:889fe610a70fee5511dc3326a089188e', | |
65 | 'timestamp': 1418760010, | |
66 | 'upload_date': '20141216', | |
1d4247f6 PK |
67 | } |
68 | }, { | |
69 | 'md5': 'b8dc6b744844032dab6ba3781a7274b9', | |
70 | 'info_dict': { | |
71 | 'id': '6fe14d66853511e4833a0025900fea04', | |
72 | 'ext': 'mp4', | |
4d9fc401 S |
73 | 'title': 'Pánek: Odmítání syrských uprchlíků je ostudou české vlády', |
74 | 'description': 'md5:544f86de6d20c4815bea11bf2ac3004f', | |
75 | 'timestamp': 1418760010, | |
76 | 'upload_date': '20141216', | |
1d4247f6 | 77 | } |
081d6e47 | 78 | }], |
76552234 JK |
79 | }, { |
80 | 'url': 'https://video.aktualne.cz/dvtv/zeman-si-jen-leci-mindraky-sobotku-nenavidi-a-babis-se-mu-te/r~960cdb3a365a11e7a83b0025900fea04/', | |
81 | 'md5': 'f8efe9656017da948369aa099788c8ea', | |
82 | 'info_dict': { | |
83 | 'id': '3c496fec365911e7a6500025900fea04', | |
4d9fc401 | 84 | 'ext': 'mp4', |
76552234 | 85 | 'title': 'Zeman si jen léčí mindráky, Sobotku nenávidí a Babiš se mu teď hodí, tvrdí Kmenta', |
4d9fc401 S |
86 | 'duration': 1103, |
87 | }, | |
88 | 'params': { | |
89 | 'skip_download': True, | |
90 | }, | |
91 | }, { | |
92 | 'url': 'http://video.aktualne.cz/v-cechach-poprve-zazni-zelenkova-zrestaurovana-mse/r~45b4b00483ec11e4883b002590604f2e/', | |
93 | 'only_matching': True, | |
b9465395 PH |
94 | }] |
95 | ||
1d4247f6 | 96 | def _parse_video_metadata(self, js, video_id): |
4d9fc401 S |
97 | data = self._parse_json(js, video_id, transform_source=js_to_json) |
98 | ||
99 | title = unescapeHTML(data['title']) | |
b9465395 | 100 | |
b9465395 | 101 | formats = [] |
4d9fc401 S |
102 | for video in data['sources']: |
103 | video_url = video.get('file') | |
104 | if not video_url: | |
105 | continue | |
106 | video_type = video.get('type') | |
107 | ext = determine_ext(video_url, mimetype2ext(video_type)) | |
108 | if video_type == 'application/vnd.apple.mpegurl' or ext == 'm3u8': | |
109 | formats.extend(self._extract_m3u8_formats( | |
110 | video_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
111 | m3u8_id='hls', fatal=False)) | |
112 | elif video_type == 'application/dash+xml' or ext == 'mpd': | |
113 | formats.extend(self._extract_mpd_formats( | |
114 | video_url, video_id, mpd_id='dash', fatal=False)) | |
115 | else: | |
116 | label = video.get('label') | |
117 | height = self._search_regex( | |
118 | r'^(\d+)[pP]', label or '', 'height', default=None) | |
119 | format_id = ['http'] | |
120 | for f in (ext, label): | |
121 | if f: | |
122 | format_id.append(f) | |
76552234 | 123 | formats.append({ |
4d9fc401 S |
124 | 'url': video_url, |
125 | 'format_id': '-'.join(format_id), | |
126 | 'height': int_or_none(height), | |
76552234 | 127 | }) |
b9465395 PH |
128 | self._sort_formats(formats) |
129 | ||
130 | return { | |
4d9fc401 S |
131 | 'id': data.get('mediaid') or video_id, |
132 | 'title': title, | |
133 | 'description': data.get('description'), | |
134 | 'thumbnail': data.get('image'), | |
135 | 'duration': int_or_none(data.get('duration')), | |
136 | 'timestamp': int_or_none(data.get('pubtime')), | |
b9465395 PH |
137 | 'formats': formats |
138 | } | |
1d4247f6 PK |
139 | |
140 | def _real_extract(self, url): | |
141 | video_id = self._match_id(url) | |
081d6e47 | 142 | |
1d4247f6 PK |
143 | webpage = self._download_webpage(url, video_id) |
144 | ||
081d6e47 S |
145 | # single video |
146 | item = self._search_regex( | |
4d9fc401 | 147 | r'(?s)embedData[0-9a-f]{32}\[["\']asset["\']\]\s*=\s*(\{.+?\});', |
081d6e47 | 148 | webpage, 'video', default=None, fatal=False) |
1d4247f6 | 149 | |
081d6e47 S |
150 | if item: |
151 | return self._parse_video_metadata(item, video_id) | |
1d4247f6 PK |
152 | |
153 | # playlist | |
154 | items = re.findall( | |
081d6e47 | 155 | r"(?s)BBX\.context\.assets\['[0-9a-f]{32}'\]\.push\(({.+?})\);", |
1d4247f6 | 156 | webpage) |
4d9fc401 S |
157 | if not items: |
158 | items = re.findall(r'(?s)var\s+asset\s*=\s*({.+?});\n', webpage) | |
1d4247f6 PK |
159 | |
160 | if items: | |
161 | return { | |
162 | '_type': 'playlist', | |
163 | 'id': video_id, | |
164 | 'title': self._og_search_title(webpage), | |
165 | 'entries': [self._parse_video_metadata(i, video_id) for i in items] | |
166 | } | |
167 | ||
081d6e47 | 168 | raise ExtractorError('Could not find neither video nor playlist') |