You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.1 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class NhkVodIE(InfoExtractor):
  5. _VALID_URL = r'https?://www3\.nhk\.or\.jp/nhkworld/(?P<lang>[a-z]{2})/ondemand/(?P<type>video|audio)/(?P<id>\d{7}|[a-z]+-\d{8}-\d+)'
  6. # Content available only for a limited period of time. Visit
  7. # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
  8. _TESTS = [{
  9. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
  10. 'only_matching': True,
  11. }, {
  12. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
  13. 'only_matching': True,
  14. }, {
  15. 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
  16. 'only_matching': True,
  17. }]
  18. _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sodesdlist/v7/episode/%s/%s/all%s.json'
  19. def _real_extract(self, url):
  20. lang, m_type, episode_id = re.match(self._VALID_URL, url).groups()
  21. if episode_id.isdigit():
  22. episode_id = episode_id[:4] + '-' + episode_id[4:]
  23. is_video = m_type == 'video'
  24. episode = self._download_json(
  25. self._API_URL_TEMPLATE % ('v' if is_video else 'r', episode_id, lang, '/all' if is_video else ''),
  26. episode_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'][0]
  27. title = episode.get('sub_title_clean') or episode['sub_title']
  28. def get_clean_field(key):
  29. return episode.get(key + '_clean') or episode.get(key)
  30. series = get_clean_field('title')
  31. thumbnails = []
  32. for s, w, h in [('', 640, 360), ('_l', 1280, 720)]:
  33. img_path = episode.get('image' + s)
  34. if not img_path:
  35. continue
  36. thumbnails.append({
  37. 'id': '%dp' % h,
  38. 'height': h,
  39. 'width': w,
  40. 'url': 'https://www3.nhk.or.jp' + img_path,
  41. })
  42. info = {
  43. 'id': episode_id + '-' + lang,
  44. 'title': '%s - %s' % (series, title) if series and title else title,
  45. 'description': get_clean_field('description'),
  46. 'thumbnails': thumbnails,
  47. 'series': series,
  48. 'episode': title,
  49. }
  50. if is_video:
  51. info.update({
  52. '_type': 'url_transparent',
  53. 'ie_key': 'Ooyala',
  54. 'url': 'ooyala:' + episode['vod_id'],
  55. })
  56. else:
  57. audio = episode['audio']
  58. audio_path = audio['audio']
  59. info['formats'] = self._extract_m3u8_formats(
  60. 'https://nhks-vh.akamaihd.net/i%s/master.m3u8' % audio_path,
  61. episode_id, 'm4a', m3u8_id='hls', fatal=False)
  62. for proto in ('rtmpt', 'rtmp'):
  63. info['formats'].append({
  64. 'ext': 'flv',
  65. 'format_id': proto,
  66. 'url': '%s://flv.nhk.or.jp/ondemand/mp4:flv%s' % (proto, audio_path),
  67. 'vcodec': 'none',
  68. })
  69. for f in info['formats']:
  70. f['language'] = lang
  71. return info