5 from .common
import InfoExtractor
17 class IwaraIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:www\.|ecchi\.)?iwara\.tv/videos?/(?P<id>[a-zA-Z0-9]+)'
21 # this video cannot be played because of migration
22 'only_matching': True,
23 'url': 'https://www.iwara.tv/video/k2ayoueezfkx6gvq',
25 'id': 'k2ayoueezfkx6gvq',
28 'title': 'Defeat of Irybelda - アイリベルダの敗北',
29 'description': 'md5:70278abebe706647a8b4cb04cf23e0d3',
30 'uploader': 'Inwerwm',
31 'uploader_id': 'inwerwm',
34 'view_count': 1050343,
36 'timestamp': 1677843869,
37 'modified_timestamp': 1679056362,
40 'url': 'https://iwara.tv/video/1ywe1sbkqwumpdxz5/',
41 'md5': '20691ce1473ec2766c0788e14c60ce66',
43 'id': '1ywe1sbkqwumpdxz5',
46 'title': 'Aponia 阿波尼亚SEX Party Tonight 手动脱衣 大奶 裸腿',
47 'description': 'md5:0c4c310f2e0592d68b9f771d348329ca',
49 'uploader_id': 'user792540',
56 'timestamp': 1678732213,
57 'modified_timestamp': 1679110271,
61 def _extract_formats(self
, video_id
, fileurl
):
62 up
= urllib
.parse
.urlparse(fileurl
)
63 q
= urllib
.parse
.parse_qs(up
.query
)
64 paths
= up
.path
.rstrip('/').split('/')
65 # https://github.com/yt-dlp/yt-dlp/issues/6549#issuecomment-1473771047
66 x_version
= hashlib
.sha1('_'.join((paths
[-1], q
['expires'][0], '5nFp9kmbNnHdAFhaqMvt')).encode()).hexdigest()
68 preference
= qualities(['preview', '360', '540', 'Source'])
70 files
= self
._download
_json
(fileurl
, video_id
, headers
={'X-Version': x_version}
)
72 yield traverse_obj(fmt
, {
74 'url': ('src', ('view', 'download'), {self._proto_relative_url}
),
75 'ext': ('type', {mimetype2ext}
),
76 'quality': ('name', {preference}
),
77 'height': ('name', {int_or_none}
),
80 def _real_extract(self
, url
):
81 video_id
= self
._match
_id
(url
)
82 video_data
= self
._download
_json
(f
'https://api.iwara.tv/video/{video_id}', video_id
, expected_status
=lambda x
: True)
83 errmsg
= video_data
.get('message')
84 # at this point we can actually get uploaded user info, but do we need it?
85 if errmsg
== 'errors.privateVideo':
86 self
.raise_login_required('Private video. Login if you have permissions to watch')
88 raise ExtractorError(f
'Iwara says: {errmsg}')
90 if not video_data
.get('fileUrl'):
91 if video_data
.get('embedUrl'):
92 return self
.url_result(video_data
.get('embedUrl'))
93 raise ExtractorError('This video is unplayable', expected
=True)
97 'age_limit': 18 if video_data
.get('rating') == 'ecchi' else 0, # ecchi is 'sexy' in Japanese
98 **traverse_obj(video_data
, {
100 'description': 'body',
101 'uploader': ('user', 'name'),
102 'uploader_id': ('user', 'username'),
103 'tags': ('tags', ..., 'id'),
104 'like_count': 'numLikes',
105 'view_count': 'numViews',
106 'comment_count': 'numComments',
107 'timestamp': ('createdAt', {unified_timestamp}
),
108 'modified_timestamp': ('updatedAt', {unified_timestamp}
),
109 'thumbnail': ('file', 'id', {str}
, {
110 lambda x
: f
'https://files.iwara.tv/image/thumbnail/{x}/thumbnail-00.jpg'}),
112 'formats': list(self
._extract
_formats
(video_id
, video_data
.get('fileUrl'))),
116 class IwaraUserIE(InfoExtractor
):
117 _VALID_URL
= r
'https?://(?:www\.)?iwara\.tv/profile/(?P<id>[^/?#&]+)'
118 IE_NAME
= 'iwara:user'
122 'url': 'https://iwara.tv/profile/user792540/videos',
126 'playlist_mincount': 80,
128 'url': 'https://iwara.tv/profile/theblackbirdcalls/videos',
130 'id': 'theblackbirdcalls',
132 'playlist_mincount': 723,
134 'url': 'https://iwara.tv/profile/user792540',
135 'only_matching': True,
137 'url': 'https://iwara.tv/profile/theblackbirdcalls',
138 'only_matching': True,
141 def _entries(self
, playlist_id
, user_id
, page
):
142 videos
= self
._download
_json
(
143 'https://api.iwara.tv/videos', playlist_id
,
144 note
=f
'Downloading page {page}',
149 'limit': self
._PER
_PAGE
,
151 for x
in traverse_obj(videos
, ('results', ..., 'id')):
152 yield self
.url_result(f
'https://iwara.tv/video/{x}')
154 def _real_extract(self
, url
):
155 playlist_id
= self
._match
_id
(url
)
156 user_info
= self
._download
_json
(
157 f
'https://api.iwara.tv/profile/{playlist_id}', playlist_id
,
158 note
='Requesting user info')
159 user_id
= traverse_obj(user_info
, ('user', 'id'))
161 return self
.playlist_result(
163 functools
.partial(self
._entries
, playlist_id
, user_id
),
165 playlist_id
, traverse_obj(user_info
, ('user', 'name')))
168 class IwaraPlaylistIE(InfoExtractor
):
169 # the ID is an UUID but I don't think it's necessary to write concrete regex
170 _VALID_URL
= r
'https?://(?:www\.)?iwara\.tv/playlist/(?P<id>[0-9a-f-]+)'
171 IE_NAME
= 'iwara:playlist'
175 'url': 'https://iwara.tv/playlist/458e5486-36a4-4ac0-b233-7e9eef01025f',
177 'id': '458e5486-36a4-4ac0-b233-7e9eef01025f',
179 'playlist_mincount': 3,
182 def _entries(self
, playlist_id
, first_page
, page
):
183 videos
= self
._download
_json
(
184 'https://api.iwara.tv/videos', playlist_id
, f
'Downloading page {page}',
185 query
={'page': page, 'limit': self._PER_PAGE}
) if page
else first_page
186 for x
in traverse_obj(videos
, ('results', ..., 'id')):
187 yield self
.url_result(f
'https://iwara.tv/video/{x}')
189 def _real_extract(self
, url
):
190 playlist_id
= self
._match
_id
(url
)
191 page_0
= self
._download
_json
(
192 f
'https://api.iwara.tv/playlist/{playlist_id}?page=0&limit={self._PER_PAGE}', playlist_id
,
193 note
='Requesting playlist info')
195 return self
.playlist_result(
197 functools
.partial(self
._entries
, playlist_id
, page_0
),
199 playlist_id
, traverse_obj(page_0
, ('title', 'name')))