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