youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

tver.py (1981B)


      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     try_get,
     13 )
     14 
     15 
     16 class 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,
     28     }, {
     29         # subtitle = ' '
     30         'url': 'https://tver.jp/corner/f0068870',
     31         'only_matching': True,
     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):
     41         path, video_id = re.match(self._VALID_URL, url).groups()
     42         main = self._download_json(
     43             'https://api.tver.jp/v4/' + path, video_id,
     44             query={'token': self._TOKEN})['main']
     45         p_id = main['publisher_id']
     46         service = remove_start(main['service'], 'ts_')
     47 
     48         r_id = main['reference_id']
     49         if service not in ('tx', 'russia2018', 'sebare2018live', 'gorin'):
     50             r_id = 'ref:' + r_id
     51         bc_url = smuggle_url(
     52             self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
     53             {'geo_countries': ['JP']})
     54 
     55         return {
     56             '_type': 'url_transparent',
     57             'description': try_get(main, lambda x: x['note'][0]['text'], compat_str),
     58             'episode_number': int_or_none(try_get(main, lambda x: x['ext']['episode_number'])),
     59             'url': bc_url,
     60             'ie_key': 'BrightcoveNew',
     61         }