Merge remote-tracking branch 'Dineshs91/f4m-2.0'
[youtube-dl] / youtube_dl / extractor / trutube.py
index 37d3af0ca7a06216218e2ceda7ec4587a2e7b709..e7b79243a8fb9f091087f5c452c8192c49c81af2 100644 (file)
@@ -1,43 +1,40 @@
-import re
+from __future__ import unicode_literals
 
 from .common import InfoExtractor
-from ..utils import (
-    ExtractorError,
-)
+from ..utils import xpath_text
 
 
 class TruTubeIE(InfoExtractor):
-    _VALID_URL = r'(?:https?://)?(?:www\.)?(?P<url>trutube\.tv/video/(?P<videoid>.*/.*))'
-    _TEST = {
-        'url': ('http://www.trutube.tv/video/20814/Ernst-Zundel-met-les-Jui'
-                'fs-en-guarde-VOSTFR'),
-        'md5': '9973aa3c2870626799d2ac4e36cfc3dc',
+    _VALID_URL = r'https?://(?:www\.)?trutube\.tv/(?:video/|nuevo/player/embed\.php\?v=)(?P<id>[0-9]+)'
+    _TESTS = [{
+        'url': 'http://trutube.tv/video/14880/Ramses-II-Proven-To-Be-A-Red-Headed-Caucasoid-',
+        'md5': 'c5b6e301b0a2040b074746cbeaa26ca1',
         'info_dict': {
-            u"title": u"TruTube.TV - Spitting in the face of die-versity",
-            u"ext": u"mp4"
+            'id': '14880',
+            'ext': 'flv',
+            'title': 'Ramses II - Proven To Be A Red Headed Caucasoid',
+            'thumbnail': 're:^http:.*\.jpg$',
         }
-    }
+    }, {
+        'url': 'https://trutube.tv/nuevo/player/embed.php?v=14880',
+        'only_matching': True,
+    }]
 
     def _real_extract(self, url):
-        mobj = re.match(self._VALID_URL, url)
+        video_id = self._match_id(url)
 
-        video_id = mobj.group('videoid')
+        config = self._download_xml(
+            'https://trutube.tv/nuevo/player/config.php?v=%s' % video_id,
+            video_id, transform_source=lambda s: s.strip())
 
-        # Get webpage content
-        webpage = self._download_webpage(url, video_id)
-
-        # Get the video title
-        video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
-                                              webpage, 'title').strip()
-
-        video_url = self._search_regex(r'(http://.*\.(?:mp4|flv))',
-                                       webpage, u'video URL')
-
-        ext = video_url[-3:]
+        # filehd is always 404
+        video_url = xpath_text(config, './file', 'video URL', fatal=True)
+        title = xpath_text(config, './title', 'title').strip()
+        thumbnail = xpath_text(config, './image', ' thumbnail')
 
         return {
             'id': video_id,
             'url': video_url,
-            'title': video_title,
-            'ext': ext
-            }
+            'title': title,
+            'thumbnail': thumbnail,
+        }