[xhamster:embed] Extract vars (Closes #8912)
authorSergey M․ <dstftw@gmail.com>
Mon, 21 Mar 2016 16:07:34 +0000 (22:07 +0600)
committerSergey M․ <dstftw@gmail.com>
Mon, 21 Mar 2016 16:07:34 +0000 (22:07 +0600)
youtube_dl/extractor/xhamster.py

index fd43e8854c994e5b15c661ce49636853c41d2ecd..b3547174dd92beffafaf8f220b50b94a25f2fa2b 100644 (file)
@@ -4,6 +4,7 @@ import re
 
 from .common import InfoExtractor
 from ..utils import (
+    dict_get,
     float_or_none,
     int_or_none,
     unified_strdate,
@@ -170,6 +171,12 @@ class XHamsterEmbedIE(InfoExtractor):
 
         video_url = self._search_regex(
             r'href="(https?://xhamster\.com/movies/%s/[^"]+\.html[^"]*)"' % video_id,
-            webpage, 'xhamster url')
+            webpage, 'xhamster url', default=None)
+
+        if not video_url:
+            vars = self._parse_json(
+                self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
+                video_id)
+            video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
 
         return self.url_result(video_url, 'XHamster')