]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/tvp.py
release 2016.06.23.1
[yt-dlp.git] / youtube_dl / extractor / tvp.py
CommitLineData
6f8cb242 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 8
6f8cb242
S
9class TVPIE(InfoExtractor):
10 IE_NAME = 'tvp'
11 IE_DESC = 'Telewizja Polska'
12 _VALID_URL = r'https?://[^/]+\.tvp\.(?:pl|info)/(?:(?!\d+/)[^/]+/)*(?P<id>\d+)'
fb4b030a
PH
13
14 _TESTS = [{
6f8cb242 15 'url': 'http://vod.tvp.pl/194536/i-seria-odc-13',
030aa5d9 16 'md5': '8aa518c15e5cc32dfe8db400dc921fbb',
fb4b030a
PH
17 'info_dict': {
18 'id': '194536',
19 'ext': 'mp4',
20 'title': 'Czas honoru, I seria – odc. 13',
fb4b030a
PH
21 },
22 }, {
23 'url': 'http://www.tvp.pl/there-can-be-anything-so-i-shortened-it/17916176',
030aa5d9 24 'md5': 'c3b15ed1af288131115ff17a17c19dda',
fb4b030a
PH
25 'info_dict': {
26 'id': '17916176',
27 'ext': 'mp4',
28 'title': 'TVP Gorzów pokaże filmy studentów z podroży dookoła świata',
29 },
fb4b030a
PH
30 }, {
31 'url': 'http://vod.tvp.pl/seriale/obyczajowe/na-sygnale/sezon-2-27-/odc-39/17834272',
6f8cb242
S
32 'only_matching': True,
33 }, {
34 'url': 'http://wiadomosci.tvp.pl/25169746/24052016-1200',
35 'only_matching': True,
36 }, {
37 'url': 'http://krakow.tvp.pl/25511623/25lecie-mck-wyjatkowe-miejsce-na-mapie-krakowa',
38 'only_matching': True,
39 }, {
40 'url': 'http://teleexpress.tvp.pl/25522307/wierni-wzieli-udzial-w-procesjach',
41 'only_matching': True,
42 }, {
43 'url': 'http://sport.tvp.pl/25522165/krychowiak-uspokaja-w-sprawie-kontuzji-dwa-tygodnie-to-maksimum',
44 'only_matching': True,
45 }, {
46 'url': 'http://www.tvp.info/25511919/trwa-rewolucja-wladza-zdecydowala-sie-na-pogwalcenie-konstytucji',
47 'only_matching': True,
fb4b030a 48 }]
5137ebac
MC
49
50 def _real_extract(self, url):
fb4b030a 51 video_id = self._match_id(url)
030aa5d9 52
29f400b9
TF
53 webpage = self._download_webpage(
54 'http://www.tvp.pl/sess/tvplayer.php?object_id=%s' % video_id, video_id)
fb4b030a 55
030aa5d9
S
56 title = self._search_regex(
57 r'name\s*:\s*([\'"])Title\1\s*,\s*value\s*:\s*\1(?P<title>.+?)\1',
58 webpage, 'title', group='title')
59 series_title = self._search_regex(
60 r'name\s*:\s*([\'"])SeriesTitle\1\s*,\s*value\s*:\s*\1(?P<series>.+?)\1',
29f400b9 61 webpage, 'series', group='series', default=None)
030aa5d9
S
62 if series_title:
63 title = '%s, %s' % (series_title, title)
64
65 thumbnail = self._search_regex(
66 r"poster\s*:\s*'([^']+)'", webpage, 'thumbnail', default=None)
fb4b030a 67
29f400b9
TF
68 video_url = self._search_regex(
69 r'0:{src:([\'"])(?P<url>.*?)\1', webpage, 'formats', group='url', default=None)
030aa5d9 70 if not video_url:
29f400b9
TF
71 video_url = self._download_json(
72 'http://www.tvp.pl/pub/stat/videofileinfo?video_id=%s' % video_id,
73 video_id)['video_url']
74
75 ext = video_url.rsplit('.', 1)[-1]
76 if ext != 'ism/manifest':
77 if '/' in ext:
78 ext = 'mp4'
fb4b030a
PH
79 formats = [{
80 'format_id': 'direct',
29f400b9 81 'url': video_url,
fb4b030a
PH
82 'ext': ext,
83 }]
29f400b9
TF
84 else:
85 m3u8_url = re.sub('([^/]*)\.ism/manifest', r'\1.ism/\1.m3u8', video_url)
86 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
fb4b030a
PH
87
88 self._sort_formats(formats)
89
90 return {
91 'id': video_id,
92 'title': title,
030aa5d9 93 'thumbnail': thumbnail,
fb4b030a
PH
94 'formats': formats,
95 }
6ce2c678
TF
96
97
6f8cb242
S
98class TVPSeriesIE(InfoExtractor):
99 IE_NAME = 'tvp:series'
6ce2c678
TF
100 _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
101
fb4b030a
PH
102 _TESTS = [{
103 'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
104 'info_dict': {
105 'title': 'Ogniem i mieczem',
106 'id': '4278026',
107 },
108 'playlist_count': 4,
109 }, {
110 'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
111 'info_dict': {
112 'title': 'Boso przez świat',
113 'id': '9329207',
114 },
115 'playlist_count': 86,
116 }]
6ce2c678 117
6ce2c678
TF
118 def _real_extract(self, url):
119 display_id = self._match_id(url)
2415951e 120 webpage = self._download_webpage(url, display_id, tries=5)
fb4b030a 121
6ce2c678 122 title = self._html_search_regex(
2415951e 123 r'(?s) id=[\'"]path[\'"]>(?:.*? / ){2}(.*?)</span>', webpage, 'series')
6ce2c678 124 playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
2415951e 125 playlist = self._download_webpage(
6ce2c678 126 'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
fb4b030a
PH
127 'edId=0&sort=&page=0&pageSize=10000' % playlist_id, display_id, tries=5,
128 note='Downloading playlist')
129
6ce2c678
TF
130 videos_paths = re.findall(
131 '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
132 entries = [
6f8cb242 133 self.url_result('http://vod.tvp.pl%s' % v_path, ie=TVPIE.ie_key())
6ce2c678 134 for v_path in videos_paths]
fb4b030a 135
6ce2c678
TF
136 return {
137 '_type': 'playlist',
138 'id': playlist_id,
139 'display_id': display_id,
140 'title': title,
141 'entries': entries,
142 }