]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/eporner.py
[youtube] Make --write-annotations non fatal (closes #21452)
[yt-dlp.git] / youtube_dl / extractor / eporner.py
CommitLineData
1d57b252 1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
b13647cf 7from ..compat import compat_str
48d4681e 8from ..utils import (
b13647cf
S
9 encode_base_n,
10 ExtractorError,
11 int_or_none,
96dbf70d 12 merge_dicts,
48d4681e
PH
13 parse_duration,
14 str_to_int,
3052a30d 15 url_or_none,
48d4681e
PH
16)
17
1d57b252 18
19class EpornerIE(InfoExtractor):
acc4ea62 20 _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:hd-porn|embed)/(?P<id>\w+)(?:/(?P<display_id>[\w-]+))?'
4ee0b8af 21 _TESTS = [{
1d57b252 22 'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/',
8c23945c 23 'md5': '39d486f046212d8e1b911c52ab4691f8',
1d57b252 24 'info_dict': {
b13647cf 25 'id': 'qlDUmNsj6VS',
a7862a1b 26 'display_id': 'Infamous-Tiffany-Teen-Strip-Tease-Video',
8c23945c 27 'ext': 'mp4',
1d57b252 28 'title': 'Infamous Tiffany Teen Strip Tease Video',
96dbf70d
S
29 'description': 'md5:764f39abf932daafa37485eb46efa152',
30 'timestamp': 1232520922,
31 'upload_date': '20090121',
6a68bb57 32 'duration': 1838,
48d4681e 33 'view_count': int,
563f6dea 34 'age_limit': 18,
4ee0b8af 35 },
96dbf70d
S
36 'params': {
37 'proxy': '127.0.0.1:8118'
38 }
6f748df4
S
39 }, {
40 # New (May 2016) URL layout
4ee0b8af 41 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0/Star-Wars-XXX-Parody/',
6f748df4 42 'only_matching': True,
b13647cf
S
43 }, {
44 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
acc4ea62
S
45 'only_matching': True,
46 }, {
47 'url': 'http://www.eporner.com/hd-porn/3YRUtzMcWn0',
b13647cf 48 'only_matching': True,
4ee0b8af 49 }]
1d57b252 50
51 def _real_extract(self, url):
52 mobj = re.match(self._VALID_URL, url)
53 video_id = mobj.group('id')
b13647cf
S
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()))
a7862a1b 59
b13647cf
S
60 hash = self._search_regex(
61 r'hash\s*:\s*["\']([\da-f]{32})', webpage, 'hash')
1d57b252 62
b13647cf
S
63 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
64 r'<title>(.+?) - EPORNER', webpage, 'title')
a7862a1b 65
b13647cf
S
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']
a7862a1b
S
85
86 formats = []
b13647cf
S
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
3052a30d
S
93 src = url_or_none(format_dict.get('src'))
94 if not src or not src.startswith('http'):
b13647cf
S
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 })
a7862a1b 112 self._sort_formats(formats)
1d57b252 113
96dbf70d
S
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))
48d4681e
PH
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))
1d57b252 121
96dbf70d 122 return merge_dicts(json_ld, {
1d57b252 123 'id': video_id,
a7862a1b 124 'display_id': display_id,
1d57b252 125 'title': title,
48d4681e
PH
126 'duration': duration,
127 'view_count': view_count,
a7862a1b 128 'formats': formats,
37f88565 129 'age_limit': 18,
96dbf70d 130 })