2 from __future__ import unicode_literals
6 from .common import InfoExtractor
10 get_element_by_attribute,
15 class TVPIE(InfoExtractor):
17 IE_DESC = 'Telewizja Polska'
18 _VALID_URL = r'https?://[^/]+\.tvp\.(?:pl|info)/(?:video/(?:[^,\s]*,)*|(?:(?!\d+/)[^/]+/)*)(?P<id>\d+)'
21 'url': 'https://vod.tvp.pl/video/czas-honoru,i-seria-odc-13,194536',
22 'md5': 'a21eb0aa862f25414430f15fdfb9e76c',
26 'title': 'Czas honoru, odc. 13 – Władek',
27 'description': 'md5:437f48b93558370b031740546b696e24',
30 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
31 'md5': 'b0005b542e5b4de643a9690326ab1257',
35 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
36 'description': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
39 # page id is not the same as video id(#7799)
40 'url': 'https://wiadomosci.tvp.pl/33908820/28092017-1930',
41 'md5': '84cd3c8aec4840046e5ab712416b73d0',
45 'title': 'Wiadomości, 28.09.2017, 19:30',
46 'description': 'Wydanie główne codziennego serwisu informacyjnego.'
48 'skip': 'HTTP Error 404: Not Found',
50 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
51 'only_matching': True,
53 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
54 'only_matching': True,
56 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
57 'only_matching': True,
59 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
60 'only_matching': True,
62 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
63 'only_matching': True,
65 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
66 'only_matching': True,
69 def _real_extract(self, url):
70 page_id = self._match_id(url)
71 webpage = self._download_webpage(url, page_id)
72 video_id = self._search_regex([
73 r'<iframe[^>]+src="[^"]*?object_id=(\d+)',
74 r"object_id\s*:\s*'(\d+)'",
75 r'data-video-id="(\d+)"'], webpage, 'video id', default=page_id)
77 '_type': 'url_transparent',
78 'url': 'tvp:' + video_id,
79 'description': self._og_search_description(
80 webpage, default=None) or self._html_search_meta(
81 'description', webpage, default=None),
82 'thumbnail': self._og_search_thumbnail(webpage, default=None),
87 class TVPEmbedIE(InfoExtractor):
89 IE_DESC = 'Telewizja Polska'
90 _VALID_URL = r'(?:tvp:|https?://[^/]+\.tvp\.(?:pl|info)/sess/tvplayer\.php\?.*?object_id=)(?P<id>\d+)'
94 'md5': 'a21eb0aa862f25414430f15fdfb9e76c',
98 'title': 'Czas honoru, odc. 13 – Władek',
101 'url': 'http://www.tvp.pl/sess/tvplayer.php?object_id=22670268',
102 'md5': '8c9cd59d16edabf39331f93bf8a766c7',
106 'title': 'Panorama, 07.12.2015, 15:40',
109 'url': 'tvp:22670268',
110 'only_matching': True,
113 def _real_extract(self, url):
114 video_id = self._match_id(url)
116 webpage = self._download_webpage(
117 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
119 error_massage = get_element_by_attribute('class', 'msg error', webpage)
121 raise ExtractorError('%s said: %s' % (
122 self.IE_NAME, clean_html(error_massage)), expected=True)
124 title = self._search_regex(
125 r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
126 webpage, 'title', group='title')
127 series_title = self._search_regex(
128 r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
129 webpage, 'series', group='series', default=None)
131 title = '%s, %s' % (series_title, title)
133 thumbnail = self._search_regex(
134 r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
136 video_url = self._search_regex(
137 r'0:{src:([\'"])(?P<url>.*?)\1', webpage,
138 'formats', group='url', default=None)
139 if not video_url or 'material_niedostepny.mp4' in video_url:
140 video_url = self._download_json(
141 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
142 video_id)['video_url']
145 video_url_base = self._search_regex(
146 r'(https?://.+?/video)(?:\.(?:ism|f4m|m3u8)|-\d+\.mp4)',
147 video_url, 'video base url', default=None)
149 # TODO: <Group> found instead of <AdaptationSet> in MPD manifest.
150 # It's not mentioned in MPEG-DASH standard. Figure that out.
151 # formats.extend(self._extract_mpd_formats(
152 # video_url_base + '.ism/video.mpd',
153 # video_id, mpd_id='dash', fatal=False))
154 formats.extend(self._extract_ism_formats(
155 video_url_base + '.ism/Manifest',
156 video_id, 'mss', fatal=False))
157 formats.extend(self._extract_f4m_formats(
158 video_url_base + '.ism/video.f4m',
159 video_id, f4m_id='hds', fatal=False))
160 m3u8_formats = self._extract_m3u8_formats(
161 video_url_base + '.ism/video.m3u8', video_id,
162 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
163 self._sort_formats(m3u8_formats)
164 m3u8_formats = list(filter(
165 lambda f: f.get('vcodec') != 'none', m3u8_formats))
166 formats.extend(m3u8_formats)
167 for i, m3u8_format in enumerate(m3u8_formats, 2):
168 http_url = '%s-%d.mp4' % (video_url_base, i)
169 if self._is_valid_url(http_url, video_id):
170 f = m3u8_format.copy()
173 'format_id': f['format_id'].replace('hls', 'http'),
179 'format_id': 'direct',
181 'ext': determine_ext(video_url, 'mp4'),
184 self._sort_formats(formats)
189 'thumbnail': thumbnail,
194 class TVPSeriesIE(InfoExtractor):
195 IE_NAME = 'tvp:series'
196 _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
199 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
201 'title': 'Ogniem i mieczem',
206 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
208 'title': 'Boso przez świat',
211 'playlist_count': 86,
214 def _real_extract(self, url):
215 display_id = self._match_id(url)
216 webpage = self._download_webpage(url, display_id, tries=5)
218 title = self._html_search_regex(
219 r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
220 playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
221 playlist = self._download_webpage(
222 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
223 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
224 note='Downloading playlist')
226 videos_paths = re.findall(
227 '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
229 self.url_result('http://vod.tvp.pl%s' % v_path, ie=TVPIE.ie_key())
230 for v_path in videos_paths]
235 'display_id': display_id,