From cc1657b753936ea96d2aa07e36938875e594a2ce Mon Sep 17 00:00:00 2001 From: dirkf Date: Mon, 16 Oct 2023 04:16:01 +0100 Subject: [PATCH] [XVideos] Add XVideosSearchKeyIE to implement a search key: xvsearchnnn:needle --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/xvideos.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index c3ef4933e..d208e6986 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -1626,6 +1626,7 @@ from .xvideos import ( XVideosPlaylistIE, XVideosRelatedIE, XVideosSearchIE, + XVideosSearchKeyIE, ) from .xxxymovies import XXXYMoviesIE from .yahoo import ( diff --git a/youtube_dl/extractor/xvideos.py b/youtube_dl/extractor/xvideos.py index 973208d41..ddda0bc61 100644 --- a/youtube_dl/extractor/xvideos.py +++ b/youtube_dl/extractor/xvideos.py @@ -1008,3 +1008,38 @@ class XVideosSearchIE(XVideosPlaylistBaseIE): if sub: title = '%s (%s)' % (title, sub) return title + + +class XVideosSearchKeyIE(SearchInfoExtractor, XVideosSearchIE): + _SEARCH_KEY = 'xvsearch' + _MAX_RESULTS = float('inf') + _TESTS = [{ + 'note': 'full search', + 'url': 'xvsearchall:lithuania', + 'info_dict': { + 'id': 'lithuania', + 'title': 'lithuania (all)', + }, + 'playlist_mincount': 75, + }, { + 'note': 'Subset of paginated result', + 'url': 'xvsearch50:lithuania', + 'info_dict': { + 'id': 'lithuania', + 'title': 'lithuania (first 50)', + }, + 'playlist_count': 50, + }] + + def _get_n_results(self, query, n): + """Get a specified number of results for a query""" + + result = XVideosSearchIE._real_extract( + self, 'https://www.xvideos.com/?k=' + query.replace(' ', '+')) + + if not isinf(n): + result['entries'] = itertools.islice(result['entries'], n) + if result.get('title') is not None: + result['title'] = result['title'].replace('(all)', '(first %d)' % n) + + return result