From 4143140adbc92182430f719f5b35f93702cd00e2 Mon Sep 17 00:00:00 2001 From: dirkf Date: Fri, 1 Mar 2024 15:07:30 +0000 Subject: [PATCH] [YouPorn] Improve extraction * use video ID from page * detect unwatchable videos * improve duration extraction * fix count extraction and support large values * detect and remnove SEO spam boilerplate description --- test/test_age_restriction.py | 2 +- youtube_dl/extractor/youporn.py | 46 ++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/test/test_age_restriction.py b/test/test_age_restriction.py index db98494ab..a241610ce 100644 --- a/test/test_age_restriction.py +++ b/test/test_age_restriction.py @@ -47,7 +47,7 @@ class TestAgeRestriction(unittest.TestCase): def test_youporn(self): self._assert_restricted( 'https://www.youporn.com/watch/16715086/sex-ed-in-detention-18-asmr/', - '16715086.mp4', 2, old_age=25) + '48260111.mp4', 2, old_age=25) if __name__ == '__main__': diff --git a/youtube_dl/extractor/youporn.py b/youtube_dl/extractor/youporn.py index 4c455b5b8..f37c06429 100644 --- a/youtube_dl/extractor/youporn.py +++ b/youtube_dl/extractor/youporn.py @@ -5,10 +5,13 @@ import re from .common import InfoExtractor from ..utils import ( + clean_html, extract_attributes, + ExtractorError, + get_element_by_id, int_or_none, - str_to_int, merge_dicts, + parse_count, T, traverse_obj, unified_strdate, @@ -38,7 +41,7 @@ class YouPornIE(InfoExtractor): 'tags': list, 'age_limit': 18, }, - 'skip': 'This video has been disabled', + 'skip': 'This video has been deactivated', }, { # Unknown uploader 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4', @@ -100,12 +103,29 @@ class YouPornIE(InfoExtractor): return list(yield_urls()) def _real_extract(self, url): + # Actual video ID is hidden in the page display_id = self._match_valid_url(url).group('id', 'display_id') url = 'http://www.youporn.com/watch/%s' % (display_id[0],) display_id = display_id[1] or display_id[0] webpage = self._download_webpage( url, display_id, headers={'Cookie': 'age_verified=1'}) - video_id = display_id[0] + + watchable = self._search_regex( + r'''(]*\bid\s*=\s*('|")?watch-container(?(2)\2|(?!-)\b)[^>]*>)''', + webpage, 'video id', default=None) + if not watchable: + msg = re.split(r'\s{4}', clean_html(get_element_by_id( + 'mainContent', webpage)) or '')[0] + raise ExtractorError( + ('%s says: %s' % (self.IE_NAME, msg)) + if msg else 'Video unavailable: no reason found', + expected=True) + video_id = extract_attributes(watchable).get('data-video-id') + if not video_id: + # last chance saloon + video_id = self._search_regex( + r'''\bcurrentVideoId\s*:\s*('|")(?P\d+)\1''', + webpage, 'video id', group='id') playervars = self._search_json( r'\bplayervars\s*:', webpage, 'playervars', display_id) @@ -169,8 +189,10 @@ class YouPornIE(InfoExtractor): thumbnail = self._search_regex( r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P.+?)\1', webpage, 'thumbnail', fatal=False, group='thumbnail') - duration = int_or_none(self._html_search_meta( - 'video:duration', webpage, 'duration', fatal=False)) + duration = traverse_obj(playervars, ('duration', T(int_or_none))) + if duration is None: + duration = int_or_none(self._html_search_meta( + 'video:duration', webpage, 'duration', fatal=False)) uploader = self._html_search_regex( r'(?s)]+class=["\']submitByLink["\'][^>]*>(.+?)', @@ -186,11 +208,11 @@ class YouPornIE(InfoExtractor): view_count = None views = self._search_regex( - r'(]+\bclass=["\']js_videoInfoViews["\']>)', webpage, - 'views', default=None) + r'(]*\bdata-value\s*=[^>]+>)\s*', + webpage, 'views', default=None) if views: - view_count = str_to_int(extract_attributes(views).get('data-value')) - comment_count = str_to_int(self._search_regex( + view_count = parse_count(extract_attributes(views).get('data-value')) + comment_count = parse_count(self._search_regex( r'>All [Cc]omments? \(([\d,.]+)\)', webpage, 'comment count', default=None)) @@ -211,7 +233,7 @@ class YouPornIE(InfoExtractor): result = merge_dicts(data, { 'id': video_id, - 'display_id': display_id if display_id != video_id else None, + 'display_id': display_id, 'title': title, 'description': description, 'thumbnail': thumbnail, @@ -225,4 +247,8 @@ class YouPornIE(InfoExtractor): 'age_limit': age_limit, 'formats': formats, }) + # Remove promotionalm non-description + if result.get('description', '').startswith( + 'Watch %s online' % (result['title'],)): + del result['description'] return result