+ })
+
+ # Remove SEO spam "description"
+ description = result.get('description')
+ if description and description.startswith(f'Watch {result.get("title")} online'):
+ del result['description']
+
+ return result
+
+
+class YouPornListBase(InfoExtractor):
+ def _get_next_url(self, url, pl_id, html):
+ return urljoin(url, self._search_regex(
+ r'''<a [^>]*?\bhref\s*=\s*("|')(?P<url>(?:(?!\1)[^>])+)\1''',
+ get_element_by_id('next', html) or '', 'next page',
+ group='url', default=None))
+
+ @classmethod
+ def _get_title_from_slug(cls, title_slug):
+ return re.sub(r'[_-]', ' ', title_slug)
+
+ def _entries(self, url, pl_id, html=None, page_num=None):
+ start = page_num or 1
+ for page in itertools.count(start):
+ if not html:
+ html = self._download_webpage(
+ url, pl_id, note=f'Downloading page {page}', fatal=page == start)
+ if not html:
+ return
+ for element in get_elements_html_by_class('video-title', html):
+ if video_url := traverse_obj(element, ({extract_attributes}, 'href', {lambda x: urljoin(url, x)})):
+ yield self.url_result(video_url)
+
+ if page_num is not None:
+ return
+ next_url = self._get_next_url(url, pl_id, html)
+ if not next_url or next_url == url:
+ return
+ url = next_url
+ html = None
+
+ def _real_extract(self, url, html=None):
+ m_dict = self._match_valid_url(url).groupdict()
+ pl_id, page_type, sort = (m_dict.get(k) for k in ('id', 'type', 'sort'))
+ qs = {k: v[-1] for k, v in parse_qs(url).items() if v}
+
+ base_id = pl_id or 'YouPorn'
+ title = self._get_title_from_slug(base_id)
+ if page_type:
+ title = f'{page_type.capitalize()} {title}'
+ base_id = [base_id.lower()]
+ if sort is None:
+ title += ' videos'
+ else:
+ title = f'{title} videos by {re.sub(r"[_-]", " ", sort)}'
+ base_id.append(sort)
+ if qs:
+ filters = list(map('='.join, sorted(qs.items())))
+ title += f' ({",".join(filters)})'
+ base_id.extend(filters)
+ pl_id = '/'.join(base_id)
+
+ return self.playlist_result(
+ self._entries(url, pl_id, html=html, page_num=int_or_none(qs.get('page'))),
+ playlist_id=pl_id, playlist_title=title)
+
+
+class YouPornCategoryIE(YouPornListBase):
+ IE_DESC = 'YouPorn category, with sorting, filtering and pagination'
+ _VALID_URL = r'''(?x)
+ https?://(?:www\.)?youporn\.com/
+ (?P<type>category)/(?P<id>[^/?#&]+)
+ (?:/(?P<sort>popular|views|rating|time|duration))?/?(?:[#?]|$)
+ '''
+ _TESTS = [{
+ 'note': 'Full list with pagination',
+ 'url': 'https://www.youporn.com/category/popular-with-women/popular/',
+ 'info_dict': {
+ 'id': 'popular-with-women/popular',
+ 'title': 'Category popular with women videos by popular',
+ },
+ 'playlist_mincount': 39,
+ }, {
+ 'note': 'Filtered paginated list with single page result',
+ 'url': 'https://www.youporn.com/category/popular-with-women/duration/?min_minutes=10',
+ 'info_dict': {
+ 'id': 'popular-with-women/duration/min_minutes=10',
+ 'title': 'Category popular with women videos by duration (min_minutes=10)',
+ },
+ 'playlist_mincount': 2,
+ # 'playlist_maxcount': 30,
+ }, {
+ 'note': 'Single page of full list',
+ 'url': 'https://www.youporn.com/category/popular-with-women/popular?page=1',
+ 'info_dict': {
+ 'id': 'popular-with-women/popular/page=1',
+ 'title': 'Category popular with women videos by popular (page=1)',
+ },
+ 'playlist_count': 36,
+ }]
+
+
+class YouPornChannelIE(YouPornListBase):
+ IE_DESC = 'YouPorn channel, with sorting and pagination'
+ _VALID_URL = r'''(?x)
+ https?://(?:www\.)?youporn\.com/
+ (?P<type>channel)/(?P<id>[^/?#&]+)
+ (?:/(?P<sort>rating|views|duration))?/?(?:[#?]|$)
+ '''
+ _TESTS = [{
+ 'note': 'Full list with pagination',
+ 'url': 'https://www.youporn.com/channel/x-feeds/',
+ 'info_dict': {
+ 'id': 'x-feeds',
+ 'title': 'Channel X-Feeds videos',
+ },
+ 'playlist_mincount': 37,
+ }, {
+ 'note': 'Single page of full list (no filters here)',
+ 'url': 'https://www.youporn.com/channel/x-feeds/duration?page=1',
+ 'info_dict': {
+ 'id': 'x-feeds/duration/page=1',
+ 'title': 'Channel X-Feeds videos by duration (page=1)',
+ },
+ 'playlist_count': 24,
+ }]
+
+ @staticmethod
+ def _get_title_from_slug(title_slug):
+ return re.sub(r'_', ' ', title_slug).title()
+
+
+class YouPornCollectionIE(YouPornListBase):
+ IE_DESC = 'YouPorn collection (user playlist), with sorting and pagination'
+ _VALID_URL = r'''(?x)
+ https?://(?:www\.)?youporn\.com/
+ (?P<type>collection)s/videos/(?P<id>\d+)
+ (?:/(?P<sort>rating|views|time|duration))?/?(?:[#?]|$)
+ '''
+ _TESTS = [{
+ 'note': 'Full list with pagination',
+ 'url': 'https://www.youporn.com/collections/videos/33044251/',
+ 'info_dict': {
+ 'id': '33044251',
+ 'title': 'Collection Sexy Lips videos',
+ 'uploader': 'ph-littlewillyb',
+ },
+ 'playlist_mincount': 50,
+ }, {
+ 'note': 'Single page of full list (no filters here)',
+ 'url': 'https://www.youporn.com/collections/videos/33044251/time?page=1',
+ 'info_dict': {
+ 'id': '33044251/time/page=1',
+ 'title': 'Collection Sexy Lips videos by time (page=1)',
+ 'uploader': 'ph-littlewillyb',
+ },
+ 'playlist_count': 20,
+ }]
+
+ def _real_extract(self, url):
+ pl_id = self._match_id(url)
+ html = self._download_webpage(url, pl_id)
+ playlist = super()._real_extract(url, html=html)
+ infos = re.sub(r'\s+', ' ', clean_html(get_element_by_class(
+ 'collection-infos', html)) or '')
+ title, uploader = self._search_regex(
+ r'^\s*Collection: (?P<title>.+?) \d+ VIDEOS \d+ VIEWS \d+ days LAST UPDATED From: (?P<uploader>[\w_-]+)',
+ infos, 'title/uploader', group=('title', 'uploader'), default=(None, None))
+ if title:
+ playlist.update({
+ 'title': playlist['title'].replace(playlist['id'].split('/')[0], title),
+ 'uploader': uploader,
+ })
+
+ return playlist
+
+
+class YouPornTagIE(YouPornListBase):
+ IE_DESC = 'YouPorn tag (porntags), with sorting, filtering and pagination'
+ _VALID_URL = r'''(?x)
+ https?://(?:www\.)?youporn\.com/
+ porn(?P<type>tag)s/(?P<id>[^/?#&]+)
+ (?:/(?P<sort>views|rating|time|duration))?/?(?:[#?]|$)
+ '''
+ _TESTS = [{
+ 'note': 'Full list with pagination',
+ 'url': 'https://www.youporn.com/porntags/austrian',
+ 'info_dict': {
+ 'id': 'austrian',
+ 'title': 'Tag austrian videos',
+ },
+ 'playlist_mincount': 33,
+ 'expected_warnings': ['YouPorn tag pages are not correctly cached'],
+ }, {
+ 'note': 'Filtered paginated list with single page result',
+ 'url': 'https://www.youporn.com/porntags/austrian/duration/?min_minutes=10',
+ 'info_dict': {
+ 'id': 'austrian/duration/min_minutes=10',
+ 'title': 'Tag austrian videos by duration (min_minutes=10)',
+ },
+ 'playlist_mincount': 10,
+ # number of videos per page is (row x col) 2x3 + 6x4 + 2, or + 3,
+ # or more, varying with number of ads; let's set max as 9x4
+ # NB col 1 may not be shown in non-JS page with site CSS and zoom 100%
+ # 'playlist_maxcount': 32,
+ 'expected_warnings': ['YouPorn tag pages are not correctly cached'],
+ }, {
+ 'note': 'Single page of full list',
+ 'url': 'https://www.youporn.com/porntags/austrian/?page=1',
+ 'info_dict': {
+ 'id': 'austrian/page=1',
+ 'title': 'Tag austrian videos (page=1)',
+ },
+ 'playlist_mincount': 32,
+ # 'playlist_maxcount': 34,
+ 'expected_warnings': ['YouPorn tag pages are not correctly cached'],
+ }]
+
+ def _real_extract(self, url):
+ self.report_warning(
+ 'YouPorn tag pages are not correctly cached and '
+ 'often return incorrect results', only_once=True)
+ return super()._real_extract(url)
+
+
+class YouPornStarIE(YouPornListBase):
+ IE_DESC = 'YouPorn Pornstar, with description, sorting and pagination'
+ _VALID_URL = r'''(?x)
+ https?://(?:www\.)?youporn\.com/
+ (?P<type>pornstar)/(?P<id>[^/?#&]+)
+ (?:/(?P<sort>rating|views|duration))?/?(?:[#?]|$)
+ '''
+ _TESTS = [{
+ 'note': 'Full list with pagination',
+ 'url': 'https://www.youporn.com/pornstar/daynia/',
+ 'info_dict': {
+ 'id': 'daynia',
+ 'title': 'Pornstar Daynia videos',
+ 'description': r're:Daynia Rank \d+ Videos \d+ Views [\d,.]+ .+ Subscribers \d+',
+ },
+ 'playlist_mincount': 40,
+ }, {
+ 'note': 'Single page of full list (no filters here)',
+ 'url': 'https://www.youporn.com/pornstar/daynia/?page=1',
+ 'info_dict': {
+ 'id': 'daynia/page=1',
+ 'title': 'Pornstar Daynia videos (page=1)',
+ 'description': 're:.{180,}',
+ },
+ 'playlist_count': 26,
+ }]
+
+ @staticmethod
+ def _get_title_from_slug(title_slug):
+ return re.sub(r'_', ' ', title_slug).title()
+
+ def _real_extract(self, url):
+ pl_id = self._match_id(url)
+ html = self._download_webpage(url, pl_id)
+ playlist = super()._real_extract(url, html=html)
+ INFO_ELEMENT_RE = r'''(?x)
+ <div [^>]*\bclass\s*=\s*('|")(?:[\w$-]+\s+|\s)*?pornstar-info-wrapper(?:\s+[\w$-]+|\s)*\1[^>]*>
+ (?P<info>[\s\S]+?)(?:</div>\s*){6,}
+ '''
+
+ if infos := self._search_regex(INFO_ELEMENT_RE, html, 'infos', group='info', default=''):
+ infos = re.sub(
+ r'(?:\s*nl=nl)+\s*', ' ',
+ re.sub(r'(?u)\s+', ' ', clean_html(re.sub('\n', 'nl=nl', infos)))).replace('ribe Subsc', '')
+
+ return {
+ **playlist,
+ 'description': infos.strip() or None,