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)/(?P<id>f?\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,
34 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
36 def _real_initialize(self
):
37 self
._TOKEN
= self
._download
_json
(
38 'https://tver.jp/api/access_token.php', None)['token']
40 def _real_extract(self
, url
):
41 path
, video_id
= self
._match
_valid
_url
(url
).groups()
42 api_response
= self
._download
_json
(
43 'https://api.tver.jp/v4/' + path
, video_id
,
44 query
={'token': self._TOKEN}
)
45 p_id
= traverse_obj(api_response
, ('main', 'publisher_id'))
47 error_msg
, expected
= traverse_obj(api_response
, ('episode', 0, 'textbar', 0, ('text', 'longer')), get_all
=False), True
49 error_msg
, expected
= 'Failed to extract publisher ID', False
50 raise ExtractorError(error_msg
, expected
=expected
)
51 service
= remove_start(traverse_obj(api_response
, ('main', 'service')), 'ts_')
53 r_id
= traverse_obj(api_response
, ('main', 'reference_id'))
54 if service
not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
57 self
.BRIGHTCOVE_URL_TEMPLATE
% (p_id
, r_id
),
58 {'geo_countries': ['JP']}
)
61 '_type': 'url_transparent',
62 'description': traverse_obj(api_response
, ('main', 'note', 0, 'text'), expected_type
=compat_str
),
63 'episode_number': int_or_none(traverse_obj(api_response
, ('main', 'ext', 'episode_number'), expected_type
=compat_str
)),
65 'ie_key': 'BrightcoveNew',