mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-18 03:08:31 +00:00
[ie/pornhub] fix code
This commit is contained in:
parent
439b931411
commit
1565a11e9a
@ -20,6 +20,7 @@
|
|||||||
remove_quotes,
|
remove_quotes,
|
||||||
remove_start,
|
remove_start,
|
||||||
str_to_int,
|
str_to_int,
|
||||||
|
traverse_obj,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
@ -267,27 +268,6 @@ class PornHubIE(PornHubBaseIE):
|
|||||||
def _extract_count(self, pattern, webpage, name):
|
def _extract_count(self, pattern, webpage, name):
|
||||||
return str_to_int(self._search_regex(pattern, webpage, f'{name} count', default=None))
|
return str_to_int(self._search_regex(pattern, webpage, f'{name} count', default=None))
|
||||||
|
|
||||||
def _extract_chapters_from_action_tags(self, action_tags, duration):
|
|
||||||
if not action_tags:
|
|
||||||
return None
|
|
||||||
|
|
||||||
chapter_list = []
|
|
||||||
for entry in action_tags.split(','):
|
|
||||||
if ':' not in entry:
|
|
||||||
continue
|
|
||||||
title, start_str = entry.split(':', 1)
|
|
||||||
start_time = int_or_none(start_str)
|
|
||||||
if start_time is not None:
|
|
||||||
chapter_list.append({'title': title.strip(), 'start_time': start_time})
|
|
||||||
|
|
||||||
for i, chapter in enumerate(chapter_list):
|
|
||||||
if i + 1 < len(chapter_list):
|
|
||||||
chapter['end_time'] = chapter_list[i + 1]['start_time']
|
|
||||||
elif duration is not None:
|
|
||||||
chapter['end_time'] = duration
|
|
||||||
|
|
||||||
return chapter_list or None
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = self._match_valid_url(url)
|
mobj = self._match_valid_url(url)
|
||||||
host = mobj.group('host') or 'pornhub.com'
|
host = mobj.group('host') or 'pornhub.com'
|
||||||
@ -346,7 +326,12 @@ def dl_webpage(platform):
|
|||||||
})
|
})
|
||||||
thumbnail = flashvars.get('image_url')
|
thumbnail = flashvars.get('image_url')
|
||||||
duration = int_or_none(flashvars.get('video_duration'))
|
duration = int_or_none(flashvars.get('video_duration'))
|
||||||
chapters = self._extract_chapters_from_action_tags(flashvars.get('actionTags'), duration)
|
chapters = traverse_obj(flashvars, (
|
||||||
|
'actionTags', {lambda x: x.split(',')}, ..., {lambda x: x.split(':', 1)},
|
||||||
|
all, lambda _, v: int_or_none(v[1]) is not None, {
|
||||||
|
'title': (0, {str.strip}),
|
||||||
|
'start_time': (1, {int_or_none}),
|
||||||
|
})) or None
|
||||||
media_definitions = flashvars.get('mediaDefinitions')
|
media_definitions = flashvars.get('mediaDefinitions')
|
||||||
if isinstance(media_definitions, list):
|
if isinstance(media_definitions, list):
|
||||||
for definition in media_definitions:
|
for definition in media_definitions:
|
||||||
|
Loading…
Reference in New Issue
Block a user