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