[extractor/youporn] Extract m3u8 formats

Closes #6977
This commit is contained in:
pukkandan 2023-05-05 09:41:56 +05:30
parent 45998b3e37
commit ddae33754a
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
1 changed files with 18 additions and 17 deletions

View File

@ -6,6 +6,7 @@ from ..utils import (
int_or_none, int_or_none,
merge_dicts, merge_dicts,
str_to_int, str_to_int,
traverse_obj,
unified_strdate, unified_strdate,
url_or_none, url_or_none,
) )
@ -86,32 +87,31 @@ class YouPornIE(InfoExtractor):
}] }]
def _real_extract(self, url): def _real_extract(self, url):
mobj = self._match_valid_url(url) video_id, display_id = self._match_valid_url(url).group('id', 'display_id')
video_id = mobj.group('id')
display_id = mobj.group('display_id') or video_id
definitions = self._download_json( definitions = self._download_json(
'https://www.youporn.com/api/video/media_definitions/%s/' % video_id, f'https://www.youporn.com/api/video/media_definitions/{video_id}/', display_id or video_id)
display_id)
def get_format_data(data, f):
return traverse_obj(data, lambda _, v: v['format'] == f and url_or_none(v['videoUrl']))
formats = [] formats = []
for definition in definitions: # Try to extract only the actual master m3u8 first, avoiding the duplicate single resolution "master" m3u8s
if not isinstance(definition, dict): for hls_url in traverse_obj(get_format_data(definitions, 'hls'), (
continue lambda _, v: not isinstance(v['defaultQuality'], bool), 'videoUrl'), (..., 'videoUrl')):
video_url = url_or_none(definition.get('videoUrl')) formats.extend(self._extract_m3u8_formats(hls_url, video_id, 'mp4', fatal=False, m3u8_id='hls'))
if not video_url:
continue for definition in get_format_data(definitions, 'mp4'):
f = { f = traverse_obj(definition, {
'url': video_url, 'url': 'videoUrl',
'filesize': int_or_none(definition.get('videoSize')), 'filesize': ('videoSize', {int_or_none})
} })
height = int_or_none(definition.get('quality')) height = int_or_none(definition.get('quality'))
# Video URL's path looks like this: # Video URL's path looks like this:
# /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
# /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
# /videos/201703/11/109285532/1080P_4000K_109285532.mp4 # /videos/201703/11/109285532/1080P_4000K_109285532.mp4
# We will benefit from it by extracting some metadata # We will benefit from it by extracting some metadata
mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url) mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', definition['videoUrl'])
if mobj: if mobj:
if not height: if not height:
height = int(mobj.group('height')) height = int(mobj.group('height'))
@ -179,6 +179,7 @@ class YouPornIE(InfoExtractor):
'tags') 'tags')
data = self._search_json_ld(webpage, video_id, expected_type='VideoObject', fatal=False) data = self._search_json_ld(webpage, video_id, expected_type='VideoObject', fatal=False)
data.pop('url', None)
return merge_dicts(data, { return merge_dicts(data, {
'id': video_id, 'id': video_id,
'display_id': display_id, 'display_id': display_id,