]>
Commit | Line | Data |
---|---|---|
221a59fe OC |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
221a59fe OC |
4 | from .common import InfoExtractor |
5 | from ..compat import ( | |
6 | compat_urlparse, | |
15707c7e | 7 | compat_urllib_parse_urlencode, |
221a59fe | 8 | ) |
276c9897 S |
9 | from ..utils import ( |
10 | ExtractorError, | |
11 | int_or_none, | |
12 | parse_iso8601, | |
13 | qualities, | |
14 | ) | |
221a59fe OC |
15 | |
16 | ||
17 | class PlaytvakIE(InfoExtractor): | |
276c9897 S |
18 | IE_DESC = 'Playtvak.cz, iDNES.cz and Lidovky.cz' |
19 | _VALID_URL = r'https?://(?:.+?\.)?(?:playtvak|idnes|lidovky|metro)\.cz/.*\?(?:c|idvideo)=(?P<id>[^&]+)' | |
221a59fe OC |
20 | _TESTS = [{ |
21 | 'url': 'http://www.playtvak.cz/vyzente-vosy-a-srsne-ze-zahrady-dn5-/hodinovy-manzel.aspx?c=A150730_150323_hodinovy-manzel_kuko', | |
22 | 'md5': '4525ae312c324b4be2f4603cc78ceb4a', | |
23 | 'info_dict': { | |
24 | 'id': 'A150730_150323_hodinovy-manzel_kuko', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Vyžeňte vosy a sršně ze zahrady', | |
616bb95b | 27 | 'description': 'md5:4436e61b7df227a093778efb7e373571', |
ec85ded8 | 28 | 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$', |
276c9897 S |
29 | 'duration': 279, |
30 | 'timestamp': 1438732860, | |
31 | 'upload_date': '20150805', | |
32 | 'is_live': False, | |
221a59fe OC |
33 | } |
34 | }, { # live video test | |
35 | 'url': 'http://slowtv.playtvak.cz/planespotting-0pr-/planespotting.aspx?c=A150624_164934_planespotting_cat', | |
36 | 'info_dict': { | |
37 | 'id': 'A150624_164934_planespotting_cat', | |
38 | 'ext': 'flv', | |
616bb95b | 39 | 'title': 're:^Planespotting [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', |
221a59fe | 40 | 'description': 'Sledujte provoz na ranveji Letiště Václava Havla v Praze', |
616bb95b OC |
41 | 'is_live': True, |
42 | }, | |
43 | 'params': { | |
44 | 'skip_download': True, # requires rtmpdump | |
45 | }, | |
46 | }, { # another live stream, this one without Misc.videoFLV | |
47 | 'url': 'https://slowtv.playtvak.cz/zive-sledujte-vlaky-v-primem-prenosu-dwi-/hlavni-nadrazi.aspx?c=A151218_145728_hlavni-nadrazi_plap', | |
48 | 'info_dict': { | |
49 | 'id': 'A151218_145728_hlavni-nadrazi_plap', | |
50 | 'ext': 'flv', | |
51 | 'title': 're:^Hlavní nádraží [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', | |
221a59fe OC |
52 | 'is_live': True, |
53 | }, | |
54 | 'params': { | |
55 | 'skip_download': True, # requires rtmpdump | |
56 | }, | |
57 | }, { # idnes.cz | |
58 | 'url': 'http://zpravy.idnes.cz/pes-zavreny-v-aute-rozbijeni-okynek-v-aute-fj5-/domaci.aspx?c=A150809_104116_domaci_pku', | |
59 | 'md5': '819832ba33cd7016e58a6658577fe289', | |
60 | 'info_dict': { | |
61 | 'id': 'A150809_104116_domaci_pku', | |
62 | 'ext': 'mp4', | |
63 | 'title': 'Zavřeli jsme mraženou pizzu do auta. Upekla se', | |
276c9897 | 64 | 'description': 'md5:01e73f02329e2e5760bd5eed4d42e3c2', |
ec85ded8 | 65 | 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$', |
276c9897 S |
66 | 'duration': 39, |
67 | 'timestamp': 1438969140, | |
68 | 'upload_date': '20150807', | |
69 | 'is_live': False, | |
221a59fe OC |
70 | } |
71 | }, { # lidovky.cz | |
72 | 'url': 'http://www.lidovky.cz/dalsi-demonstrace-v-praze-o-migraci-duq-/video.aspx?c=A150808_214044_ln-video_ELE', | |
73 | 'md5': 'c7209ac4ba9d234d4ad5bab7485bcee8', | |
74 | 'info_dict': { | |
75 | 'id': 'A150808_214044_ln-video_ELE', | |
76 | 'ext': 'mp4', | |
77 | 'title': 'Táhni! Demonstrace proti imigrantům budila emoce', | |
276c9897 | 78 | 'description': 'md5:97c81d589a9491fbfa323c9fa3cca72c', |
ec85ded8 | 79 | 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$', |
276c9897 S |
80 | 'timestamp': 1439052180, |
81 | 'upload_date': '20150808', | |
82 | 'is_live': False, | |
221a59fe | 83 | } |
974f1a38 S |
84 | }, { # metro.cz |
85 | 'url': 'http://www.metro.cz/video-pod-billboardem-se-na-vltavske-roztocil-kolotoc-deti-vozil-jen-par-hodin-1hx-/metro-extra.aspx?c=A141111_173251_metro-extra_row', | |
86 | 'md5': '84fc1deedcac37b7d4a6ccae7c716668', | |
87 | 'info_dict': { | |
88 | 'id': 'A141111_173251_metro-extra_row', | |
89 | 'ext': 'mp4', | |
90 | 'title': 'Recesisté udělali z billboardu kolotoč', | |
91 | 'description': 'md5:7369926049588c3989a66c9c1a043c4c', | |
ec85ded8 | 92 | 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$', |
974f1a38 S |
93 | 'timestamp': 1415725500, |
94 | 'upload_date': '20141111', | |
95 | 'is_live': False, | |
96 | } | |
276c9897 S |
97 | }, { |
98 | 'url': 'http://www.playtvak.cz/embed.aspx?idvideo=V150729_141549_play-porad_kuko', | |
99 | 'only_matching': True, | |
221a59fe OC |
100 | }] |
101 | ||
102 | def _real_extract(self, url): | |
103 | video_id = self._match_id(url) | |
276c9897 | 104 | |
221a59fe | 105 | webpage = self._download_webpage(url, video_id) |
276c9897 S |
106 | |
107 | info_url = self._html_search_regex( | |
616bb95b | 108 | r'Misc\.video(?:FLV)?\(\s*{\s*data\s*:\s*"([^"]+)"', webpage, 'info url') |
276c9897 S |
109 | |
110 | parsed_url = compat_urlparse.urlparse(info_url) | |
111 | ||
112 | qs = compat_urlparse.parse_qs(parsed_url.query) | |
113 | qs.update({ | |
114 | 'reklama': ['0'], | |
115 | 'type': ['js'], | |
116 | }) | |
117 | ||
118 | info_url = compat_urlparse.urlunparse( | |
15707c7e | 119 | parsed_url._replace(query=compat_urllib_parse_urlencode(qs, True))) |
276c9897 S |
120 | |
121 | json_info = self._download_json( | |
122 | info_url, video_id, | |
123 | transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1]) | |
221a59fe OC |
124 | |
125 | item = None | |
276c9897 S |
126 | for i in json_info['items']: |
127 | if i.get('type') == 'video' or i.get('type') == 'stream': | |
221a59fe OC |
128 | item = i |
129 | break | |
276c9897 | 130 | if not item: |
221a59fe | 131 | raise ExtractorError('No suitable stream found') |
276c9897 | 132 | |
00868742 | 133 | quality = qualities(('low', 'middle', 'high')) |
221a59fe OC |
134 | |
135 | formats = [] | |
136 | for fmt in item['video']: | |
276c9897 S |
137 | video_url = fmt.get('file') |
138 | if not video_url: | |
139 | continue | |
140 | ||
141 | format_ = fmt['format'] | |
142 | format_id = '%s_%s' % (format_, fmt['quality']) | |
143 | preference = None | |
144 | ||
00868742 | 145 | if format_ in ('mp4', 'webm'): |
276c9897 S |
146 | ext = format_ |
147 | elif format_ == 'rtmp': | |
148 | ext = 'flv' | |
149 | elif format_ == 'apple': | |
150 | ext = 'mp4' | |
221a59fe OC |
151 | # Some streams have mp3 audio which does not play |
152 | # well with ffmpeg filter aac_adtstoasc | |
f983b875 | 153 | preference = -10 |
276c9897 S |
154 | elif format_ == 'adobe': # f4m manifest fails with 404 in 80% of requests |
155 | continue | |
221a59fe OC |
156 | else: # Other formats not supported yet |
157 | continue | |
158 | ||
276c9897 S |
159 | formats.append({ |
160 | 'url': video_url, | |
161 | 'ext': ext, | |
162 | 'format_id': format_id, | |
163 | 'quality': quality(fmt.get('quality')), | |
164 | 'preference': preference, | |
165 | }) | |
221a59fe | 166 | self._sort_formats(formats) |
276c9897 S |
167 | |
168 | title = item['title'] | |
169 | is_live = item['type'] == 'stream' | |
170 | if is_live: | |
171 | title = self._live_title(title) | |
974f1a38 | 172 | description = self._og_search_description(webpage, default=None) or self._html_search_meta( |
616bb95b | 173 | 'description', webpage, 'description', default=None) |
276c9897 S |
174 | timestamp = None |
175 | duration = None | |
176 | if not is_live: | |
177 | duration = int_or_none(item.get('length')) | |
178 | timestamp = item.get('published') | |
179 | if timestamp: | |
180 | timestamp = parse_iso8601(timestamp[:-5]) | |
181 | ||
221a59fe OC |
182 | return { |
183 | 'id': video_id, | |
184 | 'title': title, | |
974f1a38 | 185 | 'description': description, |
276c9897 S |
186 | 'thumbnail': item.get('image'), |
187 | 'duration': duration, | |
188 | 'timestamp': timestamp, | |
221a59fe OC |
189 | 'is_live': is_live, |
190 | 'formats': formats, | |
191 | } |