]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/rule34video.py
[ie/Rule34Video] Fix `_VALID_URL` (#9044)
[yt-dlp.git] / yt_dlp / extractor / rule34video.py
CommitLineData
faca6745 1import re
2
faca6745 3from .common import InfoExtractor
fee2d8d9 4from ..utils import (
5 clean_html,
6 extract_attributes,
7 get_element_by_attribute,
8 get_element_by_class,
9 get_element_html_by_class,
10 get_elements_by_class,
11 int_or_none,
12 join_nonempty,
13 parse_count,
14 parse_duration,
15 unescapeHTML,
16)
17from ..utils.traversal import traverse_obj
faca6745 18
19
20class Rule34VideoIE(InfoExtractor):
c0ecceee 21 _VALID_URL = r'https?://(?:www\.)?rule34video\.com/videos?/(?P<id>\d+)'
faca6745 22 _TESTS = [
23 {
c0ecceee 24 'url': 'https://rule34video.com/video/3065157/shot-it-mmd-hmv/',
faca6745 25 'md5': 'ffccac2c23799dabbd192621ae4d04f3',
26 'info_dict': {
27 'id': '3065157',
28 'ext': 'mp4',
29 'title': 'Shot It-(mmd hmv)',
30 'thumbnail': 'https://rule34video.com/contents/videos_screenshots/3065000/3065157/preview.jpg',
31 'duration': 347.0,
58493923 32 'age_limit': 18,
fee2d8d9 33 'view_count': int,
34 'like_count': int,
35 'comment_count': int,
36 'timestamp': 1639872000,
37 'description': 'https://discord.gg/aBqPrHSHvv',
38 'upload_date': '20211219',
39 'uploader': 'Sweet HMV',
40 'uploader_url': 'https://rule34video.com/members/22119/',
41 'categories': ['3D', 'MMD', 'iwara'],
42 'tags': 'mincount:10'
faca6745 43 }
44 },
45 {
46 'url': 'https://rule34video.com/videos/3065296/lara-in-trouble-ep-7-wildeerstudio/',
47 'md5': '6bb5169f9f6b38cd70882bf2e64f6b86',
48 'info_dict': {
49 'id': '3065296',
50 'ext': 'mp4',
51 'title': 'Lara in Trouble Ep. 7 [WildeerStudio]',
52 'thumbnail': 'https://rule34video.com/contents/videos_screenshots/3065000/3065296/preview.jpg',
53 'duration': 938.0,
58493923 54 'age_limit': 18,
fee2d8d9 55 'view_count': int,
56 'like_count': int,
57 'comment_count': int,
58 'timestamp': 1640131200,
59 'description': '',
60 'creator': 'WildeerStudio',
61 'upload_date': '20211222',
62 'uploader': 'CerZule',
63 'uploader_url': 'https://rule34video.com/members/36281/',
64 'categories': ['3D', 'Tomb Raider'],
65 'tags': 'mincount:40'
faca6745 66 }
67 },
68 ]
69
70 def _real_extract(self, url):
71 video_id = self._match_id(url)
72 webpage = self._download_webpage(url, video_id)
73
74 formats = []
75
76 for mobj in re.finditer(r'<a[^>]+href="(?P<video_url>[^"]+download=true[^"]+)".*>(?P<ext>[^\s]+) (?P<quality>[^<]+)p</a>', webpage):
77 url, ext, quality = mobj.groups()
78 formats.append({
79 'url': url,
80 'ext': ext.lower(),
81 'quality': quality,
82 })
83
fee2d8d9 84 categories, creator, uploader, uploader_url = [None] * 4
85 for col in get_elements_by_class('col', webpage):
86 label = clean_html(get_element_by_class('label', col))
87 if label == 'Categories:':
88 categories = list(map(clean_html, get_elements_by_class('item', col)))
89 elif label == 'Artist:':
90 creator = join_nonempty(*map(clean_html, get_elements_by_class('item', col)), delim=', ')
91 elif label == 'Uploaded By:':
92 uploader = clean_html(get_element_by_class('name', col))
93 uploader_url = extract_attributes(get_element_html_by_class('name', col) or '').get('href')
faca6745 94
faca6745 95 return {
fee2d8d9 96 **traverse_obj(self._search_json_ld(webpage, video_id, default={}), ({
97 'title': 'title',
98 'view_count': 'view_count',
99 'like_count': 'like_count',
100 'duration': 'duration',
101 'timestamp': 'timestamp',
102 'description': 'description',
103 'thumbnail': ('thumbnails', 0, 'url'),
104 })),
faca6745 105 'id': video_id,
106 'formats': formats,
fee2d8d9 107 'title': self._html_extract_title(webpage),
108 'thumbnail': self._html_search_regex(
109 r'preview_url:\s+\'([^\']+)\'', webpage, 'thumbnail', default=None),
110 'duration': parse_duration(self._html_search_regex(
111 r'"icon-clock"></i>\s+<span>((?:\d+:?)+)', webpage, 'duration', default=None)),
112 'view_count': int_or_none(self._html_search_regex(
113 r'"icon-eye"></i>\s+<span>([ \d]+)', webpage, 'views', default='').replace(' ', '')),
114 'like_count': parse_count(get_element_by_class('voters count', webpage)),
115 'comment_count': int_or_none(self._search_regex(
116 r'[^(]+\((\d+)\)', get_element_by_attribute('href', '#tab_comments', webpage), 'comment count', fatal=False)),
58493923 117 'age_limit': 18,
fee2d8d9 118 'creator': creator,
119 'uploader': uploader,
120 'uploader_url': uploader_url,
121 'categories': categories,
58493923 122 'tags': list(map(unescapeHTML, re.findall(
123 r'<a class="tag_item"[^>]+\bhref="https://rule34video\.com/tags/\d+/"[^>]*>(?P<tag>[^>]*)</a>', webpage))),
faca6745 124 }