[vgtv] extract 5 digit length video ids using both xstream and vgtv
authorremitamine <remitamine@gmail.com>
Thu, 10 Dec 2015 21:18:42 +0000 (22:18 +0100)
committerremitamine <remitamine@gmail.com>
Thu, 10 Dec 2015 21:18:42 +0000 (22:18 +0100)
youtube_dl/extractor/vgtv.py
youtube_dl/extractor/xstream.py

index 1fba37578ac832b74c2ec4a67ab9448fa451eea7..347410a78c2c3f49da2812070e9ac7d3b5943ed2 100644 (file)
@@ -4,13 +4,14 @@ from __future__ import unicode_literals
 import re
 
 from .common import InfoExtractor
+from .xstream import XstreamIE
 from ..utils import (
     ExtractorError,
     float_or_none,
 )
 
 
-class VGTVIE(InfoExtractor):
+class VGTVIE(XstreamIE):
     IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
 
     _HOST_TO_APPNAME = {
@@ -137,6 +138,15 @@ class VGTVIE(InfoExtractor):
             raise ExtractorError(
                 'Video %s is no longer available' % video_id, expected=True)
 
+        info = {
+            'formats': [],
+        }
+        if len(video_id) == 5:
+            if appname == 'bttv':
+                info = self._extract_video_info('btno', video_id)
+            elif appname == 'aptv':
+                info = self._extract_video_info('ap', video_id)
+
         streams = data['streamUrls']
         stream_type = data.get('streamType')
 
@@ -177,9 +187,11 @@ class VGTVIE(InfoExtractor):
                 })
             formats.append(format_info)
 
-        self._sort_formats(formats)
+        info['formats'].extend(formats)
 
-        return {
+        self._sort_formats(info['formats'])
+
+        info.update({
             'id': video_id,
             'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
             'description': data['description'],
@@ -187,9 +199,9 @@ class VGTVIE(InfoExtractor):
             'timestamp': data['published'],
             'duration': float_or_none(data['duration'], 1000),
             'view_count': data['displays'],
-            'formats': formats,
             'is_live': True if stream_type == 'live' else False,
-        }
+        })
+        return info
 
 
 class BTArticleIE(InfoExtractor):
index 71584c291f9134ac2444a1ac48bba9ae514c2981..436f8978be89c9dcd606c73dcefdf6a4f8636d8e 100644 (file)
@@ -42,11 +42,7 @@ class XstreamIE(InfoExtractor):
         'only_matching': True,
     }]
 
-    def _real_extract(self, url):
-        mobj = re.match(self._VALID_URL, url)
-        partner_id = mobj.group('partner_id')
-        video_id = mobj.group('id')
-
+    def _extract_video_info(self, partner_id, video_id):
         data = self._download_xml(
             'http://frontend.xstream.dk/%s/feed/video/?platform=web&id=%s'
             % (partner_id, video_id),
@@ -97,6 +93,7 @@ class XstreamIE(InfoExtractor):
             formats.append({
                 'url': link.get('href'),
                 'format_id': link.get('rel'),
+                'preference': 2,
             })
 
         thumbnails = [{
@@ -113,3 +110,10 @@ class XstreamIE(InfoExtractor):
             'formats': formats,
             'thumbnails': thumbnails,
         }
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        partner_id = mobj.group('partner_id')
+        video_id = mobj.group('id')
+
+        return self._extract_video_info(partner_id, video_id)