]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tv2hu.py
debian/control: Set 'Rules-Requires-Root: no'.
[youtubedl] / youtube_dl / extractor / tv2hu.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6
7
8 class TV2HuIE(InfoExtractor):
9 IE_NAME = 'tv2.hu'
10 _VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:[^/]+/)+(?P<id>\d+)_[^/?#]+?\.html'
11 _TESTS = [{
12 'url': 'http://tv2.hu/ezek_megorultek/217679_ezek-megorultek---1.-adas-1.-resz.html',
13 'md5': '585e58e2e090f34603804bb2c48e98d8',
14 'info_dict': {
15 'id': '217679',
16 'ext': 'mp4',
17 'title': 'Ezek megőrültek! - 1. adás 1. rész',
18 'upload_date': '20160826',
19 'thumbnail': r're:^https?://.*\.jpg$'
20 }
21 }, {
22 'url': 'http://tv2.hu/ezek_megorultek/teljes_adasok/217677_ezek-megorultek---1.-adas-2.-resz.html',
23 'only_matching': True
24 }, {
25 'url': 'http://tv2.hu/musoraink/aktiv/aktiv_teljes_adas/217963_aktiv-teljes-adas---2016.08.30..html',
26 'only_matching': True
27 }]
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31 webpage = self._download_webpage(url, video_id)
32 json_url = self._search_regex(
33 r'jsonUrl\s*=\s*"([^"]+)"', webpage, 'json url')
34 json_data = self._download_json(json_url, video_id)
35
36 formats = []
37 for b in ('bitrates', 'backupBitrates'):
38 bitrates = json_data.get(b, {})
39 m3u8_url = bitrates.get('hls')
40 if m3u8_url:
41 formats.extend(self._extract_wowza_formats(
42 m3u8_url, video_id, skip_protocols=['rtmp', 'rtsp']))
43
44 for mp4_url in bitrates.get('mp4', []):
45 height = int_or_none(self._search_regex(
46 r'\.(\d+)p\.mp4', mp4_url, 'height', default=None))
47 formats.append({
48 'format_id': 'http' + ('-%d' % height if height else ''),
49 'url': mp4_url,
50 'height': height,
51 'width': int_or_none(height / 9.0 * 16.0 if height else None),
52 })
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': self._og_search_title(webpage).strip(),
58 'thumbnail': self._og_search_thumbnail(webpage),
59 'upload_date': self._search_regex(
60 r'/vod/(\d{8})/', json_url, 'upload_date', default=None),
61 'formats': formats,
62 }