mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-28 14:34:41 +00:00
[xhamster] Make more robust
This commit is contained in:
parent
defce60385
commit
be7a8379b4
@ -46,12 +46,12 @@ class XHamsterIE(InfoExtractor):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
def extract_video_url(webpage):
|
def extract_video_url(webpage, name):
|
||||||
mp4 = re.search(r'file:\s+\'([^\']+)\'', webpage)
|
return self._search_regex(
|
||||||
if mp4 is None:
|
[r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
|
||||||
raise ExtractorError('Unable to extract media URL')
|
r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
|
||||||
else:
|
r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
|
||||||
return mp4.group(1)
|
webpage, name, group='mp4')
|
||||||
|
|
||||||
def is_hd(webpage):
|
def is_hd(webpage):
|
||||||
return '<div class=\'icon iconHD\'' in webpage
|
return '<div class=\'icon iconHD\'' in webpage
|
||||||
@ -97,7 +97,9 @@ class XHamsterIE(InfoExtractor):
|
|||||||
|
|
||||||
hd = is_hd(webpage)
|
hd = is_hd(webpage)
|
||||||
|
|
||||||
video_url = extract_video_url(webpage)
|
format_id = 'hd' if hd else 'sd'
|
||||||
|
|
||||||
|
video_url = extract_video_url(webpage, format_id)
|
||||||
formats = [{
|
formats = [{
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'format_id': 'hd' if hd else 'sd',
|
'format_id': 'hd' if hd else 'sd',
|
||||||
@ -108,7 +110,7 @@ class XHamsterIE(InfoExtractor):
|
|||||||
mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
|
mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
|
||||||
webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
|
webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
|
||||||
if is_hd(webpage):
|
if is_hd(webpage):
|
||||||
video_url = extract_video_url(webpage)
|
video_url = extract_video_url(webpage, 'hd')
|
||||||
formats.append({
|
formats.append({
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
'format_id': 'hd',
|
'format_id': 'hd',
|
||||||
|
Loading…
Reference in New Issue
Block a user