]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rule34video.py
[cleanup] Use `_html_extract_title`
[yt-dlp.git] / yt_dlp / extractor / rule34video.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3 import re
4
5 from ..utils import parse_duration
6 from .common import InfoExtractor
7
8
9 class Rule34VideoIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?rule34video\.com/videos/(?P<id>\d+)'
11 _TESTS = [
12 {
13 'url': 'https://rule34video.com/videos/3065157/shot-it-mmd-hmv/',
14 'md5': 'ffccac2c23799dabbd192621ae4d04f3',
15 'info_dict': {
16 'id': '3065157',
17 'ext': 'mp4',
18 'title': 'Shot It-(mmd hmv)',
19 'thumbnail': 'https://rule34video.com/contents/videos_screenshots/3065000/3065157/preview.jpg',
20 'duration': 347.0,
21 'age_limit': 18
22 }
23 },
24 {
25 'url': 'https://rule34video.com/videos/3065296/lara-in-trouble-ep-7-wildeerstudio/',
26 'md5': '6bb5169f9f6b38cd70882bf2e64f6b86',
27 'info_dict': {
28 'id': '3065296',
29 'ext': 'mp4',
30 'title': 'Lara in Trouble Ep. 7 [WildeerStudio]',
31 'thumbnail': 'https://rule34video.com/contents/videos_screenshots/3065000/3065296/preview.jpg',
32 'duration': 938.0,
33 'age_limit': 18
34 }
35 },
36 ]
37
38 def _real_extract(self, url):
39 video_id = self._match_id(url)
40 webpage = self._download_webpage(url, video_id)
41
42 formats = []
43
44 for mobj in re.finditer(r'<a[^>]+href="(?P<video_url>[^"]+download=true[^"]+)".*>(?P<ext>[^\s]+) (?P<quality>[^<]+)p</a>', webpage):
45 url, ext, quality = mobj.groups()
46 formats.append({
47 'url': url,
48 'ext': ext.lower(),
49 'quality': quality,
50 })
51
52 title = self._html_extract_title(webpage)
53 thumbnail = self._html_search_regex(r'preview_url:\s+\'([^\']+)\'', webpage, 'thumbnail', default=None)
54 duration = self._html_search_regex(r'"icon-clock"></i>\s+<span>((?:\d+:?)+)', webpage, 'duration', default=None)
55
56 self._sort_formats(formats)
57
58 return {
59 'id': video_id,
60 'formats': formats,
61 'title': title,
62 'thumbnail': thumbnail,
63 'duration': parse_duration(duration),
64 'age_limit': 18
65 }