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