]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/tvp.py
[common] Fix non-bootstrapped support in f4m
[yt-dlp.git] / youtube_dl / extractor / tvp.py
CommitLineData
29f400b9 1# -*- coding: utf-8 -*-
24144e3b 2from __future__ import unicode_literals
5137ebac 3
29f400b9
TF
4import re
5
5137ebac 6from .common import InfoExtractor
c3a3028f 7
5137ebac
MC
8
9class TvpIE(InfoExtractor):
24144e3b 10 IE_NAME = 'tvp.pl'
fb4b030a
PH
11 _VALID_URL = r'https?://(?:vod|www)\.tvp\.pl/.*/(?P<id>\d+)$'
12
13 _TESTS = [{
14 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem/wideo/odc-2/4278035',
030aa5d9 15 'md5': 'cdd98303338b8a7f7abab5cd14092bf2',
fb4b030a
PH
16 'info_dict': {
17 'id': '4278035',
18 'ext': 'wmv',
19 'title': 'Ogniem i mieczem, odc. 2',
fb4b030a
PH
20 },
21 }, {
22 'url': 'http://vod.tvp.pl/seriale/obyczajowe/czas-honoru/sezon-1-1-13/i-seria-odc-13/194536',
030aa5d9 23 'md5': '8aa518c15e5cc32dfe8db400dc921fbb',
fb4b030a
PH
24 'info_dict': {
25 'id': '194536',
26 'ext': 'mp4',
27 'title': 'Czas honoru, I seria – odc. 13',
fb4b030a
PH
28 },
29 }, {
30 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
030aa5d9 31 'md5': 'c3b15ed1af288131115ff17a17c19dda',
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',
36 },
fb4b030a
PH
37 }, {
38 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
030aa5d9 39 'md5': 'c3b15ed1af288131115ff17a17c19dda',
fb4b030a
PH
40 'info_dict': {
41 'id': '17834272',
42 'ext': 'mp4',
43 'title': 'Na sygnale, odc. 39',
fb4b030a
PH
44 },
45 }]
5137ebac
MC
46
47 def _real_extract(self, url):
fb4b030a 48 video_id = self._match_id(url)
030aa5d9 49
29f400b9
TF
50 webpage = self._download_webpage(
51 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
fb4b030a 52
030aa5d9
S
53 title = self._search_regex(
54 r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
55 webpage, 'title', group='title')
56 series_title = self._search_regex(
57 r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
29f400b9 58 webpage, 'series', group='series', default=None)
030aa5d9
S
59 if series_title:
60 title = '%s, %s' % (series_title, title)
61
62 thumbnail = self._search_regex(
63 r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
fb4b030a 64
29f400b9
TF
65 video_url = self._search_regex(
66 r'0:{src:([\'"])(?P<url>.*?)\1', webpage, 'formats', group='url', default=None)
030aa5d9 67 if not video_url:
29f400b9
TF
68 video_url = self._download_json(
69 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
70 video_id)['video_url']
71
72 ext = video_url.rsplit('.', 1)[-1]
73 if ext != 'ism/manifest':
74 if '/' in ext:
75 ext = 'mp4'
fb4b030a
PH
76 formats = [{
77 'format_id': 'direct',
29f400b9 78 'url': video_url,
fb4b030a
PH
79 'ext': ext,
80 }]
29f400b9
TF
81 else:
82 m3u8_url = re.sub('([^/]*)\.ism/manifest', r'\1.ism/\1.m3u8', video_url)
83 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
fb4b030a
PH
84
85 self._sort_formats(formats)
86
87 return {
88 'id': video_id,
89 'title': title,
030aa5d9 90 'thumbnail': thumbnail,
fb4b030a
PH
91 'formats': formats,
92 }
6ce2c678
TF
93
94
95class TvpSeriesIE(InfoExtractor):
96 IE_NAME = 'tvp.pl:Series'
97 _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
98
fb4b030a
PH
99 _TESTS = [{
100 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
101 'info_dict': {
102 'title': 'Ogniem i mieczem',
103 'id': '4278026',
104 },
105 'playlist_count': 4,
106 }, {
107 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
108 'info_dict': {
109 'title': 'Boso przez świat',
110 'id': '9329207',
111 },
112 'playlist_count': 86,
113 }]
6ce2c678 114
6ce2c678
TF
115 def _real_extract(self, url):
116 display_id = self._match_id(url)
2415951e 117 webpage = self._download_webpage(url, display_id, tries=5)
fb4b030a 118
6ce2c678 119 title = self._html_search_regex(
2415951e 120 r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
6ce2c678 121 playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
2415951e 122 playlist = self._download_webpage(
6ce2c678 123 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
fb4b030a
PH
124 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
125 note='Downloading playlist')
126
6ce2c678
TF
127 videos_paths = re.findall(
128 '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
129 entries = [
130 self.url_result('http://vod.tvp.pl%s' % v_path, ie=TvpIE.ie_key())
131 for v_path in videos_paths]
fb4b030a 132
6ce2c678
TF
133 return {
134 '_type': 'playlist',
135 'id': playlist_id,
136 'display_id': display_id,
137 'title': title,
138 'entries': entries,
139 }