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