Merge pull request #6467 from vijayanandnandam/master
[youtube-dl] / youtube_dl / extractor / xhamster.py
index 519bfc1914524b50eca470c792a0e46651c4115f..9d025530fb9f1fcb14a4cc139c4c67c88c157668 100644 (file)
@@ -13,7 +13,6 @@ from ..utils import (
 
 
 class XHamsterIE(InfoExtractor):
-    """Information Extractor for xHamster"""
     _VALID_URL = r'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
     _TESTS = [
         {
@@ -42,33 +41,13 @@ class XHamsterIE(InfoExtractor):
         },
         {
             'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
-            'info_dict': {
-                'id': '2272726',
-                'ext': 'mp4',
-                'title': 'Amber slayed by the Knight',
-                'upload_date': '20131009',
-                'uploader_id': 'amberblank',
-                'duration': 149,
-                'age_limit': 18,
-            }
+            'only_matching': True,
         },
-        {
-            "url": "https://xhamster.com/movies/1444747/hotkinkyjo_amp_asian_girl_elbow_deep_anal_fisting_and_footing.html",
-            'info_dict': {
-                "id": "1444747",
-                'ext': 'mp4',
-                "title": "HOTKINKYJO & ASIAN GIRL ELBOW DEEP ANAL FISTING AND FOOTING",
-                "upload_date": "20120922",
-                "uploader_id": "alex1981",
-                "duration": 80,
-                "age_limit": 18,
-            }
-        }
     ]
 
     def _real_extract(self, url):
         def extract_video_url(webpage):
-            mp4 = re.search(r'<video\s+.*?file="([^"]+)".*?>', webpage)
+            mp4 = re.search(r'file:\s+\'([^\']+)\'', webpage)
             if mp4 is None:
                 raise ExtractorError('Unable to extract media URL')
             else:
@@ -153,3 +132,36 @@ class XHamsterIE(InfoExtractor):
             'age_limit': age_limit,
             'formats': formats,
         }
+
+
+class XHamsterEmbedIE(InfoExtractor):
+    _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
+    _TEST = {
+        'url': 'http://xhamster.com/xembed.php?video=3328539',
+        'info_dict': {
+            'id': '3328539',
+            'ext': 'mp4',
+            'title': 'Pen Masturbation',
+            'upload_date': '20140728',
+            'uploader_id': 'anonymous',
+            'duration': 5,
+            'age_limit': 18,
+        }
+    }
+
+    @staticmethod
+    def _extract_urls(webpage):
+        return [url for _, url in re.findall(
+            r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
+            webpage)]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
+
+        webpage = self._download_webpage(url, video_id)
+
+        video_url = self._search_regex(
+            r'href="(https?://xhamster\.com/movies/%s/[^"]+\.html[^"]*)"' % video_id,
+            webpage, 'xhamster url')
+
+        return self.url_result(video_url, 'XHamster')