[youtube] Fix extraction.
[youtube-dl] / youtube_dl / extractor / presstv.py
index 724d8b1c4334870c75aa001029bfa0af6d226bd5..b5c279203b9486e765f6e79f2d9ce8b67acf73b1 100644 (file)
@@ -1,77 +1,71 @@
 # coding: utf-8
 from __future__ import unicode_literals
+
 import re
 
 from .common import InfoExtractor
-from ..utils import str_to_int
+from ..utils import remove_start
 
 
 class PressTVIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?presstv\.ir/Video/(?P<y>[0-9]+)/(?P<m>[0-9]+)/(?P<d>[0-9]+)/(?P<id>[0-9]+)/'
+    _VALID_URL = r'https?://(?:www\.)?presstv\.ir/[^/]+/(?P<y>\d+)/(?P<m>\d+)/(?P<d>\d+)/(?P<id>\d+)/(?P<display_id>[^/]+)?'
 
     _TEST = {
-        'url': 'http://www.presstv.ir/Video/2015/10/04/431915/Max-Igan-Press-TV-Face-to-Face',
-        'md5': 'e95736ac75088b5f1e5bbb68f248f90d',
+        'url': 'http://www.presstv.ir/Detail/2016/04/09/459911/Australian-sewerage-treatment-facility-/',
+        'md5': '5d7e3195a447cb13e9267e931d8dd5a5',
         'info_dict': {
-            'id': '431915',
+            'id': '459911',
+            'display_id': 'Australian-sewerage-treatment-facility-',
             'ext': 'mp4',
-            'title': 'Press TV’s full interview with Max Igan',
-            'upload_date': '20151004',
-            'thumbnail': 'http://217.218.67.233/photo/20151004/d5c333ad-98f9-4bd3-bc3e-a1ad6a192803.jpg',
-            'description': ('Watch Press TV’s full interview with Max Igan, a radio talk show host and political '
-                            'commentator.\nThe interview, conducted on Press TV’s Face '
-                            'to Face program, was aired on October 3, 2015.')
+            'title': 'Organic mattresses used to clean waste water',
+            'upload_date': '20160409',
+            'thumbnail': r're:^https?://.*\.jpg',
+            'description': 'md5:20002e654bbafb6908395a5c0cfcd125'
         }
     }
 
     def _real_extract(self, url):
-        video_id = self._match_id(url)
-        webpage = self._download_webpage(url, video_id)
+        mobj = re.match(self._VALID_URL, url)
+        video_id = mobj.group('id')
+        display_id = mobj.group('display_id') or video_id
+
+        webpage = self._download_webpage(url, display_id)
 
         # extract video URL from webpage
-        video_url = self._html_search_regex(r'<input type="hidden" id="inpPlayback" value="([^"]+)" />', webpage,
-                                            'Video URL')
+        video_url = self._hidden_inputs(webpage)['inpPlayback']
 
         # build list of available formats
         # specified in http://www.presstv.ir/Scripts/playback.js
         base_url = 'http://192.99.219.222:82/presstv'
-        formats = [
-            {
-                'url': base_url + video_url,
-                'format': '1080p mp4',
-                'format_id': '1080p'
-            }, {
-                'url': base_url + video_url.replace(".mp4", "_low800.mp4"),
-                'format': '720p mp4',
-                'format_id': '720p'
-            }, {
-                'url': base_url + video_url.replace(".mp4", "_low400.mp4"),
-                'format': '360p mp4',
-                'format_id': '360p'
-            }, {
-                'url': base_url + video_url.replace(".mp4", "_low200.mp4"),
-                'format': '180p mp4',
-                'format_id': '180p'
-            }
+        _formats = [
+            (180, '_low200.mp4'),
+            (360, '_low400.mp4'),
+            (720, '_low800.mp4'),
+            (1080, '.mp4')
         ]
-        formats.reverse()
 
-        # extract video metadata
-        title = self._html_search_meta('title', webpage, 'Title', True)
-        title = title.partition(' - ')[2]
+        formats = [{
+            'url': base_url + video_url[:-4] + extension,
+            'format_id': '%dp' % height,
+            'height': height,
+        } for height, extension in _formats]
 
-        description = self._html_search_regex(r'<div class="media-text nano-content">(.*?)</div>', webpage,
-                                              'Description', flags=re.DOTALL)
+        # extract video metadata
+        title = remove_start(
+            self._html_search_meta('title', webpage, fatal=True), 'PressTV-')
 
-        thumbnail = self._html_search_meta('og:image', webpage, 'Thumbnail', True)
+        thumbnail = self._og_search_thumbnail(webpage)
+        description = self._og_search_description(webpage)
 
-        year = str_to_int(self._search_regex(PressTVIE._VALID_URL, url, 'Upload year', group='y'))
-        month = str_to_int(self._search_regex(PressTVIE._VALID_URL, url, 'Upload month', group='m'))
-        day = str_to_int(self._search_regex(PressTVIE._VALID_URL, url, 'Upload day', group='d'))
-        upload_date = '%04d%02d%02d' % (year, month, day)
+        upload_date = '%04d%02d%02d' % (
+            int(mobj.group('y')),
+            int(mobj.group('m')),
+            int(mobj.group('d')),
+        )
 
         return {
             'id': video_id,
+            'display_id': display_id,
             'title': title,
             'formats': formats,
             'thumbnail': thumbnail,