]>
Commit | Line | Data |
---|---|---|
6f8cb242 | 1 | # coding: utf-8 |
24144e3b | 2 | from __future__ import unicode_literals |
5137ebac | 3 | |
29f400b9 TF |
4 | import re |
5 | ||
5137ebac | 6 | from .common import InfoExtractor |
6e3c2047 RA |
7 | from ..utils import ( |
8 | determine_ext, | |
9 | clean_html, | |
10 | get_element_by_attribute, | |
11 | ExtractorError, | |
12 | ) | |
c3a3028f | 13 | |
5137ebac | 14 | |
6f8cb242 S |
15 | class TVPIE(InfoExtractor): |
16 | IE_NAME = 'tvp' | |
17 | IE_DESC = 'Telewizja Polska' | |
18 | _VALID_URL = r'https?://[^/]+\.tvp\.(?:pl|info)/(?:(?!\d+/)[^/]+/)*(?P<id>\d+)' | |
fb4b030a PH |
19 | |
20 | _TESTS = [{ | |
6f8cb242 | 21 | 'url': 'http://vod.tvp.pl/194536/i-seria-odc-13', |
030aa5d9 | 22 | 'md5': '8aa518c15e5cc32dfe8db400dc921fbb', |
fb4b030a PH |
23 | 'info_dict': { |
24 | 'id': '194536', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Czas honoru, I seria – odc. 13', | |
fdd0b8f8 | 27 | 'description': 'md5:76649d2014f65c99477be17f23a4dead', |
fb4b030a PH |
28 | }, |
29 | }, { | |
30 | 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176', | |
6e3c2047 | 31 | 'md5': 'b0005b542e5b4de643a9690326ab1257', |
fb4b030a PH |
32 | 'info_dict': { |
33 | 'id': '17916176', | |
34 | 'ext': 'mp4', | |
35 | 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata', | |
fdd0b8f8 RA |
36 | 'description': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata', |
37 | }, | |
38 | }, { | |
39 | # page id is not the same as video id(#7799) | |
40 | 'url': 'http://vod.tvp.pl/22704887/08122015-1500', | |
41 | 'md5': 'cf6a4705dfd1489aef8deb168d6ba742', | |
42 | 'info_dict': { | |
43 | 'id': '22680786', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'Wiadomości, 08.12.2015, 15:00', | |
fb4b030a | 46 | }, |
fb4b030a PH |
47 | }, { |
48 | 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272', | |
6f8cb242 S |
49 | 'only_matching': True, |
50 | }, { | |
51 | 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200', | |
52 | 'only_matching': True, | |
53 | }, { | |
54 | 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa', | |
55 | 'only_matching': True, | |
56 | }, { | |
57 | 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach', | |
58 | 'only_matching': True, | |
59 | }, { | |
60 | 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum', | |
61 | 'only_matching': True, | |
62 | }, { | |
63 | 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji', | |
64 | 'only_matching': True, | |
fb4b030a | 65 | }] |
5137ebac | 66 | |
fdd0b8f8 RA |
67 | def _real_extract(self, url): |
68 | page_id = self._match_id(url) | |
69 | webpage = self._download_webpage(url, page_id) | |
70 | video_id = self._search_regex([ | |
71 | r'<iframe[^>]+src="[^"]*?object_id=(\d+)', | |
3d8d44c7 RA |
72 | r"object_id\s*:\s*'(\d+)'", |
73 | r'data-video-id="(\d+)"'], webpage, 'video id', default=page_id) | |
fdd0b8f8 RA |
74 | return { |
75 | '_type': 'url_transparent', | |
76 | 'url': 'tvp:' + video_id, | |
77 | 'description': self._og_search_description(webpage, default=None), | |
78 | 'thumbnail': self._og_search_thumbnail(webpage), | |
79 | 'ie_key': 'TVPEmbed', | |
80 | } | |
81 | ||
82 | ||
83 | class TVPEmbedIE(InfoExtractor): | |
84 | IE_NAME = 'tvp:embed' | |
85 | IE_DESC = 'Telewizja Polska' | |
86 | _VALID_URL = r'(?:tvp:|https?://[^/]+\.tvp\.(?:pl|info)/sess/tvplayer\.php\?.*?object_id=)(?P<id>\d+)' | |
87 | ||
88 | _TESTS = [{ | |
89 | 'url': 'http://www.tvp.pl/sess/tvplayer.php?object_id=22670268', | |
90 | 'md5': '8c9cd59d16edabf39331f93bf8a766c7', | |
91 | 'info_dict': { | |
92 | 'id': '22670268', | |
93 | 'ext': 'mp4', | |
94 | 'title': 'Panorama, 07.12.2015, 15:40', | |
95 | }, | |
96 | }, { | |
97 | 'url': 'tvp:22670268', | |
98 | 'only_matching': True, | |
99 | }] | |
100 | ||
5137ebac | 101 | def _real_extract(self, url): |
fb4b030a | 102 | video_id = self._match_id(url) |
030aa5d9 | 103 | |
29f400b9 TF |
104 | webpage = self._download_webpage( |
105 | 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id) | |
fb4b030a | 106 | |
6e3c2047 RA |
107 | error_massage = get_element_by_attribute('class', 'msg error', webpage) |
108 | if error_massage: | |
109 | raise ExtractorError('%s said: %s' % ( | |
110 | self.IE_NAME, clean_html(error_massage)), expected=True) | |
111 | ||
030aa5d9 S |
112 | title = self._search_regex( |
113 | r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1', | |
114 | webpage, 'title', group='title') | |
115 | series_title = self._search_regex( | |
116 | r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1', | |
29f400b9 | 117 | webpage, 'series', group='series', default=None) |
030aa5d9 S |
118 | if series_title: |
119 | title = '%s, %s' % (series_title, title) | |
120 | ||
121 | thumbnail = self._search_regex( | |
122 | r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None) | |
fb4b030a | 123 | |
29f400b9 | 124 | video_url = self._search_regex( |
6e3c2047 RA |
125 | r'0:{src:([\'"])(?P<url>.*?)\1', webpage, |
126 | 'formats', group='url', default=None) | |
127 | if not video_url or 'material_niedostepny.mp4' in video_url: | |
29f400b9 TF |
128 | video_url = self._download_json( |
129 | 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id, | |
130 | video_id)['video_url'] | |
131 | ||
6e3c2047 RA |
132 | formats = [] |
133 | video_url_base = self._search_regex( | |
134 | r'(https?://.+?/video)(?:\.(?:ism|f4m|m3u8)|-\d+\.mp4)', | |
135 | video_url, 'video base url', default=None) | |
136 | if video_url_base: | |
9513c1eb S |
137 | # TODO: <Group> found instead of <AdaptationSet> in MPD manifest. |
138 | # It's not mentioned in MPEG-DASH standard. Figure that out. | |
6e3c2047 RA |
139 | # formats.extend(self._extract_mpd_formats( |
140 | # video_url_base + '.ism/video.mpd', | |
141 | # video_id, mpd_id='dash', fatal=False)) | |
639e3b5c RA |
142 | formats.extend(self._extract_ism_formats( |
143 | video_url_base + '.ism/Manifest', | |
144 | video_id, 'mss', fatal=False)) | |
6e3c2047 RA |
145 | formats.extend(self._extract_f4m_formats( |
146 | video_url_base + '.ism/video.f4m', | |
147 | video_id, f4m_id='hds', fatal=False)) | |
148 | m3u8_formats = self._extract_m3u8_formats( | |
149 | video_url_base + '.ism/video.m3u8', video_id, | |
150 | 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False) | |
151 | self._sort_formats(m3u8_formats) | |
152 | m3u8_formats = list(filter( | |
ff99fe52 | 153 | lambda f: f.get('vcodec') != 'none', m3u8_formats)) |
6e3c2047 RA |
154 | formats.extend(m3u8_formats) |
155 | for i, m3u8_format in enumerate(m3u8_formats, 2): | |
156 | http_url = '%s-%d.mp4' % (video_url_base, i) | |
157 | if self._is_valid_url(http_url, video_id): | |
158 | f = m3u8_format.copy() | |
159 | f.update({ | |
160 | 'url': http_url, | |
161 | 'format_id': f['format_id'].replace('hls', 'http'), | |
162 | 'protocol': 'http', | |
163 | }) | |
164 | formats.append(f) | |
165 | else: | |
fb4b030a PH |
166 | formats = [{ |
167 | 'format_id': 'direct', | |
29f400b9 | 168 | 'url': video_url, |
6e3c2047 | 169 | 'ext': determine_ext(video_url, 'mp4'), |
fb4b030a | 170 | }] |
fb4b030a PH |
171 | |
172 | self._sort_formats(formats) | |
173 | ||
174 | return { | |
175 | 'id': video_id, | |
176 | 'title': title, | |
030aa5d9 | 177 | 'thumbnail': thumbnail, |
fb4b030a PH |
178 | 'formats': formats, |
179 | } | |
6ce2c678 TF |
180 | |
181 | ||
6f8cb242 S |
182 | class TVPSeriesIE(InfoExtractor): |
183 | IE_NAME = 'tvp:series' | |
6ce2c678 TF |
184 | _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$' |
185 | ||
fb4b030a PH |
186 | _TESTS = [{ |
187 | 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem', | |
188 | 'info_dict': { | |
189 | 'title': 'Ogniem i mieczem', | |
190 | 'id': '4278026', | |
191 | }, | |
192 | 'playlist_count': 4, | |
193 | }, { | |
194 | 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat', | |
195 | 'info_dict': { | |
196 | 'title': 'Boso przez świat', | |
197 | 'id': '9329207', | |
198 | }, | |
199 | 'playlist_count': 86, | |
200 | }] | |
6ce2c678 | 201 | |
6ce2c678 TF |
202 | def _real_extract(self, url): |
203 | display_id = self._match_id(url) | |
2415951e | 204 | webpage = self._download_webpage(url, display_id, tries=5) |
fb4b030a | 205 | |
6ce2c678 | 206 | title = self._html_search_regex( |
2415951e | 207 | r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series') |
6ce2c678 | 208 | playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id') |
2415951e | 209 | playlist = self._download_webpage( |
6ce2c678 | 210 | 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend' |
fb4b030a PH |
211 | 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5, |
212 | note='Downloading playlist') | |
213 | ||
6ce2c678 TF |
214 | videos_paths = re.findall( |
215 | '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist) | |
216 | entries = [ | |
6f8cb242 | 217 | self.url_result('http://vod.tvp.pl%s' % v_path, ie=TVPIE.ie_key()) |
6ce2c678 | 218 | for v_path in videos_paths] |
fb4b030a | 219 | |
6ce2c678 TF |
220 | return { |
221 | '_type': 'playlist', | |
222 | 'id': playlist_id, | |
223 | 'display_id': display_id, | |
224 | 'title': title, | |
225 | 'entries': entries, | |
226 | } |