1 from .common
import InfoExtractor
12 class TVerIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:www\.)?tver\.jp/(?:(?P<type>lp|corner|series|episodes?|feature|tokyo2020/video)/)+(?P<id>[a-zA-Z0-9]+)'
15 'skip': 'videos are only available for 7 days',
16 'url': 'https://tver.jp/episodes/ep83nf3w4p',
18 'title': '家事ヤロウ!!! 売り場席巻のチーズSP&財前直見×森泉親子の脱東京暮らし密着!',
19 'description': 'md5:dc2c06b6acc23f1e7c730c513737719b',
21 'episode': '売り場席巻のチーズSP&財前直見×森泉親子の脱東京暮らし密着!',
22 'alt_title': '売り場席巻のチーズSP&財前直見×森泉親子の脱東京暮らし密着!',
24 'onair_label': '5月3日(火)放送分',
25 'ext_title': '家事ヤロウ!!! 売り場席巻のチーズSP&財前直見×森泉親子の脱東京暮らし密着! テレビ朝日 5月3日(火)放送分',
27 'add_ie': ['BrightcoveNew'],
29 'url': 'https://tver.jp/corner/f0103888',
30 'only_matching': True,
32 'url': 'https://tver.jp/lp/f0033031',
33 'only_matching': True,
35 BRIGHTCOVE_URL_TEMPLATE
= 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
37 _PLATFORM_TOKEN
= None
39 def _real_initialize(self
):
40 create_response
= self
._download
_json
(
41 'https://platform-api.tver.jp/v2/api/platform_users/browser/create', None,
42 note
='Creating session', data
=b
'device_type=pc', headers
={
43 'Origin': 'https://s.tver.jp',
44 'Referer': 'https://s.tver.jp/',
45 'Content-Type': 'application/x-www-form-urlencoded',
47 self
._PLATFORM
_UID
= traverse_obj(create_response
, ('result', 'platform_uid'))
48 self
._PLATFORM
_TOKEN
= traverse_obj(create_response
, ('result', 'platform_token'))
50 def _real_extract(self
, url
):
51 video_id
, video_type
= self
._match
_valid
_url
(url
).group('id', 'type')
52 if video_type
not in {'series', 'episodes'}
:
53 webpage
= self
._download
_webpage
(url
, video_id
, note
='Resolving to new URL')
54 video_id
= self
._match
_id
(self
._search
_regex
(
55 (r
'canonical"\s*href="(https?://tver\.jp/[^"]+)"', r
'&link=(https?://tver\.jp/[^?&]+)[?&]'),
56 webpage
, 'url regex'))
58 episode_info
= self
._download
_json
(
59 f
'https://platform-api.tver.jp/service/api/v1/callEpisode/{video_id}?require_data=mylist,later[epefy106ur],good[epefy106ur],resume[epefy106ur]',
60 video_id
, fatal
=False,
62 'platform_uid': self
._PLATFORM
_UID
,
63 'platform_token': self
._PLATFORM
_TOKEN
,
65 'x-tver-platform-type': 'web'
67 episode_content
= traverse_obj(
68 episode_info
, ('result', 'episode', 'content')) or {}
70 video_info
= self
._download
_json
(
71 f
'https://statics.tver.jp/content/episode/{video_id}.json', video_id
,
73 'v': str_or_none(episode_content
.get('version')) or '5',
75 'Origin': 'https://tver.jp',
76 'Referer': 'https://tver.jp/',
78 p_id
= video_info
['video']['accountID']
79 r_id
= traverse_obj(video_info
, ('video', ('videoRefID', 'videoID')), get_all
=False)
81 raise ExtractorError('Failed to extract reference ID for Brightcove')
82 if not r_id
.isdigit():
85 episode
= strip_or_none(episode_content
.get('title'))
86 series
= str_or_none(episode_content
.get('seriesTitle'))
88 join_nonempty(series
, episode
, delim
=' ')
89 or str_or_none(video_info
.get('title')))
90 provider
= str_or_none(episode_content
.get('productionProviderName'))
91 onair_label
= str_or_none(episode_content
.get('broadcastDateLabel'))
94 '_type': 'url_transparent',
98 # an another title which is considered "full title" for some viewers
99 'alt_title': join_nonempty(title
, provider
, onair_label
, delim
=' '),
101 'description': str_or_none(video_info
.get('description')),
103 self
.BRIGHTCOVE_URL_TEMPLATE
% (p_id
, r_id
), {'geo_countries': ['JP']}
),
104 'ie_key': 'BrightcoveNew',