[pornhub] Fix review issues (closes #27393)
authorSergey M․ <dstftw@gmail.com>
Sat, 26 Dec 2020 14:16:55 +0000 (21:16 +0700)
committerSergey M․ <dstftw@gmail.com>
Sat, 26 Dec 2020 14:17:17 +0000 (21:17 +0700)
youtube_dl/extractor/pornhub.py

index 3b649896436dc36d3011cc5386cb509a518fba8e..21ec48895e960ef3b81ac234b7954d22660dedef 100644 (file)
@@ -288,15 +288,13 @@ class PornHubIE(PornHubBaseIE):
             video_urls.append((v_url, None))
             video_urls_set.add(v_url)
 
-        def parse_quality_items(js_str):
-            if (url_or_none(js_str)):
-                return js_str
-            media_definitions = self._parse_json(js_str, video_id, fatal=False)
-            if isinstance(media_definitions, list):
-                for definition in media_definitions:
-                    if not isinstance(definition, dict):
-                        continue
-                    add_video_url(definition.get('url'))
+        def parse_quality_items(quality_items):
+            q_items = self._parse_json(quality_items, video_id, fatal=False)
+            if not isinstance(q_items, list):
+                return
+            for item in q_items:
+                if isinstance(item, dict):
+                    add_video_url(item.get('url'))
 
         if not video_urls:
             FORMAT_PREFIXES = ('media', 'quality', 'qualityItems')
@@ -305,8 +303,10 @@ class PornHubIE(PornHubBaseIE):
                 default=None)
             if js_vars:
                 for key, format_url in js_vars.items():
-                    if any(key.startswith(p) for p in FORMAT_PREFIXES):
-                        add_video_url(parse_quality_items(format_url))
+                    if key.startswith(FORMAT_PREFIXES[-1]):
+                        parse_quality_items(format_url)
+                    elif any(key.startswith(p) for p in FORMAT_PREFIXES[:2]):
+                        add_video_url(format_url)
             if not video_urls and re.search(
                     r'<[^>]+\bid=["\']lockedPlayer', webpage):
                 raise ExtractorError(