Merge remote-tracking branch 'rzhxeo/embedly'
[youtube-dl] / youtube_dl / extractor / mtv.py
index 485c1fd7d02dd6920de2fae7d8dbca4d76bdf475..5447b6c0cab098b895eda0e9f2b3b266fb65a7b0 100644 (file)
@@ -6,9 +6,13 @@ from .common import InfoExtractor
 from ..utils import (
     compat_urllib_parse,
     ExtractorError,
+    find_xpath_attr,
     fix_xml_ampersands,
+    url_basename,
+    RegexNotFoundError,
 )
 
+
 def _media_xml_tag(tag):
     return '{http://search.yahoo.com/mrss/}%s' % tag
 
@@ -63,6 +67,7 @@ class MTVServicesInfoExtractor(InfoExtractor):
         mediagen_url = re.sub(r'&[^=]*?={.*?}(?=(&|$))', '', mediagen_url)
         if 'acceptMethods' not in mediagen_url:
             mediagen_url += '&acceptMethods=fms'
+
         mediagen_doc = self._download_xml(mediagen_url, video_id,
             'Downloading video urls')
 
@@ -72,8 +77,25 @@ class MTVServicesInfoExtractor(InfoExtractor):
         else:
             description = None
 
+        title_el = None
+        if title_el is None:
+            title_el = find_xpath_attr(
+                itemdoc, './/{http://search.yahoo.com/mrss/}category',
+                'scheme', 'urn:mtvn:video_title')
+        if title_el is None:
+            title_el = itemdoc.find('.//{http://search.yahoo.com/mrss/}title')
+        if title_el is None:
+            title_el = itemdoc.find('.//title')
+            if title_el.text is None:
+                title_el = None
+
+        title = title_el.text
+        if title is None:
+            raise ExtractorError('Could not find video title')
+        title = title.strip()
+
         return {
-            'title': itemdoc.find('title').text,
+            'title': title,
             'formats': self._extract_video_formats(mediagen_doc),
             'id': video_id,
             'thumbnail': self._get_thumbnail_url(uri, itemdoc),
@@ -89,6 +111,22 @@ class MTVServicesInfoExtractor(InfoExtractor):
             'Downloading info', transform_source=fix_xml_ampersands)
         return [self._get_video_info(item) for item in idoc.findall('.//item')]
 
+    def _real_extract(self, url):
+        title = url_basename(url)
+        webpage = self._download_webpage(url, title)
+        try:
+            # the url can be http://media.mtvnservices.com/fb/{mgid}.swf
+            # or http://media.mtvnservices.com/{mgid}
+            og_url = self._og_search_video_url(webpage)
+            mgid = url_basename(og_url)
+            if mgid.endswith('.swf'):
+                mgid = mgid[:-4]
+        except RegexNotFoundError:
+            mgid = self._search_regex(
+                [r'data-mgid="(.*?)"', r'swfobject.embedSWF\(".*?(mgid:.*?)"'],
+                webpage, u'mgid')
+        return self._get_videos_info(mgid)
+
 
 class MTVIE(MTVServicesInfoExtractor):
     _VALID_URL = r'''(?x)^https?://
@@ -141,3 +179,17 @@ class MTVIE(MTVServicesInfoExtractor):
     
             uri = self._html_search_regex(r'/uri/(.*?)\?', webpage, 'uri')
         return self._get_videos_info(uri)
+
+
+class MTVIggyIE(MTVServicesInfoExtractor):
+    IE_NAME = 'mtviggy.com'
+    _VALID_URL = r'https?://www\.mtviggy\.com/videos/.+'
+    _TEST = {
+        'url': 'http://www.mtviggy.com/videos/arcade-fire-behind-the-scenes-at-the-biggest-music-experiment-yet/',
+        'info_dict': {
+            'id': '984696',
+            'ext': 'mp4',
+            'title': 'Arcade Fire: Behind the Scenes at the Biggest Music Experiment Yet',
+        }
+    }
+    _FEED_URL = 'http://all.mtvworldverticals.com/feed-xml/'