[MTV] move German mtv site to new class
[youtube-dl] / youtube_dl / extractor / mtv.py
index c11de1cb61b28d03ab2430ff1db3a82d317dc718..15df62649ff3d1366ff7fefd4de396f2c263d648 100644 (file)
@@ -25,6 +25,7 @@ def _media_xml_tag(tag):
 
 class MTVServicesInfoExtractor(InfoExtractor):
     _MOBILE_TEMPLATE = None
+    _LANG = None
 
     @staticmethod
     def _id_from_uri(uri):
@@ -118,6 +119,14 @@ class MTVServicesInfoExtractor(InfoExtractor):
         mediagen_doc = self._download_xml(mediagen_url, video_id,
                                           'Downloading video urls')
 
+        item = mediagen_doc.find('./video/item')
+        if item is not None and item.get('type') == 'text':
+            message = '%s returned error: ' % self.IE_NAME
+            if item.get('code') is not None:
+                message += '%s - ' % item.get('code')
+            message += item.text
+            raise ExtractorError(message, expected=True)
+
         description_node = itemdoc.find('description')
         if description_node is not None:
             description = description_node.text.strip()
@@ -161,8 +170,12 @@ class MTVServicesInfoExtractor(InfoExtractor):
         video_id = self._id_from_uri(uri)
         feed_url = self._get_feed_url(uri)
         data = compat_urllib_parse.urlencode({'uri': uri})
+        info_url = feed_url + '?'
+        if self._LANG:
+            info_url += 'lang=%s&' % self._LANG
+        info_url += data
         idoc = self._download_xml(
-            feed_url + '?' + data, video_id,
+            info_url, video_id,
             'Downloading info', transform_source=fix_xml_ampersands)
         return self.playlist_result(
             [self._get_video_info(item) for item in idoc.findall('.//item')])
@@ -275,3 +288,40 @@ class MTVIggyIE(MTVServicesInfoExtractor):
         }
     }
     _FEED_URL = 'http://all.mtvworldverticals.com/feed-xml/'
+
+class MTVDEIE(MTVServicesInfoExtractor):
+    IE_NAME = 'mtv.de'
+    _VALID_URL = r'''(?x)^https?://(?:www\.)?mtv\.de(?P<video_path>/artists/.*)'''
+    _TESTS = [
+        {
+            'url': 'http://www.mtv.de/artists/10571-cro/videos/61131-traum',
+            'info_dict': {
+                'id': 'a50bc5f0b3aa4b3190aa',
+                'ext': 'mp4',
+                'title': 'cro-traum',
+                'description': 'Cro - Traum',
+            },
+        },
+    ]
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        return self._get_videos_info(url, mobj.group('video_path'))
+
+    def _get_videos_info(self, url, video_path):
+        webpage = self._download_webpage(url, video_path)
+        playlist_js = self._search_regex(r'<script>\s*window.pagePlaylist =(.*?\]);\s*window.trackingParams =', webpage, 'playlist', flags=re.DOTALL)
+        playlist = self._parse_json(playlist_js, video_path)
+        info = None
+        for item in playlist:
+            if item['video_path'] == video_path:
+                info = item
+                break
+        if info == None:
+            raise ExtractorError('video not in playlist')
+        mrss_url = info['mrss']
+        idoc = self._download_xml(
+            mrss_url, video_path,
+            'Downloading info', transform_source=fix_xml_ampersands)
+        return self.playlist_result(
+            [self._get_video_info(item) for item in idoc.findall('.//item')])