]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/eporner.py
[extractor] Common function `_match_valid_url`
[yt-dlp.git] / yt_dlp / extractor / eporner.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import (
7 encode_base_n,
8 ExtractorError,
9 int_or_none,
10 merge_dicts,
11 parse_duration,
12 str_to_int,
13 url_or_none,
14 )
15
16
17 class EpornerIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:(?:hd-porn|embed)/|video-)(?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 'description': 'md5:764f39abf932daafa37485eb46efa152',
28 'timestamp': 1232520922,
29 'upload_date': '20090121',
30 'duration': 1838,
31 'view_count': int,
32 'age_limit': 18,
33 },
34 'params': {
35 'proxy': '127.0.0.1:8118'
36 }
37 }, {
38 # New (May 2016) URL layout
39 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/',
40 'only_matching': True,
41 }, {
42 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
43 'only_matching': True,
44 }, {
45 'url': 'http://www.eporner.com/embed/3YRUtzMcWn0',
46 'only_matching': True,
47 }, {
48 'url': 'https://www.eporner.com/video-FJsA19J3Y3H/one-of-the-greats/',
49 'only_matching': True,
50 }]
51
52 def _real_extract(self, url):
53 mobj = self._match_valid_url(url)
54 video_id = mobj.group('id')
55 display_id = mobj.group('display_id') or video_id
56
57 webpage, urlh = self._download_webpage_handle(url, display_id)
58
59 video_id = self._match_id(urlh.geturl())
60
61 hash = self._search_regex(
62 r'hash\s*[:=]\s*["\']([\da-f]{32})', webpage, 'hash')
63
64 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
65 r'<title>(.+?) - EPORNER', webpage, 'title')
66
67 # Reverse engineered from vjs.js
68 def calc_hash(s):
69 return ''.join((encode_base_n(int(s[lb:lb + 8], 16), 36) for lb in range(0, 32, 8)))
70
71 video = self._download_json(
72 'http://www.eporner.com/xhr/video/%s' % video_id,
73 display_id, note='Downloading video JSON',
74 query={
75 'hash': calc_hash(hash),
76 'device': 'generic',
77 'domain': 'www.eporner.com',
78 'fallback': 'false',
79 })
80
81 if video.get('available') is False:
82 raise ExtractorError(
83 '%s said: %s' % (self.IE_NAME, video['message']), expected=True)
84
85 sources = video['sources']
86
87 formats = []
88 for kind, formats_dict in sources.items():
89 if not isinstance(formats_dict, dict):
90 continue
91 for format_id, format_dict in formats_dict.items():
92 if not isinstance(format_dict, dict):
93 continue
94 src = url_or_none(format_dict.get('src'))
95 if not src or not src.startswith('http'):
96 continue
97 if kind == 'hls':
98 formats.extend(self._extract_m3u8_formats(
99 src, display_id, 'mp4', entry_protocol='m3u8_native',
100 m3u8_id=kind, fatal=False))
101 else:
102 height = int_or_none(self._search_regex(
103 r'(\d+)[pP]', format_id, 'height', default=None))
104 fps = int_or_none(self._search_regex(
105 r'(\d+)fps', format_id, 'fps', default=None))
106
107 formats.append({
108 'url': src,
109 'format_id': format_id,
110 'height': height,
111 'fps': fps,
112 })
113 self._sort_formats(formats)
114
115 json_ld = self._search_json_ld(webpage, display_id, default={})
116
117 duration = parse_duration(self._html_search_meta(
118 'duration', webpage, default=None))
119 view_count = str_to_int(self._search_regex(
120 r'id=["\']cinemaviews1["\'][^>]*>\s*([0-9,]+)',
121 webpage, 'view count', default=None))
122
123 return merge_dicts(json_ld, {
124 'id': video_id,
125 'display_id': display_id,
126 'title': title,
127 'duration': duration,
128 'view_count': view_count,
129 'formats': formats,
130 'age_limit': 18,
131 })