]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tver.py
[dplay] Add extractors for site changes (#2401)
[yt-dlp.git] / yt_dlp / extractor / tver.py
CommitLineData
29f7c58a 1# coding: utf-8
2from __future__ import unicode_literals
3
29f7c58a 4
5from .common import InfoExtractor
6from ..compat import compat_str
7from ..utils import (
42c5458a 8 ExtractorError,
29f7c58a 9 int_or_none,
10 remove_start,
11 smuggle_url,
42c5458a 12 traverse_obj,
29f7c58a 13)
14
15
16class 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
19 _TESTS = [{
20 'url': 'https://tver.jp/corner/f0062178',
21 'only_matching': True,
22 }, {
23 'url': 'https://tver.jp/feature/f0062413',
24 'only_matching': True,
25 }, {
26 'url': 'https://tver.jp/episode/79622438',
27 'only_matching': True,
10db0d2f 28 }, {
29 # subtitle = ' '
30 'url': 'https://tver.jp/corner/f0068870',
31 'only_matching': True,
29f7c58a 32 }]
33 _TOKEN = None
34 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
35
36 def _real_initialize(self):
37 self._TOKEN = self._download_json(
38 'https://tver.jp/api/access_token.php', None)['token']
39
40 def _real_extract(self, url):
5ad28e7f 41 path, video_id = self._match_valid_url(url).groups()
42c5458a 42 api_response = self._download_json(
29f7c58a 43 'https://api.tver.jp/v4/' + path, video_id,
42c5458a
LNO
44 query={'token': self._TOKEN})
45 p_id = traverse_obj(api_response, ('main', 'publisher_id'))
46 if not p_id:
47 error_msg, expected = traverse_obj(api_response, ('episode', 0, 'textbar', 0, ('text', 'longer')), get_all=False), True
48 if not error_msg:
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_')
41d1cca3 52
42c5458a 53 r_id = traverse_obj(api_response, ('main', 'reference_id'))
41d1cca3 54 if service not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
55 r_id = 'ref:' + r_id
56 bc_url = smuggle_url(
57 self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
58 {'geo_countries': ['JP']})
59
60 return {
29f7c58a 61 '_type': 'url_transparent',
42c5458a
LNO
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)),
41d1cca3 64 'url': bc_url,
65 'ie_key': 'BrightcoveNew',
29f7c58a 66 }