[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / porn91.py
blob7d16a16319bd95eaf3c14de358b2d93f0d0d9e8d
1 import urllib.parse
2 from .common import InfoExtractor
3 from ..utils import (
4 determine_ext,
5 int_or_none,
6 parse_duration,
7 remove_end,
8 unified_strdate,
9 ExtractorError,
13 class Porn91IE(InfoExtractor):
14 IE_NAME = '91porn'
15 _VALID_URL = r'(?:https?://)(?:www\.|)91porn\.com/view_video.php\?([^#]+&)?viewkey=(?P<id>\w+)'
17 _TESTS = [{
18 'url': 'http://91porn.com/view_video.php?viewkey=7e42283b4f5ab36da134',
19 'md5': 'd869db281402e0ef4ddef3c38b866f86',
20 'info_dict': {
21 'id': '7e42283b4f5ab36da134',
22 'title': '18岁大一漂亮学妹,水嫩性感,再爽一次!',
23 'description': 'md5:1ff241f579b07ae936a54e810ad2e891',
24 'ext': 'mp4',
25 'duration': 431,
26 'upload_date': '20150520',
27 'comment_count': int,
28 'view_count': int,
29 'age_limit': 18,
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,
43 'age_limit': 18,
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
49 self._set_cookie('91porn.com', 'language', 'cn_CN')
51 webpage = self._download_webpage(
52 'http://91porn.com/view_video.php?viewkey=%s' % video_id, video_id)
54 if '视频不存在,可能已经被删除或者被举报为不良内容!' in webpage:
55 raise ExtractorError('91 Porn says: Video does not exist', expected=True)
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)
62 video_link_url = self._search_regex(
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')
67 formats, subtitles = self._get_formats_and_subtitle(video_link_url, video_id)
69 return {
70 'id': video_id,
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,
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 = {}
95 return formats, subtitles