]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/porn91.py
[extractor/youtube] Workaround 403 for android formats
[yt-dlp.git] / yt_dlp / extractor / porn91.py
CommitLineData
c085cc2d 1import urllib.parse
d90b3854 2from .common import InfoExtractor
a80601f8 3from ..utils import (
c085cc2d 4 determine_ext,
a80601f8 5 int_or_none,
c085cc2d 6 parse_duration,
7 remove_end,
8 unified_strdate,
d05a1dbe 9 ExtractorError,
a80601f8 10)
d90b3854
P
11
12
13class Porn91IE(InfoExtractor):
14 IE_NAME = '91porn'
c085cc2d 15 _VALID_URL = r'(?:https?://)(?:www\.|)91porn\.com/view_video.php\?([^#]+&)?viewkey=(?P<id>\w+)'
d90b3854 16
c085cc2d 17 _TESTS = [{
9ff811c5 18 'url': 'http://91porn.com/view_video.php?viewkey=7e42283b4f5ab36da134',
c085cc2d 19 'md5': 'd869db281402e0ef4ddef3c38b866f86',
9ff811c5
YCH
20 'info_dict': {
21 'id': '7e42283b4f5ab36da134',
22 'title': '18岁大一漂亮学妹,水嫩性感,再爽一次!',
c085cc2d 23 'description': 'md5:1ff241f579b07ae936a54e810ad2e891',
a80601f8
YCH
24 'ext': 'mp4',
25 'duration': 431,
c085cc2d 26 'upload_date': '20150520',
27 'comment_count': int,
28 'view_count': int,
29 'age_limit': 18,
30 }
31 }, {
32 'url': 'https://91porn.com/view_video.php?viewkey=7ef0cf3d362c699ab91c',
33 'md5': 'f8fd50540468a6d795378cd778b40226',
34 'info_dict': {
35 'id': '7ef0cf3d362c699ab91c',
36 'title': '真实空乘,冲上云霄第二部',
37 'description': 'md5:618bf9652cafcc66cd277bd96789baea',
38 'ext': 'mp4',
39 'duration': 248,
40 'upload_date': '20221119',
41 'comment_count': int,
42 'view_count': int,
b61b7787 43 'age_limit': 18,
9ff811c5 44 }
c085cc2d 45 }]
d90b3854
P
46
47 def _real_extract(self, url):
1c222387 48 video_id = self._match_id(url)
d90b3854 49 self._set_cookie('91porn.com', 'language', 'cn_CN')
298c04b4
S
50
51 webpage = self._download_webpage(
52 'http://91porn.com/view_video.php?viewkey=%s' % video_id, video_id)
d05a1dbe 53
c085cc2d 54 if '视频不存在,可能已经被删除或者被举报为不良内容!' in webpage:
55 raise ExtractorError('91 Porn says: Video does not exist', expected=True)
d05a1dbe 56
c085cc2d 57 daily_limit = self._search_regex(
58 r'作为游客,你每天只可观看([\d]+)个视频', webpage, 'exceeded daily limit', default=None, fatal=False)
59 if daily_limit:
60 raise ExtractorError(f'91 Porn says: Daily limit {daily_limit} videos exceeded', expected=True)
d90b3854 61
2fe074a9 62 video_link_url = self._search_regex(
c085cc2d 63 r'document\.write\(\s*strencode2\s*\(\s*((?:"[^"]+")|(?:\'[^\']+\'))', webpage, 'video link')
64 video_link_url = self._search_regex(
65 r'src=["\']([^"\']+)["\']', urllib.parse.unquote(video_link_url), 'unquoted video link')
a80601f8 66
c085cc2d 67 formats, subtitles = self._get_formats_and_subtitle(video_link_url, video_id)
a80601f8 68
c085cc2d 69 return {
d90b3854 70 'id': video_id,
c085cc2d 71 'title': remove_end(self._html_extract_title(webpage).replace('\n', ''), 'Chinese homemade video').strip(),
72 'formats': formats,
73 'subtitles': subtitles,
74 'upload_date': unified_strdate(self._search_regex(
75 r'<span\s+class=["\']title-yakov["\']>(\d{4}-\d{2}-\d{2})</span>', webpage, 'upload_date', fatal=False)),
76 'description': self._html_search_regex(
77 r'<span\s+class=["\']more title["\']>\s*([^<]+)', webpage, 'description', fatal=False),
78 'duration': parse_duration(self._search_regex(
79 r'时长:\s*<span[^>]*>\s*(\d+(?::\d+){1,2})', webpage, 'duration', fatal=False)),
80 'comment_count': int_or_none(self._search_regex(
81 r'留言:\s*<span[^>]*>\s*(\d+)\s*</span>', webpage, 'comment count', fatal=False)),
82 'view_count': int_or_none(self._search_regex(
83 r'热度:\s*<span[^>]*>\s*(\d+)\s*</span>', webpage, 'view count', fatal=False)),
84 'age_limit': 18,
85 }
86
87 def _get_formats_and_subtitle(self, video_link_url, video_id):
88 ext = determine_ext(video_link_url)
89 if ext == 'm3u8':
90 formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_link_url, video_id, ext='mp4')
91 else:
92 formats = [{'url': video_link_url, 'ext': ext}]
93 subtitles = {}
3110bb93 94
c085cc2d 95 return formats, subtitles