2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
13 class TVerIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?tver\.jp/(?:(?P<type>lp|corner|series|episodes?|feature|tokyo2020/video)/)+(?P<id>[a-zA-Z0-9]+)'
16 'skip': 'videos are only available for 7 days',
17 'url': 'https://tver.jp/episodes/ephss8yveb',
19 'title': '#44 料理と値段と店主にびっくり オモてなしすぎウマい店 2時間SP',
20 'description': 'md5:66985373a66fed8ad3cd595a3cfebb13',
22 'add_ie': ['BrightcoveNew'],
24 'skip': 'videos are only available for 7 days',
25 'url': 'https://tver.jp/lp/episodes/ep6f16g26p',
27 # sorry but this is "correct"
28 'title': '4月11日(月)23時06分 ~ 放送予定',
29 'description': 'md5:4029cc5f4b1e8090dfc5b7bd2bc5cd0b',
31 'add_ie': ['BrightcoveNew'],
33 'url': 'https://tver.jp/corner/f0103888',
34 'only_matching': True,
36 'url': 'https://tver.jp/lp/f0033031',
37 'only_matching': True,
39 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
41 _PLATFORM_TOKEN
= None
43 def _real_initialize(self
):
44 create_response
= self
._download
_json
(
45 'https://platform-api.tver.jp/v2/api/platform_users/browser/create', None,
46 note
='Creating session', data
=b
'device_type=pc', headers
={
47 'Origin': 'https://s.tver.jp',
48 'Referer': 'https://s.tver.jp/',
49 'Content-Type': 'application/x-www-form-urlencoded',
51 self
._PLATFORM
_UID
= traverse_obj(create_response
, ('result', 'platform_uid'))
52 self
._PLATFORM
_TOKEN
= traverse_obj(create_response
, ('result', 'platform_token'))
54 def _real_extract(self
, url
):
55 video_id
, video_type
= self
._match
_valid
_url
(url
).group('id', 'type')
56 if video_type
not in {'series', 'episodes'}
:
57 webpage
= self
._download
_webpage
(url
, video_id
, note
='Resolving to new URL')
58 video_id
= self
._match
_id
(self
._search
_regex
(
59 (r
'canonical"\s*href="(https?://tver\.jp/[^"]+)"', r
'&link=(https?://tver\.jp/[^?&]+)[?&]'),
60 webpage
, 'url regex'))
61 video_info
= self
._download
_json
(
62 f
'https://statics.tver.jp/content/episode/{video_id}.json', video_id
,
63 query
={'v': '5'}
, headers
={
64 'Origin': 'https://tver.jp',
65 'Referer': 'https://tver.jp/',
67 p_id
= video_info
['video']['accountID']
68 r_id
= traverse_obj(video_info
, ('video', ('videoRefID', 'videoID')), get_all
=False)
70 raise ExtractorError('Failed to extract reference ID for Brightcove')
71 if not r_id
.isdigit():
74 additional_info
= self
._download
_json
(
75 f
'https://platform-api.tver.jp/service/api/v1/callEpisode/{video_id}?require_data=mylist,later[epefy106ur],good[epefy106ur],resume[epefy106ur]',
76 video_id
, fatal
=False,
78 'platform_uid': self
._PLATFORM
_UID
,
79 'platform_token': self
._PLATFORM
_TOKEN
,
81 'x-tver-platform-type': 'web'
85 '_type': 'url_transparent',
86 'title': str_or_none(video_info
.get('title')),
87 'description': str_or_none(video_info
.get('description')),
89 self
.BRIGHTCOVE_URL_TEMPLATE
% (p_id
, r_id
), {'geo_countries': ['JP']}
),
90 'series': traverse_obj(
91 additional_info
, ('result', ('episode', 'series'), 'content', ('seriesTitle', 'title')),
93 'ie_key': 'BrightcoveNew',