Merge remote-tracking branch 'phaer/add-oe1-support'
authorPhilipp Hagemeister <phihag@phihag.de>
Fri, 28 Mar 2014 22:21:58 +0000 (23:21 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Fri, 28 Mar 2014 22:21:58 +0000 (23:21 +0100)
README.md
youtube_dl/__init__.py
youtube_dl/extractor/__init__.py
youtube_dl/extractor/comedycentral.py
youtube_dl/extractor/ntv.py [new file with mode: 0644]
youtube_dl/utils.py
youtube_dl/version.py

index 0352a5bcb8f17a2f9d943ef0c9ac53de47e0696b..ac1c3adad92e2ffae853501d33894a50731c9ffb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -181,7 +181,9 @@ which means you can modify it, redistribute it or use it however you like.
     --get-duration                   simulate, quiet but print video length
     --get-filename                   simulate, quiet but print output filename
     --get-format                     simulate, quiet but print output format
-    -j, --dump-json                  simulate, quiet but print JSON information
+    -j, --dump-json                  simulate, quiet but print JSON information.
+                                     See --output for a description of available
+                                     keys.
     --newline                        output progress bar as new lines
     --no-progress                    do not print progress bar
     --console-title                  display progress in console titlebar
index 6af4b8aee96c8d937940dddf103a63e220b24004..f3b2be0c1e0fbdd71ca146516356a588daca05c5 100644 (file)
@@ -395,7 +395,7 @@ def parseOpts(overrideArguments=None):
             help='simulate, quiet but print output format', default=False)
     verbosity.add_option('-j', '--dump-json',
             action='store_true', dest='dumpjson',
-            help='simulate, quiet but print JSON information', default=False)
+            help='simulate, quiet but print JSON information. See --output for a description of available keys.', default=False)
     verbosity.add_option('--newline',
             action='store_true', dest='progress_with_newline', help='output progress bar as new lines', default=False)
     verbosity.add_option('--no-progress',
index 0e4b2b6e8ce80ea7a0d2aa38fc3565cd89b19b3c..8e81fa619334305a5105420dcf42511a22211d1f 100644 (file)
@@ -177,6 +177,7 @@ from .normalboots import NormalbootsIE
 from .novamov import NovaMovIE
 from .nowness import NownessIE
 from .nowvideo import NowVideoIE
+from .ntv import NTVIE
 from .oe1 import OE1IE
 from .ooyala import OoyalaIE
 from .orf import ORFIE
index ea1675cf6f82a50d33d9b3996254ccf9ab737613..60c0a4f5dbc3c98468a184195e03dd39da299e95 100644 (file)
@@ -8,7 +8,7 @@ from ..utils import (
     compat_str,
     compat_urllib_parse,
     ExtractorError,
-    int_or_none,
+    float_or_none,
     unified_strdate,
 )
 
@@ -159,7 +159,7 @@ class ComedyCentralShowsIE(InfoExtractor):
             thumbnail = itemEl.find('.//{http://search.yahoo.com/mrss/}thumbnail').attrib.get('url')
 
             content = itemEl.find('.//{http://search.yahoo.com/mrss/}content')
-            duration = int_or_none(content.attrib.get('duration'))
+            duration = float_or_none(content.attrib.get('duration'))
             mediagen_url = content.attrib['url']
             guid = itemEl.find('.//guid').text.rpartition(':')[-1]
 
diff --git a/youtube_dl/extractor/ntv.py b/youtube_dl/extractor/ntv.py
new file mode 100644 (file)
index 0000000..e998d15
--- /dev/null
@@ -0,0 +1,158 @@
+# encoding: utf-8
+from __future__ import unicode_literals
+
+import re
+
+from .common import InfoExtractor
+from ..utils import (
+    RegexNotFoundError,
+    unescapeHTML
+)
+
+
+class NTVIE(InfoExtractor):
+    _VALID_URL = r'http://(?:www\.)?ntv\.ru/(?P<id>.+)'
+
+    _TESTS = [
+        {
+            'url': 'http://www.ntv.ru/novosti/863142/',
+            'info_dict': {
+                'id': '746000',
+                'ext': 'flv',
+                'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
+                'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
+                'duration': 136,
+            },
+            'params': {
+                    # rtmp download
+                    'skip_download': True,
+                },
+        },
+        {
+            'url': 'http://www.ntv.ru/video/novosti/750370/',
+            'info_dict': {
+                'id': '750370',
+                'ext': 'flv',
+                'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
+                'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
+                'duration': 172,
+            },
+            'params': {
+                    # rtmp download
+                    'skip_download': True,
+                },
+        },
+        {
+            'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416',
+            'info_dict': {
+                'id': '747480',
+                'ext': 'flv',
+                'title': '«Сегодня». 21 марта 2014 года. 16:00 ',
+                'description': '«Сегодня». 21 марта 2014 года. 16:00 ',
+                'duration': 1496,
+            },
+            'params': {
+                    # rtmp download
+                    'skip_download': True,
+                },
+        },
+        {
+            'url': 'http://www.ntv.ru/kino/Koma_film',
+            'info_dict': {
+                'id': '750783',
+                'ext': 'flv',
+                'title': 'Остросюжетный фильм «Кома» \97 4 апреля вечером на НТВ',
+                'description': 'Остросюжетный фильм «Кома» \97 4 апреля вечером на НТВ',
+                'duration': 28,
+            },
+            'params': {
+                    # rtmp download
+                    'skip_download': True,
+                },
+        },
+        {
+            'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
+            'info_dict': {
+                'id': '751482',
+                'ext': 'flv',
+                'title': '«Дело врачей»: «Деревце жизни»',
+                'description': '«Дело врачей»: «Деревце жизни»',
+                'duration': 2590,
+            },
+            'params': {
+                    # rtmp download
+                    'skip_download': True,
+                },
+        },
+    ]
+
+    _VIDEO_ID_REGEXES = [
+        r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)',
+        r'<video embed=[^>]+><id>(\d+)</id>',
+        r'<video restriction[^>]+><key>(\d+)</key>'
+    ]
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        video_id = mobj.group('id')
+
+        page = self._download_webpage(url, video_id, 'Downloading page')
+
+        def extract(patterns, name, page, fatal=False):
+            for pattern in patterns:
+                mobj = re.search(pattern, page)
+                if mobj:
+                    return mobj.group(1)
+            if fatal:
+                raise RegexNotFoundError(u'Unable to extract %s' % name)
+            return None
+
+        video_id = extract(self._VIDEO_ID_REGEXES, 'video id', page, fatal=True)
+
+        player = self._download_xml('http://www.ntv.ru/vi%s/' % video_id, video_id, 'Downloading video XML')
+        title = unescapeHTML(player.find('./data/title').text)
+        description = unescapeHTML(player.find('./data/description').text)
+
+        video = player.find('./data/video')
+        video_id = video.find('./id').text
+        thumbnail = video.find('./splash').text
+        duration = int(video.find('./totaltime').text)
+        view_count = int(video.find('./views').text)
+        puid22 = video.find('./puid22').text
+
+        apps = {
+            '4': 'video1',
+            '7': 'video2',
+        }
+
+        app = apps[puid22] if puid22 in apps else apps['4']
+
+        formats = []
+        for format_id in ['', 'hi', 'webm']:
+            file = video.find('./%sfile' % format_id)
+            if file is None:
+                continue
+            size = video.find('./%ssize' % format_id)
+            formats.append({
+                'url': 'rtmp://media.ntv.ru/%s' % app,
+                'app': app,
+                'play_path': file.text,
+                'rtmp_conn': 'B:1',
+                'player_url': 'http://www.ntv.ru/swf/vps1.swf?update=20131128',
+                'page_url': 'http://www.ntv.ru',
+                'flash_ver': 'LNX 11,2,202,341',
+                'rtmp_live': True,
+                'ext': 'flv',
+                'filesize': int(size.text),
+            })
+        self._sort_formats(formats)
+
+        return {
+            'id': video_id,
+            'title': title,
+            'description': description,
+            'thumbnail': thumbnail,
+            'duration': duration,
+            'view_count': view_count,
+            'formats': formats,
+        }
\ No newline at end of file
index 29c9b1a4cb6fdef970617fd6b556454cb7eff07d..b5326c0cba027e1f33ecb636a9de9c3c98919782 100644 (file)
@@ -1181,6 +1181,10 @@ def int_or_none(v, scale=1):
     return v if v is None else (int(v) // scale)
 
 
+def float_or_none(v, scale=1):
+    return v if v is None else (float(v) / scale)
+
+
 def parse_duration(s):
     if s is None:
         return None
index 5a415d489fca84ee1afce8ab0120e949cae176fb..154aeca05ae3092864f72ee1ecd6c8d1c0662ed2 100644 (file)
@@ -1,2 +1,2 @@
 
-__version__ = '2014.03.27.1'
+__version__ = '2014.03.28'