]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/vporn.py
[SpankBang] Use python2.6 compatible string formatting spec
[youtube-dl] / youtube_dl / extractor / vporn.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     parse_duration,
8     str_to_int,
9 )
10
11
12 class VpornIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?vporn\.com/[^/]+/(?P<display_id>[^/]+)/(?P<id>\d+)'
14     _TESTS = [
15         {
16             'url': 'http://www.vporn.com/masturbation/violet-on-her-th-birthday/497944/',
17             'md5': 'facf37c1b86546fa0208058546842c55',
18             'info_dict': {
19                 'id': '497944',
20                 'display_id': 'violet-on-her-th-birthday',
21                 'ext': 'mp4',
22                 'title': 'Violet on her 19th birthday',
23                 'description': 'Violet dances in front of the camera which is sure to get you horny.',
24                 'thumbnail': 're:^https?://.*\.jpg$',
25                 'uploader': 'kileyGrope',
26                 'categories': ['Masturbation', 'Teen'],
27                 'duration': 393,
28                 'age_limit': 18,
29                 'view_count': int,
30                 'like_count': int,
31                 'dislike_count': int,
32                 'comment_count': int,
33             }
34         },
35         {
36             'url': 'http://www.vporn.com/female/hana-shower/523564/',
37             'md5': 'ced35a4656198a1664cf2cda1575a25f',
38             'info_dict': {
39                 'id': '523564',
40                 'display_id': 'hana-shower',
41                 'ext': 'mp4',
42                 'title': 'Hana Shower',
43                 'description': 'Hana showers at the bathroom.',
44                 'thumbnail': 're:^https?://.*\.jpg$',
45                 'uploader': 'Hmmmmm',
46                 'categories': ['Big Boobs', 'Erotic', 'Teen', 'Female'],
47                 'duration': 588,
48                 'age_limit': 18,
49                 'view_count': int,
50                 'like_count': int,
51                 'dislike_count': int,
52                 'comment_count': int,
53             }
54         },
55     ]
56
57     def _real_extract(self, url):
58         mobj = re.match(self._VALID_URL, url)
59         video_id = mobj.group('id')
60         display_id = mobj.group('display_id')
61
62         webpage = self._download_webpage(url, display_id)
63
64         title = self._html_search_regex(
65             r'videoname\s*=\s*\'([^\']+)\'', webpage, 'title').strip()
66         description = self._html_search_regex(
67             r'<div class="description_txt">(.*?)</div>', webpage, 'description', fatal=False)
68         thumbnail = self._html_search_regex(
69             r'flashvars\.imageUrl\s*=\s*"([^"]+)"', webpage, 'description', fatal=False, default=None)
70         if thumbnail:
71             thumbnail = 'http://www.vporn.com' + thumbnail
72
73         uploader = self._html_search_regex(
74             r'(?s)UPLOADED BY.*?<a href="/user/[^"]+">([^<]+)</a>',
75             webpage, 'uploader', fatal=False)
76
77         categories = re.findall(r'<a href="/cat/[^"]+">([^<]+)</a>', webpage)
78
79         duration = parse_duration(self._search_regex(
80             r'duration (\d+ min \d+ sec)', webpage, 'duration', fatal=False))
81
82         view_count = str_to_int(self._html_search_regex(
83             r'<span>([\d,\.]+) VIEWS</span>', webpage, 'view count', fatal=False))
84         like_count = str_to_int(self._html_search_regex(
85             r'<span id="like" class="n">([\d,\.]+)</span>', webpage, 'like count', fatal=False))
86         dislike_count = str_to_int(self._html_search_regex(
87             r'<span id="dislike" class="n">([\d,\.]+)</span>', webpage, 'dislike count', fatal=False))
88         comment_count = str_to_int(self._html_search_regex(
89             r'<h4>Comments \(<b>([\d,\.]+)</b>\)</h4>', webpage, 'comment count', fatal=False))
90
91         formats = []
92
93         for video in re.findall(r'flashvars\.videoUrl([^=]+?)\s*=\s*"(https?://[^"]+)"', webpage):
94             video_url = video[1]
95             fmt = {
96                 'url': video_url,
97                 'format_id': video[0],
98             }
99             m = re.search(r'_(?P<width>\d+)x(?P<height>\d+)_(?P<vbr>\d+)k\.mp4$', video_url)
100             if m:
101                 fmt.update({
102                     'width': int(m.group('width')),
103                     'height': int(m.group('height')),
104                     'vbr': int(m.group('vbr')),
105                 })
106             formats.append(fmt)
107
108         self._sort_formats(formats)
109
110         return {
111             'id': video_id,
112             'display_id': display_id,
113             'title': title,
114             'description': description,
115             'thumbnail': thumbnail,
116             'uploader': uploader,
117             'categories': categories,
118             'duration': duration,
119             'view_count': view_count,
120             'like_count': like_count,
121             'dislike_count': dislike_count,
122             'comment_count': comment_count,
123             'age_limit': 18,
124             'formats': formats,
125         }