]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/iwara.py
[cleanup] Misc
[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
79 title = remove_end(self._html_search_regex(
80 r'<title>([^<]+)</title>', webpage, 'title'), ' | Iwara')
81
63b1ad0f 82 thumbnail = self._html_search_regex(
8eb7ba82
B
83 r'poster=[\'"]([^\'"]+)', webpage, 'thumbnail', default=None)
84
85 uploader = self._html_search_regex(
86 r'class="username">([^<]+)', webpage, 'uploader', fatal=False)
87
88 upload_date = unified_strdate(self._html_search_regex(
89 r'作成日:([^\s]+)', webpage, 'upload_date', fatal=False))
90
91 description = strip_or_none(self._search_regex(
92 r'<p>(.+?(?=</div))', webpage, 'description', fatal=False,
93 flags=re.DOTALL))
63b1ad0f 94
caf0f5f8
YCH
95 formats = []
96 for a_format in video_data:
4ecf300d
S
97 format_uri = url_or_none(a_format.get('uri'))
98 if not format_uri:
99 continue
caf0f5f8
YCH
100 format_id = a_format.get('resolution')
101 height = int_or_none(self._search_regex(
102 r'(\d+)p', format_id, 'height', default=None))
103 formats.append({
4ecf300d 104 'url': self._proto_relative_url(format_uri, 'https:'),
caf0f5f8
YCH
105 'format_id': format_id,
106 'ext': mimetype2ext(a_format.get('mime')) or 'mp4',
107 'height': height,
2ab2c0d1 108 'width': int_or_none(height / 9.0 * 16.0 if height else None),
caf0f5f8
YCH
109 'quality': 1 if format_id == 'Source' else 0,
110 })
111
112 self._sort_formats(formats)
113
114 return {
001a5fd3
YCH
115 'id': video_id,
116 'title': title,
117 'age_limit': age_limit,
caf0f5f8 118 'formats': formats,
63b1ad0f 119 'thumbnail': self._proto_relative_url(thumbnail, 'https:'),
8eb7ba82
B
120 'uploader': uploader,
121 'upload_date': upload_date,
122 'description': description,
caf0f5f8 123 }