]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/drtuber.py
[spotify] Detect iframe embeds (#3430)
[yt-dlp.git] / yt_dlp / extractor / drtuber.py
CommitLineData
d740f7e1 1import re
2
3from .common import InfoExtractor
0aef0771 4from ..utils import (
b9bc1cff 5 int_or_none,
0aef0771 6 NO_DEFAULT,
b9bc1cff 7 parse_duration,
0aef0771
S
8 str_to_int,
9)
d740f7e1 10
11
12class DrTuberIE(InfoExtractor):
38db52ad 13 _VALID_URL = r'https?://(?:(?:www|m)\.)?drtuber\.com/(?:video|embed)/(?P<id>\d+)(?:/(?P<display_id>[\w-]+))?'
519d8970 14 _TESTS = [{
d740f7e1 15 'url': 'http://www.drtuber.com/video/1740434/hot-perky-blonde-naked-golf',
16 'md5': '93e680cf2536ad0dfb7e74d94a89facd',
17 'info_dict': {
18 'id': '1740434',
33422c05 19 'display_id': 'hot-perky-blonde-naked-golf',
d740f7e1 20 'ext': 'mp4',
76d1466b 21 'title': 'hot perky blonde naked golf',
eade1d7e 22 'like_count': int,
eade1d7e 23 'comment_count': int,
2914e5f0 24 'categories': ['Babe', 'Blonde', 'Erotic', 'Outdoor', 'Softcore', 'Solo'],
ec85ded8 25 'thumbnail': r're:https?://.*\.jpg$',
11fc065c 26 'age_limit': 18,
d740f7e1 27 }
519d8970
S
28 }, {
29 'url': 'http://www.drtuber.com/embed/489939',
30 'only_matching': True,
38db52ad
W
31 }, {
32 'url': 'http://m.drtuber.com/video/3893529/lingerie-blowjob-from-beautiful-teen',
33 'only_matching': True,
519d8970 34 }]
d740f7e1 35
37e7a71c
S
36 @staticmethod
37 def _extract_urls(webpage):
38 return re.findall(
39 r'<iframe[^>]+?src=["\'](?P<url>(?:https?:)?//(?:www\.)?drtuber\.com/embed/\d+)',
40 webpage)
41
d740f7e1 42 def _real_extract(self, url):
5ad28e7f 43 mobj = self._match_valid_url(url)
d740f7e1 44 video_id = mobj.group('id')
519d8970 45 display_id = mobj.group('display_id') or video_id
d740f7e1 46
519d8970
S
47 webpage = self._download_webpage(
48 'http://www.drtuber.com/video/%s' % video_id, display_id)
d740f7e1 49
0f4a5a73
PV
50 video_data = self._download_json(
51 'http://www.drtuber.com/player_config_json/', video_id, query={
52 'vid': video_id,
53 'embed': 0,
54 'aid': 0,
55 'domain_id': 0,
56 })
57
58 formats = []
59 for format_id, video_url in video_data['files'].items():
60 if video_url:
61 formats.append({
62 'format_id': format_id,
63 'quality': 2 if format_id == 'hq' else 1,
64 'url': video_url
65 })
66 self._sort_formats(formats)
d740f7e1 67
b9bc1cff
J
68 duration = int_or_none(video_data.get('duration')) or parse_duration(
69 video_data.get('duration_format'))
70
d740f7e1 71 title = self._html_search_regex(
9d15be3a
PV
72 (r'<h1[^>]+class=["\']title[^>]+>([^<]+)',
73 r'<title>([^<]+)\s*@\s+DrTuber',
74 r'class="title_watch"[^>]*><(?:p|h\d+)[^>]*>([^<]+)<',
367976d4
S
75 r'<p[^>]+class="title_substrate">([^<]+)</p>',
76 r'<title>([^<]+) - \d+'),
76d1466b 77 webpage, 'title')
d740f7e1 78
79 thumbnail = self._html_search_regex(
80 r'poster="([^"]+)"',
81 webpage, 'thumbnail', fatal=False)
82
0aef0771 83 def extract_count(id_, name, default=NO_DEFAULT):
86511ea4
S
84 return str_to_int(self._html_search_regex(
85 r'<span[^>]+(?:class|id)="%s"[^>]*>([\d,\.]+)</span>' % id_,
0aef0771 86 webpage, '%s count' % name, default=default, fatal=False))
86511ea4
S
87
88 like_count = extract_count('rate_likes', 'like')
0aef0771 89 dislike_count = extract_count('rate_dislikes', 'dislike', default=None)
86511ea4 90 comment_count = extract_count('comments_count', 'comment')
eade1d7e 91
2914e5f0 92 cats_str = self._search_regex(
0aef0771
S
93 r'<div[^>]+class="categories_list">(.+?)</div>',
94 webpage, 'categories', fatal=False)
95 categories = [] if not cats_str else re.findall(
96 r'<a title="([^"]+)"', cats_str)
d740f7e1 97
98 return {
99 'id': video_id,
1bf8cf5c 100 'display_id': display_id,
0f4a5a73 101 'formats': formats,
d740f7e1 102 'title': title,
103 'thumbnail': thumbnail,
eade1d7e
S
104 'like_count': like_count,
105 'dislike_count': dislike_count,
106 'comment_count': comment_count,
d740f7e1 107 'categories': categories,
11fc065c 108 'age_limit': self._rta_search(webpage),
b9bc1cff 109 'duration': duration,
d740f7e1 110 }