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