]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/dvtv.py
[dvtv] Add new extractor
[yt-dlp.git] / youtube_dl / extractor / dvtv.py
CommitLineData
5f627b44
PK
1# coding: utf-8
2
3from __future__ import unicode_literals
4
5import re
6import json
7from .common import InfoExtractor
8from ..utils import (
9 ExtractorError,
10 js_to_json,
11 unescapeHTML
12)
13
14
15class DVTVIE(InfoExtractor):
16 IE_NAME = 'dvtv'
17 IE_DESC = 'http://video.aktualne.cz/dvtv/'
18
19 _VALID_URL = r'http://video\.aktualne\.cz/dvtv/(?P<id>[a-z0-9-]+/r~[0-9a-f]{32})/?'
20
21 _TESTS = [{
22 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
23 'md5': '75800f964fa0f82939a2914563301f72',
24 'info_dict': {
25 'id': 'e5efe9ca855511e4833a0025900fea04',
26 'ext': 'webm',
27 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně'
28 }
29 }, {
30 'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/',
31 'md5': 'd50455195a67a94c57f931360cc68a1b',
32 'info_dict': {
33 'id': '82ed4322849211e4a10c0025900fea04',
34 'ext': 'webm',
35 'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala'
36 }
37 }]
38
39 def _real_extract(self, url):
40 video_id = self._match_id(url)
41 webpage = self._download_webpage(url, video_id)
42
43 code = self._search_regex(r'embedData[0-9a-f]{32}\[\'asset\'\] = (\{.+?\});', webpage, 'video JSON', flags=re.DOTALL)
44 payload = self._parse_json(code, video_id, transform_source=js_to_json)
45 formats = []
46 for source in payload['sources']:
47 formats.append({
48 'url': source['file'],
49 'ext': source['type'][6:],
50 'format': '%s %s' % (source['type'][6:], source['label']),
51 'format_id': '%s-%s' % (source['type'][6:], source['label']),
52 'resolution': source['label'],
53 'fps': 25,
54 'preference': -1 if source['type'][6:] == 'mp4' and source['label'] == '720p' else -2
55 })
56
57 return {
58 'id': video_id[-32:],
59 'display_id': video_id[:-35],
60 'title': unescapeHTML(payload['title']),
61 'thumbnail': 'http:%s' % payload['image'],
62 'formats': formats
63 }