1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-05 16:37:42 +00:00
youtube-dl/youtube_dl/extractor/tv2hu.py

63 lines
2.4 KiB
Python
Raw Normal View History

2016-08-31 08:56:11 +00:00
# encoding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2017-04-12 18:31:18 +00:00
from ..utils import int_or_none
2016-08-31 08:56:11 +00:00
2017-04-12 18:31:18 +00:00
class TV2HuIE(InfoExtractor):
IE_NAME = 'tv2.hu'
_VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:[^/]+/)+(?P<id>\d+)_[^/?#]+?\.html'
2016-08-31 08:56:11 +00:00
_TESTS = [{
'url': 'http://tv2.hu/ezek_megorultek/217679_ezek-megorultek---1.-adas-1.-resz.html',
2017-04-12 18:31:18 +00:00
'md5': '585e58e2e090f34603804bb2c48e98d8',
2016-08-31 08:56:11 +00:00
'info_dict': {
'id': '217679',
'ext': 'mp4',
'title': 'Ezek megőrültek! - 1. adás 1. rész',
'upload_date': '20160826',
'thumbnail': r're:^https?://.*\.jpg$'
2016-08-31 08:56:11 +00:00
}
}, {
'url': 'http://tv2.hu/ezek_megorultek/teljes_adasok/217677_ezek-megorultek---1.-adas-2.-resz.html',
'only_matching': True
}, {
'url': 'http://tv2.hu/musoraink/aktiv/aktiv_teljes_adas/217963_aktiv-teljes-adas---2016.08.30..html',
'only_matching': True
}]
def _real_extract(self, url):
video_id = self._match_id(url)
2017-04-12 18:31:18 +00:00
webpage = self._download_webpage(url, video_id)
json_url = self._search_regex(
r'jsonUrl\s*=\s*"([^"]+)"', webpage, 'json url')
json_data = self._download_json(json_url, video_id)
formats = []
for b in ('bitrates', 'backupBitrates'):
bitrates = json_data.get(b, {})
m3u8_url = bitrates.get('hls')
if m3u8_url:
formats.extend(self._extract_wowza_formats(
m3u8_url, video_id, skip_protocols=['rtmp', 'rtsp']))
for mp4_url in bitrates.get('mp4', []):
height = int_or_none(self._search_regex(
r'\.(\d+)p\.mp4', mp4_url, 'height', default=None))
formats.append({
'format_id': 'http' + ('-%d' % height if height else ''),
'url': mp4_url,
'height': height,
'width': int_or_none(height / 9.0 * 16.0 if height else None),
})
2016-08-31 08:56:11 +00:00
self._sort_formats(formats)
return {
'id': video_id,
'title': self._og_search_title(webpage).strip(),
2017-04-12 18:31:18 +00:00
'thumbnail': self._og_search_thumbnail(webpage),
'upload_date': self._search_regex(
r'/vod/(\d{8})/', json_url, 'upload_date', default=None),
'formats': formats,
2016-08-31 08:56:11 +00:00
}