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