]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..compat import compat_str | |
8 | from ..utils import ( | |
9 | encode_base_n, | |
10 | ExtractorError, | |
11 | int_or_none, | |
12 | parse_duration, | |
13 | str_to_int, | |
14 | ) | |
15 | ||
16 | ||
17 | class EpornerIE(InfoExtractor): | |
18 | _VALID_URL = r'https?://(?:www\.)?eporner\.com/hd-porn/(?P<id>\w+)(?:/(?P<display_id>[\w-]+))?' | |
19 | _TESTS = [{ | |
20 | 'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/', | |
21 | 'md5': '39d486f046212d8e1b911c52ab4691f8', | |
22 | 'info_dict': { | |
23 | 'id': 'qlDUmNsj6VS', | |
24 | 'display_id': 'Infamous-Tiffany-Teen-Strip-Tease-Video', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Infamous Tiffany Teen Strip Tease Video', | |
27 | 'duration': 1838, | |
28 | 'view_count': int, | |
29 | 'age_limit': 18, | |
30 | }, | |
31 | }, { | |
32 | # New (May 2016) URL layout | |
33 | 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/', | |
34 | 'only_matching': True, | |
35 | }, { | |
36 | 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0', | |
37 | 'only_matching': True, | |
38 | }] | |
39 | ||
40 | def _real_extract(self, url): | |
41 | mobj = re.match(self._VALID_URL, url) | |
42 | video_id = mobj.group('id') | |
43 | display_id = mobj.group('display_id') or video_id | |
44 | ||
45 | webpage, urlh = self._download_webpage_handle(url, display_id) | |
46 | ||
47 | video_id = self._match_id(compat_str(urlh.geturl())) | |
48 | ||
49 | hash = self._search_regex( | |
50 | r'hash\s*:\s*["\']([\da-f]{32})', webpage, 'hash') | |
51 | ||
52 | title = self._og_search_title(webpage, default=None) or self._html_search_regex( | |
53 | r'<title>(.+?) - EPORNER', webpage, 'title') | |
54 | ||
55 | # Reverse engineered from vjs.js | |
56 | def calc_hash(s): | |
57 | return ''.join((encode_base_n(int(s[lb:lb + 8], 16), 36) for lb in range(0, 32, 8))) | |
58 | ||
59 | video = self._download_json( | |
60 | 'http://www.eporner.com/xhr/video/%s' % video_id, | |
61 | display_id, note='Downloading video JSON', | |
62 | query={ | |
63 | 'hash': calc_hash(hash), | |
64 | 'device': 'generic', | |
65 | 'domain': 'www.eporner.com', | |
66 | 'fallback': 'false', | |
67 | }) | |
68 | ||
69 | if video.get('available') is False: | |
70 | raise ExtractorError( | |
71 | '%s said: %s' % (self.IE_NAME, video['message']), expected=True) | |
72 | ||
73 | sources = video['sources'] | |
74 | ||
75 | formats = [] | |
76 | for kind, formats_dict in sources.items(): | |
77 | if not isinstance(formats_dict, dict): | |
78 | continue | |
79 | for format_id, format_dict in formats_dict.items(): | |
80 | if not isinstance(format_dict, dict): | |
81 | continue | |
82 | src = format_dict.get('src') | |
83 | if not isinstance(src, compat_str) or not src.startswith('http'): | |
84 | continue | |
85 | if kind == 'hls': | |
86 | formats.extend(self._extract_m3u8_formats( | |
87 | src, display_id, 'mp4', entry_protocol='m3u8_native', | |
88 | m3u8_id=kind, fatal=False)) | |
89 | else: | |
90 | height = int_or_none(self._search_regex( | |
91 | r'(\d+)[pP]', format_id, 'height', default=None)) | |
92 | fps = int_or_none(self._search_regex( | |
93 | r'(\d+)fps', format_id, 'fps', default=None)) | |
94 | ||
95 | formats.append({ | |
96 | 'url': src, | |
97 | 'format_id': format_id, | |
98 | 'height': height, | |
99 | 'fps': fps, | |
100 | }) | |
101 | self._sort_formats(formats) | |
102 | ||
103 | duration = parse_duration(self._html_search_meta('duration', webpage)) | |
104 | view_count = str_to_int(self._search_regex( | |
105 | r'id="cinemaviews">\s*([0-9,]+)\s*<small>views', | |
106 | webpage, 'view count', fatal=False)) | |
107 | ||
108 | return { | |
109 | 'id': video_id, | |
110 | 'display_id': display_id, | |
111 | 'title': title, | |
112 | 'duration': duration, | |
113 | 'view_count': view_count, | |
114 | 'formats': formats, | |
115 | 'age_limit': 18, | |
116 | } |