Skip to content

Commit

Permalink
[pornhub] Improve locked videos detection (closes #22449, closes #22780)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey M․ committed Dec 31, 2019
1 parent f413472 commit 0164cd5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions youtube_dl/extractor/pornhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
determine_ext,
ExtractorError,
int_or_none,
NO_DEFAULT,
orderedSet,
remove_quotes,
str_to_int,
Expand Down Expand Up @@ -227,9 +228,9 @@ def dl_webpage(platform):
else:
thumbnail, duration = [None] * 2

def extract_js_vars(webpage, pattern, fatal=True):
def extract_js_vars(webpage, pattern, default=NO_DEFAULT):
assignments = self._search_regex(
pattern, webpage, 'encoded url', fatal=fatal)
pattern, webpage, 'encoded url', default=default)
if not assignments:
return {}

Expand Down Expand Up @@ -270,11 +271,15 @@ def add_video_url(video_url):
FORMAT_PREFIXES = ('media', 'quality')
js_vars = extract_js_vars(
webpage, r'(var\s+(?:%s)_.+)' % '|'.join(FORMAT_PREFIXES),
fatal=False)
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(format_url)
if not video_urls and re.search(
r'<[^>]+\bid=["\']lockedPlayer', webpage):
raise ExtractorError(
'Video %s is locked' % video_id, expected=True)

if not video_urls:
js_vars = extract_js_vars(
Expand Down

0 comments on commit 0164cd5

Please sign in to comment.