2016-12-16 08:05:02 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
int_or_none,
|
|
|
|
str_or_none,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class VVVVIDIE(InfoExtractor):
|
2020-12-30 17:12:17 +00:00
|
|
|
_VALID_URL_BASE = r'https?://(?:www\.)?vvvvid\.it/(?:#!)?(?:show|anime|film|series)/'
|
|
|
|
_VALID_URL = r'%s(?P<show_id>\d+)/[^/]+/(?P<season_id>\d+)/(?P<id>[0-9]+)' % _VALID_URL_BASE
|
2016-12-16 08:05:02 +00:00
|
|
|
_TESTS = [{
|
|
|
|
# video_type == 'video/vvvvid'
|
|
|
|
'url': 'https://www.vvvvid.it/#!show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048/ping-pong',
|
|
|
|
'md5': 'b8d3cecc2e981adc3835adf07f6df91b',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '489048',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Ping Pong',
|
2020-12-30 17:16:47 +00:00
|
|
|
'duration': 239,
|
|
|
|
'series': '"Perché dovrei guardarlo?" di Dario Moccia',
|
|
|
|
'season_id': '437',
|
|
|
|
'season_number': 1,
|
|
|
|
'episode': 'Ping Pong',
|
|
|
|
'episode_number': 1,
|
|
|
|
'episode_id': '3334',
|
|
|
|
'view_count': int,
|
|
|
|
'like_count': int,
|
|
|
|
'repost_count': int,
|
2016-12-16 08:05:02 +00:00
|
|
|
},
|
2017-11-29 15:09:45 +00:00
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
2016-12-16 08:05:02 +00:00
|
|
|
}, {
|
|
|
|
# video_type == 'video/rcs'
|
|
|
|
'url': 'https://www.vvvvid.it/#!show/376/death-note-live-action/377/482493/episodio-01',
|
|
|
|
'md5': '33e0edfba720ad73a8782157fdebc648',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '482493',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Episodio 01',
|
|
|
|
},
|
2017-11-29 15:09:45 +00:00
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
2020-12-30 17:16:47 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.vvvvid.it/show/434/perche-dovrei-guardarlo-di-dario-moccia/437/489048',
|
|
|
|
'only_matching': True
|
2016-12-16 08:05:02 +00:00
|
|
|
}]
|
|
|
|
_conn_id = None
|
|
|
|
|
|
|
|
def _real_initialize(self):
|
2016-12-16 10:04:58 +00:00
|
|
|
self._conn_id = self._download_json(
|
|
|
|
'https://www.vvvvid.it/user/login',
|
|
|
|
None, headers=self.geo_verification_headers())['data']['conn_id']
|
2016-12-16 08:05:02 +00:00
|
|
|
|
2020-12-30 17:12:17 +00:00
|
|
|
def _download_info(self, show_id, path, video_id, fatal=True):
|
2016-12-16 08:05:02 +00:00
|
|
|
response = self._download_json(
|
2020-12-30 17:16:47 +00:00
|
|
|
'https://www.vvvvid.it/vvvvid/ondemand/%s/%s' % (show_id, path),
|
2016-12-16 08:05:02 +00:00
|
|
|
video_id, headers=self.geo_verification_headers(), query={
|
|
|
|
'conn_id': self._conn_id,
|
2020-12-30 17:12:17 +00:00
|
|
|
}, fatal=fatal)
|
2020-12-30 17:16:47 +00:00
|
|
|
if not (response or fatal):
|
|
|
|
return
|
|
|
|
if response.get('result') == 'error':
|
2016-12-16 08:05:02 +00:00
|
|
|
raise ExtractorError('%s said: %s' % (
|
|
|
|
self.IE_NAME, response['message']), expected=True)
|
2020-12-30 17:12:17 +00:00
|
|
|
return response['data']
|
|
|
|
|
2020-12-30 17:16:47 +00:00
|
|
|
def _extract_common_video_info(self, video_data):
|
|
|
|
return {
|
|
|
|
'thumbnail': video_data.get('thumbnail'),
|
|
|
|
'episode_number': int_or_none(video_data.get('number')),
|
|
|
|
'episode_id': str_or_none(video_data.get('id')),
|
|
|
|
}
|
|
|
|
|
2020-12-30 17:12:17 +00:00
|
|
|
def _real_extract(self, url):
|
|
|
|
show_id, season_id, video_id = re.match(self._VALID_URL, url).groups()
|
|
|
|
|
|
|
|
response = self._download_info(
|
2020-12-30 17:16:47 +00:00
|
|
|
show_id, 'season/%s' % season_id, video_id)
|
2016-12-16 08:05:02 +00:00
|
|
|
|
|
|
|
vid = int(video_id)
|
|
|
|
video_data = list(filter(
|
2020-12-30 17:12:17 +00:00
|
|
|
lambda episode: episode.get('video_id') == vid, response))[0]
|
2020-12-30 17:16:47 +00:00
|
|
|
title = video_data['title']
|
2016-12-16 08:05:02 +00:00
|
|
|
formats = []
|
|
|
|
|
|
|
|
# vvvvid embed_info decryption algorithm is reverse engineered from function $ds(h) at vvvvid.js
|
|
|
|
def ds(h):
|
|
|
|
g = "MNOPIJKL89+/4567UVWXQRSTEFGHABCDcdefYZabstuvopqr0123wxyzklmnghij"
|
|
|
|
|
|
|
|
def f(m):
|
|
|
|
l = []
|
|
|
|
o = 0
|
|
|
|
b = False
|
|
|
|
m_len = len(m)
|
|
|
|
while ((not b) and o < m_len):
|
|
|
|
n = m[o] << 2
|
|
|
|
o += 1
|
|
|
|
k = -1
|
|
|
|
j = -1
|
|
|
|
if o < m_len:
|
|
|
|
n += m[o] >> 4
|
|
|
|
o += 1
|
|
|
|
if o < m_len:
|
|
|
|
k = (m[o - 1] << 4) & 255
|
|
|
|
k += m[o] >> 2
|
|
|
|
o += 1
|
|
|
|
if o < m_len:
|
|
|
|
j = (m[o - 1] << 6) & 255
|
|
|
|
j += m[o]
|
|
|
|
o += 1
|
|
|
|
else:
|
|
|
|
b = True
|
|
|
|
else:
|
|
|
|
b = True
|
|
|
|
else:
|
|
|
|
b = True
|
|
|
|
l.append(n)
|
|
|
|
if k != -1:
|
|
|
|
l.append(k)
|
|
|
|
if j != -1:
|
|
|
|
l.append(j)
|
|
|
|
return l
|
|
|
|
|
|
|
|
c = []
|
|
|
|
for e in h:
|
|
|
|
c.append(g.index(e))
|
|
|
|
|
|
|
|
c_len = len(c)
|
|
|
|
for e in range(c_len * 2 - 1, -1, -1):
|
|
|
|
a = c[e % c_len] ^ c[(e + 1) % c_len]
|
|
|
|
c[e % c_len] = a
|
|
|
|
|
|
|
|
c = f(c)
|
|
|
|
d = ''
|
|
|
|
for e in c:
|
|
|
|
d += chr(e)
|
|
|
|
|
|
|
|
return d
|
|
|
|
|
|
|
|
for quality in ('_sd', ''):
|
|
|
|
embed_code = video_data.get('embed_info' + quality)
|
|
|
|
if not embed_code:
|
|
|
|
continue
|
|
|
|
embed_code = ds(embed_code)
|
|
|
|
video_type = video_data.get('video_type')
|
|
|
|
if video_type in ('video/rcs', 'video/kenc'):
|
2017-11-29 15:09:45 +00:00
|
|
|
if video_type == 'video/kenc':
|
|
|
|
kenc = self._download_json(
|
|
|
|
'https://www.vvvvid.it/kenc', video_id, query={
|
|
|
|
'action': 'kt',
|
|
|
|
'conn_id': self._conn_id,
|
|
|
|
'url': embed_code,
|
|
|
|
}, fatal=False) or {}
|
|
|
|
kenc_message = kenc.get('message')
|
|
|
|
if kenc_message:
|
|
|
|
embed_code += '?' + ds(kenc_message)
|
2020-12-31 11:04:35 +00:00
|
|
|
formats.extend(self._extract_akamai_formats(embed_code, video_id))
|
2016-12-16 08:05:02 +00:00
|
|
|
else:
|
|
|
|
formats.extend(self._extract_wowza_formats(
|
|
|
|
'http://sb.top-ix.org/videomg/_definst_/mp4:%s/playlist.m3u8' % embed_code, video_id))
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2020-12-30 17:16:47 +00:00
|
|
|
info = self._extract_common_video_info(video_data)
|
|
|
|
info.update({
|
2016-12-16 08:05:02 +00:00
|
|
|
'id': video_id,
|
2020-12-30 17:16:47 +00:00
|
|
|
'title': title,
|
2016-12-16 08:05:02 +00:00
|
|
|
'formats': formats,
|
|
|
|
'duration': int_or_none(video_data.get('length')),
|
|
|
|
'series': video_data.get('show_title'),
|
|
|
|
'season_id': season_id,
|
|
|
|
'season_number': video_data.get('season_number'),
|
2020-12-30 17:16:47 +00:00
|
|
|
'episode': title,
|
2016-12-16 08:05:02 +00:00
|
|
|
'view_count': int_or_none(video_data.get('views')),
|
|
|
|
'like_count': int_or_none(video_data.get('video_likes')),
|
2020-12-30 17:16:47 +00:00
|
|
|
'repost_count': int_or_none(video_data.get('video_shares')),
|
|
|
|
})
|
|
|
|
return info
|
2020-12-30 17:12:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VVVVIDShowIE(VVVVIDIE):
|
2020-12-30 17:16:47 +00:00
|
|
|
_VALID_URL = r'(?P<base_url>%s(?P<id>\d+)(?:/(?P<show_title>[^/?&#]+))?)/?(?:[?#&]|$)' % VVVVIDIE._VALID_URL_BASE
|
2020-12-30 17:12:17 +00:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.vvvvid.it/show/156/psyco-pass',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '156',
|
|
|
|
'title': 'Psycho-Pass',
|
|
|
|
'description': 'md5:94d572c0bd85894b193b8aebc9a3a806',
|
|
|
|
},
|
|
|
|
'playlist_count': 46,
|
2020-12-30 17:16:47 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.vvvvid.it/show/156',
|
|
|
|
'only_matching': True,
|
2020-12-30 17:12:17 +00:00
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
base_url, show_id, show_title = re.match(self._VALID_URL, url).groups()
|
|
|
|
|
2020-12-30 17:16:47 +00:00
|
|
|
seasons = self._download_info(
|
|
|
|
show_id, 'seasons/', show_title)
|
2020-12-30 17:12:17 +00:00
|
|
|
|
2020-12-30 17:16:47 +00:00
|
|
|
show_info = self._download_info(
|
|
|
|
show_id, 'info/', show_title, fatal=False)
|
2020-12-30 17:12:17 +00:00
|
|
|
|
|
|
|
entries = []
|
2020-12-30 17:16:47 +00:00
|
|
|
for season in (seasons or []):
|
|
|
|
season_number = int_or_none(season.get('number'))
|
2020-12-30 17:12:17 +00:00
|
|
|
episodes = season.get('episodes') or []
|
|
|
|
for episode in episodes:
|
2020-12-31 11:04:35 +00:00
|
|
|
if episode.get('playable') is False:
|
|
|
|
continue
|
2020-12-30 17:12:17 +00:00
|
|
|
season_id = str_or_none(episode.get('season_id'))
|
|
|
|
video_id = str_or_none(episode.get('video_id'))
|
|
|
|
if not (season_id and video_id):
|
|
|
|
continue
|
2020-12-30 17:16:47 +00:00
|
|
|
info = self._extract_common_video_info(episode)
|
|
|
|
info.update({
|
|
|
|
'_type': 'url',
|
2020-12-30 17:12:17 +00:00
|
|
|
'ie_key': VVVVIDIE.ie_key(),
|
2020-12-30 17:16:47 +00:00
|
|
|
'url': '/'.join([base_url, season_id, video_id]),
|
2020-12-30 17:12:17 +00:00
|
|
|
'title': episode.get('title'),
|
|
|
|
'description': episode.get('description'),
|
2020-12-30 17:16:47 +00:00
|
|
|
'season_number': season_number,
|
|
|
|
'season_id': season_id,
|
2020-12-30 17:12:17 +00:00
|
|
|
})
|
2020-12-30 17:16:47 +00:00
|
|
|
entries.append(info)
|
|
|
|
|
2020-12-30 17:12:17 +00:00
|
|
|
return self.playlist_result(
|
2020-12-30 17:16:47 +00:00
|
|
|
entries, show_id, show_info.get('title'), show_info.get('description'))
|