Merge branch 'cinemassacre' of github.com:rzhxeo/youtube-dl into rzhxeo-cinemassacre
[youtube-dl] / youtube_dl / extractor / youporn.py
index 19360e2734778529cd8033c37c585a1ae4353d6d..b1f93dd1bb90d964916394d88d83aaaf153ba15b 100644 (file)
@@ -5,7 +5,6 @@ import sys
 
 from .common import InfoExtractor
 from ..utils import (
-    compat_str,
     compat_urllib_parse_urlparse,
     compat_urllib_request,
 
@@ -52,6 +51,7 @@ class YouPornIE(InfoExtractor):
         req = compat_urllib_request.Request(url)
         req.add_header('Cookie', 'age_verified=1')
         webpage = self._download_webpage(req, video_id)
+        age_limit = self._rta_search(webpage)
 
         # Get JSON parameters
         json_params = self._search_regex(r'var currentVideo = new Video\((.*)\);', webpage, u'JSON parameters')
@@ -79,14 +79,11 @@ class YouPornIE(InfoExtractor):
         LINK_RE = r'(?s)<a href="(?P<url>[^"]+)">'
         links = re.findall(LINK_RE, download_list_html)
         
-        # Get link of hd video
-        encrypted_video_url = self._html_search_regex(
-            r'var encrypted(?:Quality[0-9]+)?URL = \'(?P<encrypted_video_url>[a-zA-Z0-9+/]+={0,2})\';',
-            webpage, u'encrypted_video_url')
-        video_url = aes_decrypt_text(encrypted_video_url, video_title, 32)
-        print(video_url)
-        assert isinstance(video_url, compat_str)
-        if video_url.split('/')[6].split('_')[0] == u'720p': # only add if 720p to avoid duplicates
+        # Get link of hd video if available
+        mobj = re.search(r'var encryptedQuality720URL = \'(?P<encrypted_video_url>[a-zA-Z0-9+/]+={0,2})\';', webpage)
+        if mobj != None:
+            encrypted_video_url = mobj.group(u'encrypted_video_url')
+            video_url = aes_decrypt_text(encrypted_video_url, video_title, 32).decode('utf-8')
             links = [video_url] + links
         
         if not links:
@@ -119,7 +116,8 @@ class YouPornIE(InfoExtractor):
                 'ext': extension,
                 'format': format,
                 'thumbnail': thumbnail,
-                'description': video_description
+                'description': video_description,
+                'age_limit': age_limit,
             })
 
         if self._downloader.params.get('listformats', None):