]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/drtuber.py
[drtuber] Extract counters
[yt-dlp.git] / youtube_dl / extractor / drtuber.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import str_to_int
7
8
9 class DrTuberIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?drtuber\.com/video/(?P<id>\d+)/(?P<title_dash>[\w-]+)'
11 _TEST = {
12 'url': 'http://www.drtuber.com/video/1740434/hot-perky-blonde-naked-golf',
13 'md5': '93e680cf2536ad0dfb7e74d94a89facd',
14 'info_dict': {
15 'id': '1740434',
16 'ext': 'mp4',
17 'title': 'Hot Perky Blonde Naked Golf',
18 'like_count': int,
19 'dislike_count': int,
20 'comment_count': int,
21 'categories': list, # NSFW
22 'thumbnail': 're:https?://.*\.jpg$',
23 'age_limit': 18,
24 }
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 webpage = self._download_webpage(url, video_id)
32
33 video_url = self._html_search_regex(
34 r'<source src="([^"]+)"', webpage, 'video URL')
35
36 title = self._html_search_regex(
37 r'<title>([^<]+)\s*-\s*Free', webpage, 'title')
38
39 thumbnail = self._html_search_regex(
40 r'poster="([^"]+)"',
41 webpage, 'thumbnail', fatal=False)
42
43 like_count = str_to_int(self._html_search_regex(
44 r'<span id="rate_likes">\s*<img[^>]+>\s*<span>([\d,\.]+)</span>',
45 webpage, 'like count', fatal=False))
46 dislike_count = str_to_int(self._html_search_regex(
47 r'<span id="rate_dislikes">\s*<img[^>]+>\s*<span>([\d,\.]+)</span>',
48 webpage, 'like count', fatal=False))
49 comment_count = str_to_int(self._html_search_regex(
50 r'<span class="comments_count">([\d,\.]+)</span>',
51 webpage, 'comment count', fatal=False))
52
53 cats_str = self._html_search_regex(
54 r'<meta name="keywords" content="([^"]+)"', webpage, 'categories', fatal=False)
55 categories = None if cats_str is None else cats_str.split(' ')
56
57 return {
58 'id': video_id,
59 'url': video_url,
60 'title': title,
61 'thumbnail': thumbnail,
62 'like_count': like_count,
63 'dislike_count': dislike_count,
64 'comment_count': comment_count,
65 'categories': categories,
66 'age_limit': self._rta_search(webpage),
67 }