]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[tv2hu] improve extraction
authorRemita Amine <remitamine@gmail.com>
Wed, 12 Apr 2017 18:31:18 +0000 (19:31 +0100)
committerRemita Amine <remitamine@gmail.com>
Wed, 12 Apr 2017 18:44:32 +0000 (19:44 +0100)
youtube_dl/extractor/extractors.py
youtube_dl/extractor/tv2hu.py

index 7484099f6e492e6a3bcf06862b3a0337c0ee7cd9..45591f2a7586b015fff0c40dd9f0697cdc8d9da2 100644 (file)
@@ -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
index cb1ce822a85c1cd50a16dbac780ca8685eed4ce8..ce01cc80dbac07181b9ccf1d6cd5f7781d4239a8 100644 (file)
@@ -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<uploader>[^/]+)/(?:teljes_adasok/)?(?P<id>[0-9]+)_(.+?)\.html'
-    _JSON_URL = r'(?P<json_url>https?://.+?\.tv2\.hu/vod/(?P<upload_date>\d+)/id_(?P<upload_id>\d+).+?&type=json)'
 
+class TV2HuIE(InfoExtractor):
+    IE_NAME = 'tv2.hu'
+    _VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:[^/]+/)+(?P<id>\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,
         }