]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/drtuber.py
[drtuber] Make dislike count optional (Closes #10297)
[yt-dlp.git] / youtube_dl / extractor / drtuber.py
CommitLineData
d740f7e1 1from __future__ import unicode_literals
2
3import re
4
5from .common import InfoExtractor
0aef0771
S
6from ..utils import (
7 NO_DEFAULT,
8 str_to_int,
9)
d740f7e1 10
11
12class DrTuberIE(InfoExtractor):
1bf8cf5c 13 _VALID_URL = r'https?://(?:www\.)?drtuber\.com/video/(?P<id>\d+)/(?P<display_id>[\w-]+)'
d740f7e1 14 _TEST = {
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'],
d740f7e1 25 'thumbnail': 're:https?://.*\.jpg$',
11fc065c 26 'age_limit': 18,
d740f7e1 27 }
28 }
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 video_id = mobj.group('id')
1bf8cf5c 33 display_id = mobj.group('display_id')
d740f7e1 34
1bf8cf5c 35 webpage = self._download_webpage(url, display_id)
d740f7e1 36
37 video_url = self._html_search_regex(
38 r'<source src="([^"]+)"', webpage, 'video URL')
39
40 title = self._html_search_regex(
86511ea4 41 [r'<p[^>]+class="title_substrate">([^<]+)</p>', r'<title>([^<]+) - \d+'],
76d1466b 42 webpage, 'title')
d740f7e1 43
44 thumbnail = self._html_search_regex(
45 r'poster="([^"]+)"',
46 webpage, 'thumbnail', fatal=False)
47
0aef0771 48 def extract_count(id_, name, default=NO_DEFAULT):
86511ea4
S
49 return str_to_int(self._html_search_regex(
50 r'<span[^>]+(?:class|id)="%s"[^>]*>([\d,\.]+)</span>' % id_,
0aef0771 51 webpage, '%s count' % name, default=default, fatal=False))
86511ea4
S
52
53 like_count = extract_count('rate_likes', 'like')
0aef0771 54 dislike_count = extract_count('rate_dislikes', 'dislike', default=None)
86511ea4 55 comment_count = extract_count('comments_count', 'comment')
eade1d7e 56
2914e5f0 57 cats_str = self._search_regex(
0aef0771
S
58 r'<div[^>]+class="categories_list">(.+?)</div>',
59 webpage, 'categories', fatal=False)
60 categories = [] if not cats_str else re.findall(
61 r'<a title="([^"]+)"', cats_str)
d740f7e1 62
63 return {
64 'id': video_id,
1bf8cf5c 65 'display_id': display_id,
d740f7e1 66 'url': video_url,
67 'title': title,
68 'thumbnail': thumbnail,
eade1d7e
S
69 'like_count': like_count,
70 'dislike_count': dislike_count,
71 'comment_count': comment_count,
d740f7e1 72 'categories': categories,
11fc065c 73 'age_limit': self._rta_search(webpage),
d740f7e1 74 }