1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-08-13 16:08:29 +00:00
This commit is contained in:
JChris246 2025-08-12 12:42:14 +01:00 committed by GitHub
commit c1b3ed3f4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -451,7 +451,7 @@ def _real_extract(self, url):
class XHamsterUserIE(InfoExtractor):
_VALID_URL = rf'https?://(?:[^/?#]+\.)?{XHamsterIE._DOMAINS}/(?:(?P<user>users)|creators)/(?P<id>[^/?#&]+)'
_VALID_URL = rf'https?://(?:[^/?#]+\.)?{XHamsterIE._DOMAINS}/(?P<collection>users|creators|channels)/(?P<id>[^/?#&]+)(?P<favorites>/favorites/videos)?'
_TESTS = [{
# Paginated user profile
'url': 'https://xhamster.com/users/netvideogirls/videos',
@ -472,6 +472,18 @@ class XHamsterUserIE(InfoExtractor):
'id': 'squirt-orgasm-69',
},
'playlist_mincount': 46,
}, {
'url': 'https://xhamster.com/channels/patreon/',
'info_dict': {
'id': 'patreon',
},
'playlist_mincount': 500,
}, {
'url': 'https://xhamster.com/users/cubafidel/favorites/videos',
'info_dict': {
'id': 'cubafidel',
},
'playlist_mincount': 220,
}, {
'url': 'https://xhday.com/users/mobhunter',
'only_matching': True,
@ -480,9 +492,15 @@ class XHamsterUserIE(InfoExtractor):
'only_matching': True,
}]
def _entries(self, user_id, is_user):
prefix, suffix = ('users', 'videos') if is_user else ('creators', 'exclusive')
next_page_url = f'https://xhamster.com/{prefix}/{user_id}/{suffix}/1'
def _entries(self, user_id, collection_type):
collection_prefixes = {
'users': ('users', 'videos/'),
'creators': ('creators', 'exclusive/'),
'channels': ('channels', ''),
'favorites': ('users', 'favorites/videos/'),
}
prefix, suffix = collection_prefixes[collection_type]
next_page_url = f'https://xhamster.com/{prefix}/{user_id}/{suffix}1'
for pagenum in itertools.count(1):
page = self._download_webpage(
next_page_url, user_id, f'Downloading page {pagenum}')
@ -496,7 +514,7 @@ def _entries(self, user_id, is_user):
video_id = XHamsterIE._match_id(video_url)
yield self.url_result(
video_url, ie=XHamsterIE.ie_key(), video_id=video_id)
mobj = re.search(r'<a[^>]+data-page=["\']next[^>]+>', page)
mobj = re.search(r'<a[^>]+(?:data-page=["\']next|rel=["\']next)[^>]+>', page)
if not mobj:
break
next_page = extract_attributes(mobj.group(0))
@ -505,5 +523,6 @@ def _entries(self, user_id, is_user):
break
def _real_extract(self, url):
user, user_id = self._match_valid_url(url).group('user', 'id')
return self.playlist_result(self._entries(user_id, bool(user)), user_id)
collection_type, user_id, favorites = self._match_valid_url(url).group('collection', 'id', 'favorites')
collection_type = 'favorites' if bool(favorites) else collection_type
return self.playlist_result(self._entries(user_id, collection_type), user_id)