From: Remita Amine Date: Wed, 12 Apr 2017 18:31:18 +0000 (+0100) Subject: [tv2hu] improve extraction X-Git-Url: http://git.oshgnacknak.de/?a=commitdiff_plain;h=e4d74e2778ca283330460d893a0923820a74df66;p=youtube-dl [tv2hu] improve extraction --- diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 7484099f6..45591f2a7 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -1031,7 +1031,7 @@ from .tv2 import ( TV2IE, TV2ArticleIE, ) -from .tv2hu import TV2HUIE +from .tv2hu import TV2HuIE from .tv3 import TV3IE from .tv4 import TV4IE from .tv5mondeplus import TV5MondePlusIE diff --git a/youtube_dl/extractor/tv2hu.py b/youtube_dl/extractor/tv2hu.py index cb1ce822a..ce01cc80d 100644 --- a/youtube_dl/extractor/tv2hu.py +++ b/youtube_dl/extractor/tv2hu.py @@ -1,29 +1,22 @@ # encoding: utf-8 from __future__ import unicode_literals -import re - from .common import InfoExtractor +from ..utils import int_or_none -class TV2HUIE(InfoExtractor): - IE_NAME = 'tv2.hu' - _VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:musoraink/)?(?P[^/]+)/(?:teljes_adasok/)?(?P[0-9]+)_(.+?)\.html' - _JSON_URL = r'(?Phttps?://.+?\.tv2\.hu/vod/(?P\d+)/id_(?P\d+).+?&type=json)' +class TV2HuIE(InfoExtractor): + IE_NAME = 'tv2.hu' + _VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:[^/]+/)+(?P\d+)_[^/?#]+?\.html' _TESTS = [{ 'url': 'http://tv2.hu/ezek_megorultek/217679_ezek-megorultek---1.-adas-1.-resz.html', + 'md5': '585e58e2e090f34603804bb2c48e98d8', 'info_dict': { 'id': '217679', 'ext': 'mp4', 'title': 'Ezek megőrültek! - 1. adás 1. rész', - 'upload_id': '220289', 'upload_date': '20160826', - 'uploader': 'ezek_megorultek', 'thumbnail': 're:^https?://.*\.jpg$' - }, - 'params': { - # m3u8 download - 'skip_download': True, } }, { 'url': 'http://tv2.hu/ezek_megorultek/teljes_adasok/217677_ezek-megorultek---1.-adas-2.-resz.html', @@ -35,44 +28,35 @@ class TV2HUIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - webpage = self._download_webpage( - url, video_id, 'Downloading info page') - - json_url = re.search(self._JSON_URL, webpage) - - json_data = self._download_json( - json_url.group('json_url'), video_id, 'Downloading video info') - - manifest_url = json_data['bitrates']['hls'] - - formats = self._extract_m3u8_formats( - manifest_url, video_id, 'mp4', entry_protocol='m3u8_native') - - for i in range(len(json_data['bitrates']['mp4'])): - quality = json_data.get('mp4Labels')[i] - - if quality.lower() == 'auto': - continue - - formats.append({ - 'protocol': 'http', - 'url': json_data['bitrates']['mp4'][i], - 'height': int(quality[:-1]), - 'width': int(quality[:-1])/9*16, - 'ext': 'mp4', - 'format_id': quality, - 'format_note': 'HTTP', - 'preference': int(quality[:-1]) - }) - + 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), + }) self._sort_formats(formats) return { 'id': video_id, 'title': self._og_search_title(webpage).strip(), - 'thumbnail': self._og_search_property('image', webpage), - 'uploader': self._search_regex(self._VALID_URL, url, 'uploader'), - 'upload_id': json_url.group('upload_id'), - 'upload_date': json_url.group('upload_date'), - 'formats': formats + 'thumbnail': self._og_search_thumbnail(webpage), + 'upload_date': self._search_regex( + r'/vod/(\d{8})/', json_url, 'upload_date', default=None), + 'formats': formats, }