2 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
16 class TVerIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?tver\.jp/(?P<path>corner|episode|feature|lp|tokyo2020/video)/(?P<id>[fc]?\d+)'
18 # videos are only available for 7 days
20 'url': 'https://tver.jp/corner/f0062178',
21 'only_matching': True,
23 'url': 'https://tver.jp/feature/f0062413',
24 'only_matching': True,
26 'url': 'https://tver.jp/episode/79622438',
27 'only_matching': True,
30 'url': 'https://tver.jp/corner/f0068870',
31 'only_matching': True,
33 'url': 'https://tver.jp/lp/f0009694',
34 'only_matching': True,
36 'url': 'https://tver.jp/lp/c0000239',
37 'only_matching': True,
39 'url': 'https://tver.jp/tokyo2020/video/6264525510001',
40 'only_matching': True,
43 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
45 def _real_initialize(self
):
46 self
._TOKEN
= self
._download
_json
(
47 'https://tver.jp/api/access_token.php', None)['token']
49 def _real_extract(self
, url
):
50 path
, video_id
= self
._match
_valid
_url
(url
).groups()
52 webpage
= self
._download
_webpage
(url
, video_id
)
53 redirect_path
= self
._search
_regex
(r
'to_href="([^"]+)', webpage
, 'redirect path')
54 path
, video_id
= self
._match
_valid
_url
(f
'https://tver.jp{redirect_path}').groups()
55 api_response
= self
._download
_json
(f
'https://api.tver.jp/v4/{path}/{video_id}', video_id
, query
={'token': self._TOKEN}
)
56 p_id
= traverse_obj(api_response
, ('main', 'publisher_id'))
58 error_msg
, expected
= traverse_obj(api_response
, ('episode', 0, 'textbar', 0, ('text', 'longer')), get_all
=False), True
60 error_msg
, expected
= 'Failed to extract publisher ID', False
61 raise ExtractorError(error_msg
, expected
=expected
)
62 service
= remove_start(traverse_obj(api_response
, ('main', 'service')), 'ts_')
64 r_id
= traverse_obj(api_response
, ('main', 'reference_id'))
65 if service
not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
68 self
.BRIGHTCOVE_URL_TEMPLATE
% (p_id
, r_id
),
69 {'geo_countries': ['JP']}
)
72 '_type': 'url_transparent',
73 'description': traverse_obj(api_response
, ('main', 'note', 0, 'text'), expected_type
=compat_str
),
74 'episode_number': int_or_none(traverse_obj(api_response
, ('main', 'ext', 'episode_number'), expected_type
=compat_str
)),
76 'ie_key': 'BrightcoveNew',