]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tver.py
[youtube:comments] Add more options for limiting number of comments extracted (#1626)
[yt-dlp.git] / yt_dlp / extractor / tver.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..compat import compat_str
7 from ..utils import (
8 int_or_none,
9 remove_start,
10 smuggle_url,
11 try_get,
12 )
13
14
15 class TVerIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?tver\.jp/(?P<path>(?:corner|episode|feature)/(?P<id>f?\d+))'
17 # videos are only available for 7 days
18 _TESTS = [{
19 'url': 'https://tver.jp/corner/f0062178',
20 'only_matching': True,
21 }, {
22 'url': 'https://tver.jp/feature/f0062413',
23 'only_matching': True,
24 }, {
25 'url': 'https://tver.jp/episode/79622438',
26 'only_matching': True,
27 }, {
28 # subtitle = ' '
29 'url': 'https://tver.jp/corner/f0068870',
30 'only_matching': True,
31 }]
32 _TOKEN = None
33 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
34
35 def _real_initialize(self):
36 self._TOKEN = self._download_json(
37 'https://tver.jp/api/access_token.php', None)['token']
38
39 def _real_extract(self, url):
40 path, video_id = self._match_valid_url(url).groups()
41 main = self._download_json(
42 'https://api.tver.jp/v4/' + path, video_id,
43 query={'token': self._TOKEN})['main']
44 p_id = main['publisher_id']
45 service = remove_start(main['service'], 'ts_')
46
47 r_id = main['reference_id']
48 if service not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
49 r_id = 'ref:' + r_id
50 bc_url = smuggle_url(
51 self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
52 {'geo_countries': ['JP']})
53
54 return {
55 '_type': 'url_transparent',
56 'description': try_get(main, lambda x: x['note'][0]['text'], compat_str),
57 'episode_number': int_or_none(try_get(main, lambda x: x['ext']['episode_number'])),
58 'url': bc_url,
59 'ie_key': 'BrightcoveNew',
60 }