]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/vporn.py
[pluralsight] Process all clip URLs (closes #10984)
[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     ExtractorError,
8     parse_duration,
9     str_to_int,
10 )
11
12
13 class VpornIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?vporn\.com/[^/]+/(?P<display_id>[^/]+)/(?P<id>\d+)'
15     _TESTS = [
16         {
17             'url': 'http://www.vporn.com/masturbation/violet-on-her-th-birthday/497944/',
18             'md5': 'facf37c1b86546fa0208058546842c55',
19             'info_dict': {
20                 'id': '497944',
21                 'display_id': 'violet-on-her-th-birthday',
22                 'ext': 'mp4',
23                 'title': 'Violet on her 19th birthday',
24                 'description': 'Violet dances in front of the camera which is sure to get you horny.',
25                 'thumbnail': 're:^https?://.*\.jpg$',
26                 'uploader': 'kileyGrope',
27                 'categories': ['Masturbation', 'Teen'],
28                 'duration': 393,
29                 'age_limit': 18,
30                 'view_count': int,
31             },
32             'skip': 'video removed',
33         },
34         {
35             'url': 'http://www.vporn.com/female/hana-shower/523564/',
36             'md5': 'ced35a4656198a1664cf2cda1575a25f',
37             'info_dict': {
38                 'id': '523564',
39                 'display_id': 'hana-shower',
40                 'ext': 'mp4',
41                 'title': 'Hana Shower',
42                 'description': 'Hana showers at the bathroom.',
43                 'thumbnail': 're:^https?://.*\.jpg$',
44                 'uploader': 'Hmmmmm',
45                 'categories': ['Big Boobs', 'Erotic', 'Teen', 'Female', '720p'],
46                 'duration': 588,
47                 'age_limit': 18,
48                 'view_count': int,
49             }
50         },
51     ]
52
53     def _real_extract(self, url):
54         mobj = re.match(self._VALID_URL, url)
55         video_id = mobj.group('id')
56         display_id = mobj.group('display_id')
57
58         webpage = self._download_webpage(url, display_id)
59
60         errmsg = 'This video has been deleted due to Copyright Infringement or by the account owner!'
61         if errmsg in webpage:
62             raise ExtractorError('%s said: %s' % (self.IE_NAME, errmsg), expected=True)
63
64         title = self._html_search_regex(
65             r'videoname\s*=\s*\'([^\']+)\'', webpage, 'title').strip()
66         description = self._html_search_regex(
67             r'class="(?:descr|description_txt)">(.*?)</div>',
68             webpage, 'description', fatal=False)
69         thumbnail = self._html_search_regex(
70             r'flashvars\.imageUrl\s*=\s*"([^"]+)"', webpage, 'description', fatal=False, default=None)
71         if thumbnail:
72             thumbnail = 'http://www.vporn.com' + thumbnail
73
74         uploader = self._html_search_regex(
75             r'(?s)Uploaded by:.*?<a href="/user/[^"]+"[^>]*>(.+?)</a>',
76             webpage, 'uploader', fatal=False)
77
78         categories = re.findall(r'<a href="/cat/[^"]+"[^>]*>([^<]+)</a>', webpage)
79
80         duration = parse_duration(self._search_regex(
81             r'Runtime:\s*</span>\s*(\d+ min \d+ sec)',
82             webpage, 'duration', fatal=False))
83
84         view_count = str_to_int(self._search_regex(
85             r'class="views">([\d,\.]+) [Vv]iews<',
86             webpage, 'view count', fatal=False))
87         comment_count = str_to_int(self._html_search_regex(
88             r"'Comments \(([\d,\.]+)\)'",
89             webpage, 'comment count', default=None))
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             'comment_count': comment_count,
121             'age_limit': 18,
122             'formats': formats,
123         }