]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/iwara.py
[spotify] Detect iframe embeds (#3430)
[yt-dlp.git] / yt_dlp / extractor / iwara.py
1 import re
2
3 from .common import InfoExtractor
4 from ..compat import compat_urllib_parse_urlparse
5 from ..utils import (
6 int_or_none,
7 mimetype2ext,
8 remove_end,
9 url_or_none,
10 unified_strdate,
11 strip_or_none,
12 )
13
14
15 class IwaraIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.|ecchi\.)?iwara\.tv/videos/(?P<id>[a-zA-Z0-9]+)'
17 _TESTS = [{
18 'url': 'http://iwara.tv/videos/amVwUl1EHpAD9RD',
19 # md5 is unstable
20 'info_dict': {
21 'id': 'amVwUl1EHpAD9RD',
22 'ext': 'mp4',
23 'title': '【MMD R-18】ガールフレンド carry_me_off',
24 'age_limit': 18,
25 'thumbnail': 'https://i.iwara.tv/sites/default/files/videos/thumbnails/7951/thumbnail-7951_0001.png',
26 'uploader': 'Reimu丨Action',
27 'upload_date': '20150828',
28 'description': 'md5:1d4905ce48c66c9299c617f08e106e0f',
29 },
30 }, {
31 'url': 'http://ecchi.iwara.tv/videos/Vb4yf2yZspkzkBO',
32 'md5': '7e5f1f359cd51a027ba4a7b7710a50f0',
33 'info_dict': {
34 'id': '0B1LvuHnL-sRFNXB1WHNqbGw4SXc',
35 'ext': 'mp4',
36 'title': '[3D Hentai] Kyonyu × Genkai × Emaki Shinobi Girls.mp4',
37 'age_limit': 18,
38 },
39 'add_ie': ['GoogleDrive'],
40 }, {
41 'url': 'http://www.iwara.tv/videos/nawkaumd6ilezzgq',
42 # md5 is unstable
43 'info_dict': {
44 'id': '6liAP9s2Ojc',
45 'ext': 'mp4',
46 'age_limit': 18,
47 'title': '[MMD] Do It Again Ver.2 [1080p 60FPS] (Motion,Camera,Wav+DL)',
48 'description': 'md5:590c12c0df1443d833fbebe05da8c47a',
49 'upload_date': '20160910',
50 'uploader': 'aMMDsork',
51 'uploader_id': 'UCVOFyOSCyFkXTYYHITtqB7A',
52 },
53 'add_ie': ['Youtube'],
54 }]
55
56 def _real_extract(self, url):
57 video_id = self._match_id(url)
58
59 webpage, urlh = self._download_webpage_handle(url, video_id)
60
61 hostname = compat_urllib_parse_urlparse(urlh.geturl()).hostname
62 # ecchi is 'sexy' in Japanese
63 age_limit = 18 if hostname.split('.')[0] == 'ecchi' else 0
64
65 video_data = self._download_json('http://www.iwara.tv/api/video/%s' % video_id, video_id)
66
67 if not video_data:
68 iframe_url = self._html_search_regex(
69 r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1',
70 webpage, 'iframe URL', group='url')
71 return {
72 '_type': 'url_transparent',
73 'url': iframe_url,
74 'age_limit': age_limit,
75 }
76
77 title = remove_end(self._html_extract_title(webpage), ' | Iwara')
78
79 thumbnail = self._html_search_regex(
80 r'poster=[\'"]([^\'"]+)', webpage, 'thumbnail', default=None)
81
82 uploader = self._html_search_regex(
83 r'class="username">([^<]+)', webpage, 'uploader', fatal=False)
84
85 upload_date = unified_strdate(self._html_search_regex(
86 r'作成日:([^\s]+)', webpage, 'upload_date', fatal=False))
87
88 description = strip_or_none(self._search_regex(
89 r'<p>(.+?(?=</div))', webpage, 'description', fatal=False,
90 flags=re.DOTALL))
91
92 formats = []
93 for a_format in video_data:
94 format_uri = url_or_none(a_format.get('uri'))
95 if not format_uri:
96 continue
97 format_id = a_format.get('resolution')
98 height = int_or_none(self._search_regex(
99 r'(\d+)p', format_id, 'height', default=None))
100 formats.append({
101 'url': self._proto_relative_url(format_uri, 'https:'),
102 'format_id': format_id,
103 'ext': mimetype2ext(a_format.get('mime')) or 'mp4',
104 'height': height,
105 'width': int_or_none(height / 9.0 * 16.0 if height else None),
106 'quality': 1 if format_id == 'Source' else 0,
107 })
108
109 self._sort_formats(formats)
110
111 return {
112 'id': video_id,
113 'title': title,
114 'age_limit': age_limit,
115 'formats': formats,
116 'thumbnail': self._proto_relative_url(thumbnail, 'https:'),
117 'uploader': uploader,
118 'upload_date': upload_date,
119 'description': description,
120 }