logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tver.py (1981B)


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