]>
Commit | Line | Data |
---|---|---|
5f627b44 PK |
1 | # coding: utf-8 |
2 | ||
3 | from __future__ import unicode_literals | |
4 | ||
1d4247f6 PK |
5 | import re |
6 | ||
5f627b44 PK |
7 | from .common import InfoExtractor |
8 | from ..utils import ( | |
b9465395 | 9 | js_to_json, |
1d4247f6 PK |
10 | unescapeHTML, |
11 | ExtractorError | |
5f627b44 PK |
12 | ) |
13 | ||
14 | ||
15 | class DVTVIE(InfoExtractor): | |
b9465395 | 16 | IE_NAME = 'dvtv' |
1d4247f6 | 17 | IE_DESC = 'http://video.aktualne.cz/' |
b9465395 | 18 | |
1d4247f6 | 19 | _VALID_URL = r'http://video\.aktualne\.cz/.*/r~(?P<id>[0-9a-f]{32})/' |
b9465395 PH |
20 | |
21 | _TESTS = [{ | |
22 | 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/', | |
1d4247f6 | 23 | 'md5': '67cb83e4a955d36e1b5d31993134a0c2', |
b9465395 | 24 | 'info_dict': { |
1d4247f6 PK |
25 | 'id': 'dc0768de855511e49e4b0025900fea04', |
26 | 'ext': 'mp4', | |
b9465395 PH |
27 | 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně' |
28 | } | |
29 | }, { | |
30 | 'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/', | |
31 | 'md5': '6388f1941b48537dbd28791f712af8bf', | |
32 | 'info_dict': { | |
1d4247f6 | 33 | 'id': '72c02230849211e49f60002590604f2e', |
b9465395 PH |
34 | 'ext': 'mp4', |
35 | 'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala' | |
36 | } | |
1d4247f6 PK |
37 | }, { |
38 | 'url': 'http://video.aktualne.cz/dvtv/dvtv-16-12-2014-utok-talibanu-boj-o-kliniku-uprchlici/r~973eb3bc854e11e498be002590604f2e/', | |
39 | 'info_dict': { | |
40 | 'title': 'DVTV 16. 12. 2014: útok Talibanu, boj o kliniku, uprchlíci', | |
41 | 'id': '973eb3bc854e11e498be002590604f2e' | |
42 | }, | |
43 | 'playlist': [{ | |
44 | 'md5': 'da7ca6be4935532241fa9520b3ad91e4', | |
45 | 'info_dict': { | |
46 | 'id': 'b0b40906854d11e4bdad0025900fea04', | |
47 | 'ext': 'mp4', | |
48 | 'title': 'Drtinová Veselovský TV 16. 12. 2014: Témata dne' | |
49 | } | |
50 | }, { | |
51 | 'md5': '5f7652a08b05009c1292317b449ffea2', | |
52 | 'info_dict': { | |
53 | 'id': '420ad9ec854a11e4bdad0025900fea04', | |
54 | 'ext': 'mp4', | |
55 | 'title': 'Školní masakr možná změní boj s Talibanem, říká novinářka' | |
56 | } | |
57 | }, { | |
58 | 'md5': '498eb9dfa97169f409126c617e2a3d64', | |
59 | 'info_dict': { | |
60 | 'id': '95d35580846a11e4b6d20025900fea04', | |
61 | 'ext': 'mp4', | |
62 | 'title': 'Boj o kliniku: Veřejný zájem, nebo právo na majetek?' | |
63 | } | |
64 | }, { | |
65 | 'md5': 'b8dc6b744844032dab6ba3781a7274b9', | |
66 | 'info_dict': { | |
67 | 'id': '6fe14d66853511e4833a0025900fea04', | |
68 | 'ext': 'mp4', | |
69 | 'title': 'Pánek: Odmítání syrských uprchlíků je ostudou české vlády' | |
70 | } | |
71 | }] | |
b9465395 PH |
72 | }] |
73 | ||
1d4247f6 PK |
74 | def _parse_video_metadata(self, js, video_id): |
75 | metadata = self._parse_json(js, video_id, transform_source=js_to_json) | |
b9465395 | 76 | |
b9465395 | 77 | formats = [] |
1d4247f6 PK |
78 | for video in metadata['sources']: |
79 | ext = video['type'][6:] | |
b9465395 | 80 | formats.append({ |
1d4247f6 | 81 | 'url': video['file'], |
b9465395 | 82 | 'ext': ext, |
1d4247f6 PK |
83 | 'format': '%s %s' % (ext, video['label']), |
84 | 'format_id': '%s-%s' % (ext, video['label']), | |
85 | 'height': int(video['label'].rstrip('p')), | |
b9465395 PH |
86 | 'fps': 25, |
87 | }) | |
1d4247f6 | 88 | |
b9465395 PH |
89 | self._sort_formats(formats) |
90 | ||
91 | return { | |
1d4247f6 PK |
92 | 'id': metadata['mediaid'], |
93 | 'title': unescapeHTML(metadata['title']), | |
94 | 'thumbnail': 'http:%s' % metadata['image'], | |
b9465395 PH |
95 | 'formats': formats |
96 | } | |
1d4247f6 PK |
97 | |
98 | def _real_extract(self, url): | |
99 | video_id = self._match_id(url) | |
100 | webpage = self._download_webpage(url, video_id) | |
101 | ||
102 | # singe video | |
103 | items = re.findall( | |
104 | r'(?s)embedData[0-9a-f]{32}\[\'asset\'\] = (\{.+?\});', | |
105 | webpage) | |
106 | ||
107 | if items: | |
108 | return self._parse_video_metadata(items[0], video_id) | |
109 | ||
110 | # playlist | |
111 | items = re.findall( | |
112 | r'(?s)BBX\.context\.assets\[\'[0-9a-f]{32}\'\]\.push\((\{.+?\})\);', | |
113 | webpage) | |
114 | ||
115 | if items: | |
116 | return { | |
117 | '_type': 'playlist', | |
118 | 'id': video_id, | |
119 | 'title': self._og_search_title(webpage), | |
120 | 'entries': [self._parse_video_metadata(i, video_id) for i in items] | |
121 | } | |
122 | ||
123 | raise ExtractorError('Could not find neither video nor playlist for requested ID') |