]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/dvtv.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / dvtv.py
CommitLineData
5f627b44 1# coding: utf-8
5f627b44
PK
2from __future__ import unicode_literals
3
1d4247f6
PK
4import re
5
5f627b44
PK
6from .common import InfoExtractor
7from ..utils import (
b9465395 8 js_to_json,
1d4247f6 9 unescapeHTML,
081d6e47 10 ExtractorError,
5f627b44
PK
11)
12
13
14class DVTVIE(InfoExtractor):
b9465395 15 IE_NAME = 'dvtv'
1d4247f6 16 IE_DESC = 'http://video.aktualne.cz/'
b9465395 17
5886b38d 18 _VALID_URL = r'https?://video\.aktualne\.cz/(?:[^/]+/)+r~(?P<id>[0-9a-f]{32})'
b9465395
PH
19
20 _TESTS = [{
21 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
1d4247f6 22 'md5': '67cb83e4a955d36e1b5d31993134a0c2',
b9465395 23 'info_dict': {
1d4247f6
PK
24 'id': 'dc0768de855511e49e4b0025900fea04',
25 'ext': 'mp4',
081d6e47 26 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně',
b9465395
PH
27 }
28 }, {
29 'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/',
30 'md5': '6388f1941b48537dbd28791f712af8bf',
31 'info_dict': {
1d4247f6 32 'id': '72c02230849211e49f60002590604f2e',
b9465395 33 'ext': 'mp4',
081d6e47 34 'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala',
b9465395 35 }
1d4247f6
PK
36 }, {
37 'url': 'http://video.aktualne.cz/dvtv/dvtv-16-12-2014-utok-talibanu-boj-o-kliniku-uprchlici/r~973eb3bc854e11e498be002590604f2e/',
38 'info_dict': {
39 'title': 'DVTV 16. 12. 2014: útok Talibanu, boj o kliniku, uprchlíci',
081d6e47 40 'id': '973eb3bc854e11e498be002590604f2e',
1d4247f6
PK
41 },
42 'playlist': [{
43 'md5': 'da7ca6be4935532241fa9520b3ad91e4',
44 'info_dict': {
45 'id': 'b0b40906854d11e4bdad0025900fea04',
46 'ext': 'mp4',
47 'title': 'Drtinová Veselovský TV 16. 12. 2014: Témata dne'
48 }
49 }, {
50 'md5': '5f7652a08b05009c1292317b449ffea2',
51 'info_dict': {
52 'id': '420ad9ec854a11e4bdad0025900fea04',
53 'ext': 'mp4',
54 'title': 'Školní masakr možná změní boj s Talibanem, říká novinářka'
55 }
56 }, {
57 'md5': '498eb9dfa97169f409126c617e2a3d64',
58 'info_dict': {
59 'id': '95d35580846a11e4b6d20025900fea04',
60 'ext': 'mp4',
61 'title': 'Boj o kliniku: Veřejný zájem, nebo právo na majetek?'
62 }
63 }, {
64 'md5': 'b8dc6b744844032dab6ba3781a7274b9',
65 'info_dict': {
66 'id': '6fe14d66853511e4833a0025900fea04',
67 'ext': 'mp4',
68 'title': 'Pánek: Odmítání syrských uprchlíků je ostudou české vlády'
69 }
081d6e47
S
70 }],
71 }, {
72 'url': 'http://video.aktualne.cz/v-cechach-poprve-zazni-zelenkova-zrestaurovana-mse/r~45b4b00483ec11e4883b002590604f2e/',
73 'only_matching': True,
b9465395
PH
74 }]
75
1d4247f6
PK
76 def _parse_video_metadata(self, js, video_id):
77 metadata = self._parse_json(js, video_id, transform_source=js_to_json)
b9465395 78
b9465395 79 formats = []
1d4247f6
PK
80 for video in metadata['sources']:
81 ext = video['type'][6:]
b9465395 82 formats.append({
1d4247f6 83 'url': video['file'],
b9465395 84 'ext': ext,
1d4247f6
PK
85 'format_id': '%s-%s' % (ext, video['label']),
86 'height': int(video['label'].rstrip('p')),
b9465395
PH
87 'fps': 25,
88 })
1d4247f6 89
b9465395
PH
90 self._sort_formats(formats)
91
92 return {
1d4247f6
PK
93 'id': metadata['mediaid'],
94 'title': unescapeHTML(metadata['title']),
2c2a4258 95 'thumbnail': self._proto_relative_url(metadata['image'], 'http:'),
b9465395
PH
96 'formats': formats
97 }
1d4247f6
PK
98
99 def _real_extract(self, url):
100 video_id = self._match_id(url)
081d6e47 101
1d4247f6
PK
102 webpage = self._download_webpage(url, video_id)
103
081d6e47
S
104 # single video
105 item = self._search_regex(
106 r"(?s)embedData[0-9a-f]{32}\['asset'\]\s*=\s*(\{.+?\});",
107 webpage, 'video', default=None, fatal=False)
1d4247f6 108
081d6e47
S
109 if item:
110 return self._parse_video_metadata(item, video_id)
1d4247f6
PK
111
112 # playlist
113 items = re.findall(
081d6e47 114 r"(?s)BBX\.context\.assets\['[0-9a-f]{32}'\]\.push\(({.+?})\);",
1d4247f6
PK
115 webpage)
116
117 if items:
118 return {
119 '_type': 'playlist',
120 'id': video_id,
121 'title': self._og_search_title(webpage),
122 'entries': [self._parse_video_metadata(i, video_id) for i in items]
123 }
124
081d6e47 125 raise ExtractorError('Could not find neither video nor playlist')