]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/eporner.py
[bitchute] Fix test (#758)
[yt-dlp.git] / yt_dlp / extractor / eporner.py
CommitLineData
1d57b252 1# coding: utf-8
2from __future__ import unicode_literals
3
1d57b252 4
5from .common import InfoExtractor
48d4681e 6from ..utils import (
b13647cf
S
7 encode_base_n,
8 ExtractorError,
9 int_or_none,
96dbf70d 10 merge_dicts,
48d4681e
PH
11 parse_duration,
12 str_to_int,
3052a30d 13 url_or_none,
48d4681e
PH
14)
15
1d57b252 16
17class EpornerIE(InfoExtractor):
29f7c58a 18 _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:(?:hd-porn|embed)/|video-)(?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',
96dbf70d
S
27 'description': 'md5:764f39abf932daafa37485eb46efa152',
28 'timestamp': 1232520922,
29 'upload_date': '20090121',
6a68bb57 30 'duration': 1838,
48d4681e 31 'view_count': int,
563f6dea 32 'age_limit': 18,
4ee0b8af 33 },
96dbf70d
S
34 'params': {
35 'proxy': '127.0.0.1:8118'
36 }
6f748df4
S
37 }, {
38 # New (May 2016) URL layout
4ee0b8af 39 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/',
6f748df4 40 'only_matching': True,
b13647cf
S
41 }, {
42 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
acc4ea62
S
43 'only_matching': True,
44 }, {
29f7c58a 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/',
b13647cf 49 'only_matching': True,
4ee0b8af 50 }]
1d57b252 51
52 def _real_extract(self, url):
5ad28e7f 53 mobj = self._match_valid_url(url)
1d57b252 54 video_id = mobj.group('id')
b13647cf
S
55 display_id = mobj.group('display_id') or video_id
56
57 webpage, urlh = self._download_webpage_handle(url, display_id)
58
7947a1f7 59 video_id = self._match_id(urlh.geturl())
a7862a1b 60
b13647cf 61 hash = self._search_regex(
29f7c58a 62 r'hash\s*[:=]\s*["\']([\da-f]{32})', webpage, 'hash')
1d57b252 63
b13647cf
S
64 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
65 r'<title>(.+?) - EPORNER', webpage, 'title')
a7862a1b 66
b13647cf
S
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']
a7862a1b
S
86
87 formats = []
b13647cf
S
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
3052a30d
S
94 src = url_or_none(format_dict.get('src'))
95 if not src or not src.startswith('http'):
b13647cf
S
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 })
a7862a1b 113 self._sort_formats(formats)
1d57b252 114
96dbf70d
S
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))
48d4681e 119 view_count = str_to_int(self._search_regex(
29f7c58a 120 r'id=["\']cinemaviews1["\'][^>]*>\s*([0-9,]+)',
121 webpage, 'view count', default=None))
1d57b252 122
96dbf70d 123 return merge_dicts(json_ld, {
1d57b252 124 'id': video_id,
a7862a1b 125 'display_id': display_id,
1d57b252 126 'title': title,
48d4681e
PH
127 'duration': duration,
128 'view_count': view_count,
a7862a1b 129 'formats': formats,
37f88565 130 'age_limit': 18,
96dbf70d 131 })