0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-10 00:25:06 +00:00

[youporn] Fix extraction of video URLs

The API seems to be gone, but video_player_setup object will contain playervars, with URLs to fetch the format definitions.
This commit is contained in:
The-MAGI 2023-12-22 02:31:32 +02:00 committed by GitHub
parent 632b8ee54e
commit 8a6fe2e420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,19 +88,27 @@ class YouPornIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id, display_id = self._match_valid_url(url).group('id', 'display_id') video_id, display_id = self._match_valid_url(url).group('id', 'display_id')
definitions = self._download_json( webpage = self._download_webpage(
f'https://www.youporn.com/api/video/media_definitions/{video_id}/', display_id or video_id) f"https://www.youporn.com/watch/{video_id}", display_id or video_id,
headers={'Cookie': 'age_verified=1'},
)
def get_format_data(data, f): playervars = self._search_regex(r'^\s*playervars:\s*(\{.+?\})$', webpage, 'playervars', flags=re.MULTILINE)
return traverse_obj(data, lambda _, v: v['format'] == f and url_or_none(v['videoUrl'])) playervars = self._parse_json(playervars, display_id or video_id)
defs_by_format = {x['format'] : x for x in playervars.get('mediaDefinitions', {})}
def get_format_data(f):
if not f in defs_by_format:
return []
return self._download_json(defs_by_format[f]['videoUrl'], display_id or video_id, f"{f}-formats")
formats = [] formats = []
# Try to extract only the actual master m3u8 first, avoiding the duplicate single resolution "master" m3u8s # Try to extract only the actual master m3u8 first, avoiding the duplicate single resolution "master" m3u8s
for hls_url in traverse_obj(get_format_data(definitions, 'hls'), ( for hls_url in traverse_obj(get_format_data('hls'), (
lambda _, v: not isinstance(v['defaultQuality'], bool), 'videoUrl'), (..., 'videoUrl')): lambda _, v: not isinstance(v['defaultQuality'], bool), 'videoUrl'), (..., 'videoUrl')):
formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4', fatal=False, m3u8_id='hls')) formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4', fatal=False, m3u8_id='hls'))
for definition in get_format_data(definitions, 'mp4'): for definition in get_format_data('mp4'):
f = traverse_obj(definition, { f = traverse_obj(definition, {
'url': 'videoUrl', 'url': 'videoUrl',
'filesize': ('videoSize', {int_or_none}) 'filesize': ('videoSize', {int_or_none})
@ -123,10 +131,6 @@ def get_format_data(data, f):
f['height'] = height f['height'] = height
formats.append(f) formats.append(f)
webpage = self._download_webpage(
'http://www.youporn.com/watch/%s' % video_id, display_id,
headers={'Cookie': 'age_verified=1'})
title = self._html_search_regex( title = self._html_search_regex(
r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>', r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>',
webpage, 'title', default=None) or self._og_search_title( webpage, 'title', default=None) or self._og_search_title(