2021-01-01 07:26:37 -05:00
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
from ..utils import (
|
2022-01-19 08:47:07 -05:00
|
|
|
|
ExtractorError,
|
2021-01-01 07:26:37 -05:00
|
|
|
|
smuggle_url,
|
2022-04-07 03:19:36 -04:00
|
|
|
|
str_or_none,
|
2022-01-19 08:47:07 -05:00
|
|
|
|
traverse_obj,
|
2021-01-01 07:26:37 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TVerIE(InfoExtractor):
|
2022-04-07 03:19:36 -04:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?tver\.jp/(?:(?P<type>lp|corner|series|episodes?|feature|tokyo2020/video)/)+(?P<id>[a-zA-Z0-9]+)'
|
2021-01-01 07:26:37 -05:00
|
|
|
|
_TESTS = [{
|
2022-04-07 03:19:36 -04:00
|
|
|
|
'skip': 'videos are only available for 7 days',
|
|
|
|
|
'url': 'https://tver.jp/episodes/ephss8yveb',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'title': '#44 料理と値段と店主にびっくり オモてなしすぎウマい店 2時間SP',
|
|
|
|
|
'description': 'md5:66985373a66fed8ad3cd595a3cfebb13',
|
|
|
|
|
},
|
|
|
|
|
'add_ie': ['BrightcoveNew'],
|
2021-01-01 07:26:37 -05:00
|
|
|
|
}, {
|
2022-04-07 03:19:36 -04:00
|
|
|
|
'skip': 'videos are only available for 7 days',
|
|
|
|
|
'url': 'https://tver.jp/lp/episodes/ep6f16g26p',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
# sorry but this is "correct"
|
|
|
|
|
'title': '4月11日(月)23時06分 ~ 放送予定',
|
|
|
|
|
'description': 'md5:4029cc5f4b1e8090dfc5b7bd2bc5cd0b',
|
|
|
|
|
},
|
|
|
|
|
'add_ie': ['BrightcoveNew'],
|
2022-03-23 21:11:13 -04:00
|
|
|
|
}, {
|
2022-04-07 03:19:36 -04:00
|
|
|
|
'url': 'https://tver.jp/corner/f0103888',
|
2022-03-23 21:11:13 -04:00
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
2022-04-07 03:19:36 -04:00
|
|
|
|
'url': 'https://tver.jp/lp/f0033031',
|
2022-03-23 21:11:13 -04:00
|
|
|
|
'only_matching': True,
|
2021-01-01 07:26:37 -05:00
|
|
|
|
}]
|
|
|
|
|
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
|
2022-04-07 03:19:36 -04:00
|
|
|
|
_PLATFORM_UID = None
|
|
|
|
|
_PLATFORM_TOKEN = None
|
2021-01-01 07:26:37 -05:00
|
|
|
|
|
|
|
|
|
def _real_initialize(self):
|
2022-04-07 03:19:36 -04:00
|
|
|
|
create_response = self._download_json(
|
|
|
|
|
'https://platform-api.tver.jp/v2/api/platform_users/browser/create', None,
|
|
|
|
|
note='Creating session', data=b'device_type=pc', headers={
|
|
|
|
|
'Origin': 'https://s.tver.jp',
|
|
|
|
|
'Referer': 'https://s.tver.jp/',
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
|
})
|
|
|
|
|
self._PLATFORM_UID = traverse_obj(create_response, ('result', 'platform_uid'))
|
|
|
|
|
self._PLATFORM_TOKEN = traverse_obj(create_response, ('result', 'platform_token'))
|
2021-01-01 07:26:37 -05:00
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2022-04-07 03:19:36 -04:00
|
|
|
|
video_id, video_type = self._match_valid_url(url).group('id', 'type')
|
|
|
|
|
if video_type not in {'series', 'episodes'}:
|
|
|
|
|
webpage = self._download_webpage(url, video_id, note='Resolving to new URL')
|
|
|
|
|
video_id = self._match_id(self._search_regex(
|
|
|
|
|
(r'canonical"\s*href="(https?://tver\.jp/[^"]+)"', r'&link=(https?://tver\.jp/[^?&]+)[?&]'),
|
|
|
|
|
webpage, 'url regex'))
|
|
|
|
|
video_info = self._download_json(
|
|
|
|
|
f'https://statics.tver.jp/content/episode/{video_id}.json', video_id,
|
|
|
|
|
query={'v': '5'}, headers={
|
|
|
|
|
'Origin': 'https://tver.jp',
|
|
|
|
|
'Referer': 'https://tver.jp/',
|
|
|
|
|
})
|
|
|
|
|
p_id = video_info['video']['accountID']
|
|
|
|
|
r_id = traverse_obj(video_info, ('video', ('videoRefID', 'videoID')), get_all=False)
|
|
|
|
|
if not r_id:
|
|
|
|
|
raise ExtractorError('Failed to extract reference ID for Brightcove')
|
|
|
|
|
if not r_id.isdigit():
|
|
|
|
|
r_id = f'ref:{r_id}'
|
2021-05-06 12:01:20 -04:00
|
|
|
|
|
2022-04-07 03:19:36 -04:00
|
|
|
|
additional_info = self._download_json(
|
|
|
|
|
f'https://platform-api.tver.jp/service/api/v1/callEpisode/{video_id}?require_data=mylist,later[epefy106ur],good[epefy106ur],resume[epefy106ur]',
|
|
|
|
|
video_id, fatal=False,
|
|
|
|
|
query={
|
|
|
|
|
'platform_uid': self._PLATFORM_UID,
|
|
|
|
|
'platform_token': self._PLATFORM_TOKEN,
|
|
|
|
|
}, headers={
|
|
|
|
|
'x-tver-platform-type': 'web'
|
|
|
|
|
})
|
2021-05-06 12:01:20 -04:00
|
|
|
|
|
|
|
|
|
return {
|
2021-01-01 07:26:37 -05:00
|
|
|
|
'_type': 'url_transparent',
|
2022-04-07 03:19:36 -04:00
|
|
|
|
'title': str_or_none(video_info.get('title')),
|
|
|
|
|
'description': str_or_none(video_info.get('description')),
|
|
|
|
|
'url': smuggle_url(
|
|
|
|
|
self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id), {'geo_countries': ['JP']}),
|
|
|
|
|
'series': traverse_obj(
|
|
|
|
|
additional_info, ('result', ('episode', 'series'), 'content', ('seriesTitle', 'title')),
|
|
|
|
|
get_all=False),
|
2021-05-06 12:01:20 -04:00
|
|
|
|
'ie_key': 'BrightcoveNew',
|
2021-01-01 07:26:37 -05:00
|
|
|
|
}
|