]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nova.py
Update Standards-Version to 3.9.8 (no changes required).
[youtubedl] / youtube_dl / extractor / nova.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 clean_html,
9 unified_strdate,
10 )
11
12
13 class NovaIE(InfoExtractor):
14 IE_DESC = 'TN.cz, Prásk.tv, Nova.cz, Novaplus.cz, FANDA.tv, Krásná.cz and Doma.cz'
15 _VALID_URL = r'https?://(?:[^.]+\.)?(?P<site>tv(?:noviny)?|tn|novaplus|vymena|fanda|krasna|doma|prask)\.nova\.cz/(?:[^/]+/)+(?P<id>[^/]+?)(?:\.html|/|$)'
16 _TESTS = [{
17 'url': 'http://tvnoviny.nova.cz/clanek/novinky/co-na-sebe-sportaci-praskli-vime-jestli-pujde-hrdlicka-na-materskou.html?utm_source=tvnoviny&utm_medium=cpfooter&utm_campaign=novaplus',
18 'info_dict': {
19 'id': '1608920',
20 'display_id': 'co-na-sebe-sportaci-praskli-vime-jestli-pujde-hrdlicka-na-materskou',
21 'ext': 'flv',
22 'title': 'Duel: Michal Hrdlička a Petr Suchoň',
23 'description': 'md5:d0cc509858eee1b1374111c588c6f5d5',
24 'thumbnail': 're:^https?://.*\.(?:jpg)',
25 },
26 'params': {
27 # rtmp download
28 'skip_download': True,
29 }
30 }, {
31 'url': 'http://tn.nova.cz/clanek/tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci.html#player_13260',
32 'md5': '1dd7b9d5ea27bc361f110cd855a19bd3',
33 'info_dict': {
34 'id': '1757139',
35 'display_id': 'tajemstvi-ukryte-v-podzemi-specialni-nemocnice-v-prazske-krci',
36 'ext': 'mp4',
37 'title': 'Podzemní nemocnice v pražské Krči',
38 'description': 'md5:f0a42dd239c26f61c28f19e62d20ef53',
39 'thumbnail': 're:^https?://.*\.(?:jpg)',
40 }
41 }, {
42 'url': 'http://novaplus.nova.cz/porad/policie-modrava/video/5591-policie-modrava-15-dil-blondynka-na-hrbitove',
43 'info_dict': {
44 'id': '1756825',
45 'display_id': '5591-policie-modrava-15-dil-blondynka-na-hrbitove',
46 'ext': 'flv',
47 'title': 'Policie Modrava - 15. díl - Blondýnka na hřbitově',
48 'description': 'md5:dc24e50be5908df83348e50d1431295e', # Make sure this description is clean of html tags
49 'thumbnail': 're:^https?://.*\.(?:jpg)',
50 },
51 'params': {
52 # rtmp download
53 'skip_download': True,
54 }
55 }, {
56 'url': 'http://novaplus.nova.cz/porad/televizni-noviny/video/5585-televizni-noviny-30-5-2015/',
57 'info_dict': {
58 'id': '1756858',
59 'ext': 'flv',
60 'title': 'Televizní noviny - 30. 5. 2015',
61 'thumbnail': 're:^https?://.*\.(?:jpg)',
62 'upload_date': '20150530',
63 },
64 'params': {
65 # rtmp download
66 'skip_download': True,
67 }
68 }, {
69 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
70 'info_dict': {
71 'id': '1753621',
72 'ext': 'mp4',
73 'title': 'Zaklínač 3: Divoký hon',
74 'description': 're:.*Pokud se stejně jako my nemůžete.*',
75 'thumbnail': 're:https?://.*\.jpg(\?.*)?',
76 'upload_date': '20150521',
77 },
78 'params': {
79 # rtmp download
80 'skip_download': True,
81 }
82 }, {
83 'url': 'http://sport.tn.nova.cz/clanek/sport/hokej/nhl/zivot-jde-dal-hodnotil-po-vyrazeni-z-playoff-jiri-sekac.html',
84 'only_matching': True,
85 }, {
86 'url': 'http://fanda.nova.cz/clanek/fun-and-games/krvavy-epos-zaklinac-3-divoky-hon-vychazi-vyhrajte-ho-pro-sebe.html',
87 'only_matching': True,
88 }, {
89 'url': 'http://doma.nova.cz/clanek/zdravi/prijdte-se-zapsat-do-registru-kostni-drene-jiz-ve-stredu-3-cervna.html',
90 'only_matching': True,
91 }, {
92 'url': 'http://prask.nova.cz/clanek/novinky/co-si-na-sobe-nase-hvezdy-nechaly-pojistit.html',
93 'only_matching': True,
94 }, {
95 'url': 'http://tv.nova.cz/clanek/novinky/zivot-je-zivot-bondovsky-trailer.html',
96 'only_matching': True,
97 }]
98
99 def _real_extract(self, url):
100 mobj = re.match(self._VALID_URL, url)
101 display_id = mobj.group('id')
102 site = mobj.group('site')
103
104 webpage = self._download_webpage(url, display_id)
105
106 video_id = self._search_regex(
107 [r"(?:media|video_id)\s*:\s*'(\d+)'",
108 r'media=(\d+)',
109 r'id="article_video_(\d+)"',
110 r'id="player_(\d+)"'],
111 webpage, 'video id')
112
113 config_url = self._search_regex(
114 r'src="(http://tn\.nova\.cz/bin/player/videojs/config\.php\?[^"]+)"',
115 webpage, 'config url', default=None)
116
117 if not config_url:
118 DEFAULT_SITE_ID = '23000'
119 SITES = {
120 'tvnoviny': DEFAULT_SITE_ID,
121 'novaplus': DEFAULT_SITE_ID,
122 'vymena': DEFAULT_SITE_ID,
123 'krasna': DEFAULT_SITE_ID,
124 'fanda': '30',
125 'tn': '30',
126 'doma': '30',
127 }
128
129 site_id = self._search_regex(
130 r'site=(\d+)', webpage, 'site id', default=None) or SITES.get(site, DEFAULT_SITE_ID)
131
132 config_url = ('http://tn.nova.cz/bin/player/videojs/config.php?site=%s&media=%s&jsVar=vjsconfig'
133 % (site_id, video_id))
134
135 config = self._download_json(
136 config_url, display_id,
137 'Downloading config JSON',
138 transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
139
140 mediafile = config['mediafile']
141 video_url = mediafile['src']
142
143 m = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+?))/&*(?P<playpath>.+)$', video_url)
144 if m:
145 formats = [{
146 'url': m.group('url'),
147 'app': m.group('app'),
148 'play_path': m.group('playpath'),
149 'player_path': 'http://tvnoviny.nova.cz/static/shared/app/videojs/video-js.swf',
150 'ext': 'flv',
151 }]
152 else:
153 formats = [{
154 'url': video_url,
155 }]
156 self._sort_formats(formats)
157
158 title = mediafile.get('meta', {}).get('title') or self._og_search_title(webpage)
159 description = clean_html(self._og_search_description(webpage, default=None))
160 thumbnail = config.get('poster')
161
162 if site == 'novaplus':
163 upload_date = unified_strdate(self._search_regex(
164 r'(\d{1,2}-\d{1,2}-\d{4})$', display_id, 'upload date', default=None))
165 elif site == 'fanda':
166 upload_date = unified_strdate(self._search_regex(
167 r'<span class="date_time">(\d{1,2}\.\d{1,2}\.\d{4})', webpage, 'upload date', default=None))
168 else:
169 upload_date = None
170
171 return {
172 'id': video_id,
173 'display_id': display_id,
174 'title': title,
175 'description': description,
176 'upload_date': upload_date,
177 'thumbnail': thumbnail,
178 'formats': formats,
179 }