[MTV] move German mtv site to new class
authorPaul Hartmann <phaaurlt@gmail.com>
Tue, 25 Aug 2015 22:06:44 +0000 (00:06 +0200)
committerSergey M․ <dstftw@gmail.com>
Fri, 28 Aug 2015 15:23:00 +0000 (21:23 +0600)
youtube_dl/extractor/__init__.py
youtube_dl/extractor/mtv.py

index d59882598c5dba1fa09f2996b19dca8cfcf4ae6b..66422b005cf5bd82d06a00497c70f63e212d8d02 100644 (file)
@@ -340,6 +340,7 @@ from .mtv import (
     MTVIE,
     MTVServicesEmbeddedIE,
     MTVIggyIE,
+    MTVDEIE,
 )
 from .muenchentv import MuenchenTVIE
 from .musicplayon import MusicPlayOnIE
index b48fac5e3e434569642284d0b6388cab34696b01..15df62649ff3d1366ff7fefd4de396f2c263d648 100644 (file)
@@ -288,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')])