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