mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-15 14:58:00 +09:00
[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
This commit is contained in:
parent
e1a57763d7
commit
4143140adb
@ -47,7 +47,7 @@ class TestAgeRestriction(unittest.TestCase):
|
|||||||
def test_youporn(self):
|
def test_youporn(self):
|
||||||
self._assert_restricted(
|
self._assert_restricted(
|
||||||
'https://www.youporn.com/watch/16715086/sex-ed-in-detention-18-asmr/',
|
'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__':
|
if __name__ == '__main__':
|
||||||
|
@ -5,10 +5,13 @@ import re
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
clean_html,
|
||||||
extract_attributes,
|
extract_attributes,
|
||||||
|
ExtractorError,
|
||||||
|
get_element_by_id,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
str_to_int,
|
|
||||||
merge_dicts,
|
merge_dicts,
|
||||||
|
parse_count,
|
||||||
T,
|
T,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
unified_strdate,
|
unified_strdate,
|
||||||
@ -38,7 +41,7 @@ class YouPornIE(InfoExtractor):
|
|||||||
'tags': list,
|
'tags': list,
|
||||||
'age_limit': 18,
|
'age_limit': 18,
|
||||||
},
|
},
|
||||||
'skip': 'This video has been disabled',
|
'skip': 'This video has been deactivated',
|
||||||
}, {
|
}, {
|
||||||
# Unknown uploader
|
# 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',
|
'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())
|
return list(yield_urls())
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
|
# Actual video ID is hidden in the page
|
||||||
display_id = self._match_valid_url(url).group('id', 'display_id')
|
display_id = self._match_valid_url(url).group('id', 'display_id')
|
||||||
url = 'http://www.youporn.com/watch/%s' % (display_id[0],)
|
url = 'http://www.youporn.com/watch/%s' % (display_id[0],)
|
||||||
display_id = display_id[1] or display_id[0]
|
display_id = display_id[1] or display_id[0]
|
||||||
webpage = self._download_webpage(
|
webpage = self._download_webpage(
|
||||||
url, display_id, headers={'Cookie': 'age_verified=1'})
|
url, display_id, headers={'Cookie': 'age_verified=1'})
|
||||||
video_id = display_id[0]
|
|
||||||
|
watchable = self._search_regex(
|
||||||
|
r'''(<div\s[^>]*\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<id>\d+)\1''',
|
||||||
|
webpage, 'video id', group='id')
|
||||||
|
|
||||||
playervars = self._search_json(
|
playervars = self._search_json(
|
||||||
r'\bplayervars\s*:', webpage, 'playervars', display_id)
|
r'\bplayervars\s*:', webpage, 'playervars', display_id)
|
||||||
@ -169,8 +189,10 @@ class YouPornIE(InfoExtractor):
|
|||||||
thumbnail = self._search_regex(
|
thumbnail = self._search_regex(
|
||||||
r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
|
r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1',
|
||||||
webpage, 'thumbnail', fatal=False, group='thumbnail')
|
webpage, 'thumbnail', fatal=False, group='thumbnail')
|
||||||
duration = int_or_none(self._html_search_meta(
|
duration = traverse_obj(playervars, ('duration', T(int_or_none)))
|
||||||
'video:duration', webpage, 'duration', fatal=False))
|
if duration is None:
|
||||||
|
duration = int_or_none(self._html_search_meta(
|
||||||
|
'video:duration', webpage, 'duration', fatal=False))
|
||||||
|
|
||||||
uploader = self._html_search_regex(
|
uploader = self._html_search_regex(
|
||||||
r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
|
r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>',
|
||||||
@ -186,11 +208,11 @@ class YouPornIE(InfoExtractor):
|
|||||||
|
|
||||||
view_count = None
|
view_count = None
|
||||||
views = self._search_regex(
|
views = self._search_regex(
|
||||||
r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage,
|
r'(<div\s[^>]*\bdata-value\s*=[^>]+>)\s*<label>Views:</label>',
|
||||||
'views', default=None)
|
webpage, 'views', default=None)
|
||||||
if views:
|
if views:
|
||||||
view_count = str_to_int(extract_attributes(views).get('data-value'))
|
view_count = parse_count(extract_attributes(views).get('data-value'))
|
||||||
comment_count = str_to_int(self._search_regex(
|
comment_count = parse_count(self._search_regex(
|
||||||
r'>All [Cc]omments? \(([\d,.]+)\)',
|
r'>All [Cc]omments? \(([\d,.]+)\)',
|
||||||
webpage, 'comment count', default=None))
|
webpage, 'comment count', default=None))
|
||||||
|
|
||||||
@ -211,7 +233,7 @@ class YouPornIE(InfoExtractor):
|
|||||||
|
|
||||||
result = merge_dicts(data, {
|
result = merge_dicts(data, {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id if display_id != video_id else None,
|
'display_id': display_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
@ -225,4 +247,8 @@ class YouPornIE(InfoExtractor):
|
|||||||
'age_limit': age_limit,
|
'age_limit': age_limit,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
})
|
})
|
||||||
|
# Remove promotionalm non-description
|
||||||
|
if result.get('description', '').startswith(
|
||||||
|
'Watch %s online' % (result['title'],)):
|
||||||
|
del result['description']
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user