]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tver.py
Update to ytdl v2021-04-01
[yt-dlp.git] / yt_dlp / extractor / tver.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9 int_or_none,
10 remove_start,
11 smuggle_url,
12 strip_or_none,
13 try_get,
14 )
15
16
17 class TVerIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?P<path>(?:corner|episode|feature)/(?P<id>f?\d+))'
19 # videos are only available for 7 days
20 _TESTS = [{
21 'url': 'https://tver.jp/corner/f0062178',
22 'only_matching': True,
23 }, {
24 'url': 'https://tver.jp/feature/f0062413',
25 'only_matching': True,
26 }, {
27 'url': 'https://tver.jp/episode/79622438',
28 'only_matching': True,
29 }, {
30 # subtitle = ' '
31 'url': 'https://tver.jp/corner/f0068870',
32 'only_matching': True,
33 }]
34 _TOKEN = None
35 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
36
37 def _real_initialize(self):
38 self._TOKEN = self._download_json(
39 'https://tver.jp/api/access_token.php', None)['token']
40
41 def _real_extract(self, url):
42 path, video_id = re.match(self._VALID_URL, url).groups()
43 main = self._download_json(
44 'https://api.tver.jp/v4/' + path, video_id,
45 query={'token': self._TOKEN})['main']
46 p_id = main['publisher_id']
47 service = remove_start(main['service'], 'ts_')
48 info = {
49 '_type': 'url_transparent',
50 'description': try_get(main, lambda x: x['note'][0]['text'], compat_str),
51 'episode_number': int_or_none(try_get(main, lambda x: x['ext']['episode_number'])),
52 }
53
54 if service == 'cx':
55 title = main['title']
56 subtitle = strip_or_none(main.get('subtitle'))
57 if subtitle:
58 title += ' - ' + subtitle
59 info.update({
60 'title': title,
61 'url': 'https://i.fod.fujitv.co.jp/plus7/web/%s/%s.html' % (p_id[:4], p_id),
62 'ie_key': 'FujiTVFODPlus7',
63 })
64 else:
65 r_id = main['reference_id']
66 if service not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
67 r_id = 'ref:' + r_id
68 bc_url = smuggle_url(
69 self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
70 {'geo_countries': ['JP']})
71 info.update({
72 'url': bc_url,
73 'ie_key': 'BrightcoveNew',
74 })
75
76 return info