]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/markiza.py
debian/README.source: Document source-only uploads procedure.
[youtubedl] / youtube_dl / extractor / markiza.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9 orderedSet,
10 parse_duration,
11 try_get,
12 )
13
14
15 class MarkizaIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?videoarchiv\.markiza\.sk/(?:video/(?:[^/]+/)*|embed/)(?P<id>\d+)(?:[_/]|$)'
17 _TESTS = [{
18 'url': 'http://videoarchiv.markiza.sk/video/oteckovia/84723_oteckovia-109',
19 'md5': 'ada4e9fad038abeed971843aa028c7b0',
20 'info_dict': {
21 'id': '139078',
22 'ext': 'mp4',
23 'title': 'Oteckovia 109',
24 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
25 'thumbnail': r're:^https?://.*\.jpg$',
26 'duration': 2760,
27 },
28 }, {
29 'url': 'http://videoarchiv.markiza.sk/video/televizne-noviny/televizne-noviny/85430_televizne-noviny',
30 'info_dict': {
31 'id': '85430',
32 'title': 'Televízne noviny',
33 },
34 'playlist_count': 23,
35 }, {
36 'url': 'http://videoarchiv.markiza.sk/video/oteckovia/84723',
37 'only_matching': True,
38 }, {
39 'url': 'http://videoarchiv.markiza.sk/video/84723',
40 'only_matching': True,
41 }, {
42 'url': 'http://videoarchiv.markiza.sk/video/filmy/85190_kamenak',
43 'only_matching': True,
44 }, {
45 'url': 'http://videoarchiv.markiza.sk/video/reflex/zo-zakulisia/84651_pribeh-alzbetky',
46 'only_matching': True,
47 }, {
48 'url': 'http://videoarchiv.markiza.sk/embed/85295',
49 'only_matching': True,
50 }]
51
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54
55 data = self._download_json(
56 'http://videoarchiv.markiza.sk/json/video_jwplayer7.json',
57 video_id, query={'id': video_id})
58
59 info = self._parse_jwplayer_data(data, m3u8_id='hls', mpd_id='dash')
60
61 if info.get('_type') == 'playlist':
62 info.update({
63 'id': video_id,
64 'title': try_get(
65 data, lambda x: x['details']['name'], compat_str),
66 })
67 else:
68 info['duration'] = parse_duration(
69 try_get(data, lambda x: x['details']['duration'], compat_str))
70 return info
71
72
73 class MarkizaPageIE(InfoExtractor):
74 _VALID_URL = r'https?://(?:www\.)?(?:(?:[^/]+\.)?markiza|tvnoviny)\.sk/(?:[^/]+/)*(?P<id>\d+)_'
75 _TESTS = [{
76 'url': 'http://www.markiza.sk/soubiz/zahranicny/1923705_oteckovia-maju-svoj-den-ti-slavni-nie-su-o-nic-menej-rozkosni',
77 'md5': 'ada4e9fad038abeed971843aa028c7b0',
78 'info_dict': {
79 'id': '139355',
80 'ext': 'mp4',
81 'title': 'Oteckovia 110',
82 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
83 'thumbnail': r're:^https?://.*\.jpg$',
84 'duration': 2604,
85 },
86 'params': {
87 'skip_download': True,
88 },
89 }, {
90 'url': 'http://dajto.markiza.sk/filmy-a-serialy/1774695_frajeri-vo-vegas',
91 'only_matching': True,
92 }, {
93 'url': 'http://superstar.markiza.sk/aktualne/1923870_to-je-ale-telo-spevacka-ukazala-sexy-postavicku-v-bikinach',
94 'only_matching': True,
95 }, {
96 'url': 'http://hybsa.markiza.sk/aktualne/1923790_uzasna-atmosfera-na-hybsa-v-poprade-superstaristi-si-prve-koncerty-pred-davom-ludi-poriadne-uzili',
97 'only_matching': True,
98 }, {
99 'url': 'http://doma.markiza.sk/filmy/1885250_moja-vysnivana-svadba',
100 'only_matching': True,
101 }, {
102 'url': 'http://www.tvnoviny.sk/domace/1923887_po-smrti-manzela-ju-cakalo-poriadne-prekvapenie',
103 'only_matching': True,
104 }]
105
106 @classmethod
107 def suitable(cls, url):
108 return False if MarkizaIE.suitable(url) else super(MarkizaPageIE, cls).suitable(url)
109
110 def _real_extract(self, url):
111 playlist_id = self._match_id(url)
112
113 webpage = self._download_webpage(
114 # Downloading for some hosts (e.g. dajto, doma) fails with 500
115 # although everything seems to be OK, so considering 500
116 # status code to be expected.
117 url, playlist_id, expected_status=500)
118
119 entries = [
120 self.url_result('http://videoarchiv.markiza.sk/video/%s' % video_id)
121 for video_id in orderedSet(re.findall(
122 r'(?:initPlayer_|data-entity=["\']|id=["\']player_)(\d+)',
123 webpage))]
124
125 return self.playlist_result(entries, playlist_id)