]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/vvvvid.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from .youtube
import YoutubeIE
15 class VVVVIDIE(InfoExtractor
):
16 _VALID_URL_BASE
= r
'https?://(?:www\.)?vvvvid\.it/(?:#!)?(?:show|anime|film|series)/'
17 _VALID_URL
= r
'%s(?P<show_id>\d+)/[^/]+/(?P<season_id>\d+)/(?P<id>[0-9]+)' % _VALID_URL_BASE
19 # video_type == 'video/vvvvid'
20 'url': 'https://www.vvvvid.it/#!show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048/ping-pong',
21 'md5': 'b8d3cecc2e981adc3835adf07f6df91b',
27 'series': '"Perché dovrei guardarlo?" di Dario Moccia',
29 'episode': 'Ping Pong',
37 'skip_download': True,
40 # video_type == 'video/rcs'
41 'url': 'https://www.vvvvid.it/#!show/376/death-note-live-action/377/482493/episodio-01',
42 'md5': '33e0edfba720ad73a8782157fdebc648',
46 'title': 'Episodio 01',
49 'skip_download': True,
52 # video_type == 'video/youtube'
53 'url': 'https://www.vvvvid.it/show/404/one-punch-man/406/486683/trailer',
54 'md5': '33e0edfba720ad73a8782157fdebc648',
59 'upload_date': '20150906',
60 'description': 'md5:a5e802558d35247fee285875328c0b80',
61 'uploader_id': 'BandaiVisual',
62 'uploader': 'BANDAI NAMCO Arts Channel',
65 'skip_download': True,
68 'url': 'https://www.vvvvid.it/show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048',
73 def _real_initialize(self
):
74 self
._conn
_id
= self
._download
_json
(
75 'https://www.vvvvid.it/user/login',
76 None, headers
=self
.geo_verification_headers())['data']['conn_id']
78 def _download_info(self
, show_id
, path
, video_id
, fatal
=True, query
=None):
80 'conn_id': self
._conn
_id
,
84 response
= self
._download
_json
(
85 'https://www.vvvvid.it/vvvvid/ondemand/%s/%s' % (show_id
, path
),
86 video_id
, headers
=self
.geo_verification_headers(), query
=q
, fatal
=fatal
)
87 if not (response
or fatal
):
89 if response
.get('result') == 'error':
90 raise ExtractorError('%s said: %s' % (
91 self
.IE_NAME
, response
['message']), expected
=True)
92 return response
['data']
94 def _extract_common_video_info(self
, video_data
):
96 'thumbnail': video_data
.get('thumbnail'),
97 'episode_id': str_or_none(video_data
.get('id')),
100 def _real_extract(self
, url
):
101 show_id
, season_id
, video_id
= self
._match
_valid
_url
(url
).groups()
103 response
= self
._download
_info
(
104 show_id
, 'season/%s' % season_id
,
105 video_id
, query
={'video_id': video_id}
)
108 video_data
= list(filter(
109 lambda episode
: episode
.get('video_id') == vid
, response
))[0]
110 title
= video_data
['title']
113 # vvvvid embed_info decryption algorithm is reverse engineered from function $ds(h) at vvvvid.js
115 g
= "MNOPIJKL89+/4567UVWXQRSTEFGHABCDcdefYZabstuvopqr0123wxyzklmnghij"
122 while ((not b
) and o
< m_len
):
131 k
= (m
[o
- 1] << 4) & 255
135 j
= (m
[o
- 1] << 6) & 255
156 for e
in range(c_len
* 2 - 1, -1, -1):
157 a
= c
[e
% c_len
] ^ c
[(e
+ 1) % c_len
]
169 def metadata_from_url(r_url
):
170 if not info
and r_url
:
171 mobj
= re
.search(r
'_(?:S(\d+))?Ep(\d+)', r_url
)
173 info
['episode_number'] = int(mobj
.group(2))
174 season_number
= mobj
.group(1)
176 info
['season_number'] = int(season_number
)
178 video_type
= video_data
.get('video_type')
180 for quality
in ('', '_sd'):
181 embed_code
= video_data
.get('embed_info' + quality
)
184 embed_code
= ds(embed_code
)
185 if video_type
== 'video/kenc':
186 embed_code
= re
.sub(r
'https?(://[^/]+)/z/', r
'https\1/i/', embed_code
).replace('/manifest.f4m', '/master.m3u8')
187 kenc
= self
._download
_json
(
188 'https://www.vvvvid.it/kenc', video_id
, query
={
190 'conn_id': self
._conn
_id
,
192 }, fatal
=False) or {}
193 kenc_message
= kenc
.get('message')
195 embed_code
+= '?' + ds(kenc_message
)
196 formats
.extend(self
._extract
_m
3u8_formats
(
197 embed_code
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False))
198 elif video_type
== 'video/rcs':
199 formats
.extend(self
._extract
_akamai
_formats
(embed_code
, video_id
))
200 elif video_type
== 'video/youtube':
202 '_type': 'url_transparent',
203 'ie_key': YoutubeIE
.ie_key(),
209 formats
.extend(self
._extract
_wowza
_formats
(
210 'http://sb.top-ix.org/videomg/_definst_/mp4:%s/playlist.m3u8' % embed_code
, video_id
))
211 metadata_from_url(embed_code
)
214 self
._sort
_formats
(formats
)
215 info
['formats'] = formats
217 metadata_from_url(video_data
.get('thumbnail'))
218 info
.update(self
._extract
_common
_video
_info
(video_data
))
222 'duration': int_or_none(video_data
.get('length')),
223 'series': video_data
.get('show_title'),
224 'season_id': season_id
,
226 'view_count': int_or_none(video_data
.get('views')),
227 'like_count': int_or_none(video_data
.get('video_likes')),
228 'repost_count': int_or_none(video_data
.get('video_shares')),
233 class VVVVIDShowIE(VVVVIDIE
):
234 _VALID_URL
= r
'(?P<base_url>%s(?P<id>\d+)(?:/(?P<show_title>[^/?&#]+))?)/?(?:[?#&]|$)' % VVVVIDIE
._VALID
_URL
_BASE
236 'url': 'https://www.vvvvid.it/show/156/psyco-pass',
239 'title': 'Psycho-Pass',
240 'description': 'md5:94d572c0bd85894b193b8aebc9a3a806',
242 'playlist_count': 46,
244 'url': 'https://www.vvvvid.it/show/156',
245 'only_matching': True,
248 def _real_extract(self
, url
):
249 base_url
, show_id
, show_title
= self
._match
_valid
_url
(url
).groups()
251 seasons
= self
._download
_info
(
252 show_id
, 'seasons/', show_title
)
254 show_info
= self
._download
_info
(
255 show_id
, 'info/', show_title
, fatal
=False)
261 for season
in (seasons
or []):
262 episodes
= season
.get('episodes') or []
263 playlist_title
= season
.get('name') or show_info
.get('title')
264 for episode
in episodes
:
265 if episode
.get('playable') is False:
267 season_id
= str_or_none(episode
.get('season_id'))
268 video_id
= str_or_none(episode
.get('video_id'))
269 if not (season_id
and video_id
):
271 info
= self
._extract
_common
_video
_info
(episode
)
273 '_type': 'url_transparent',
274 'ie_key': VVVVIDIE
.ie_key(),
275 'url': '/'.join([base_url
, season_id
, video_id
]),
276 'title': episode
.get('title'),
277 'description': episode
.get('description'),
278 'season_id': season_id
,
279 'playlist_title': playlist_title
,
283 return self
.playlist_result(
284 entries
, show_id
, show_info
.get('title'), show_info
.get('description'))