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.

96 lines
3.7 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. # clip
  10. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/',
  11. 'md5': '256a1be14f48d960a7e61e2532d95ec3',
  12. 'info_dict': {
  13. 'id': 'a95j5iza',
  14. 'ext': 'mp4',
  15. 'title': "Dining with the Chef - Chef Saito's Family recipe: MENCHI-KATSU",
  16. 'description': 'md5:5aee4a9f9d81c26281862382103b0ea5',
  17. 'timestamp': 1565965194,
  18. 'upload_date': '20190816',
  19. },
  20. }, {
  21. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/plugin-20190404-1/',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://www3.nhk.or.jp/nhkworld/fr/ondemand/audio/plugin-20190404-1/',
  28. 'only_matching': True,
  29. }]
  30. _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sod%slist/v7/episode/%s/%s/all%s.json'
  31. def _real_extract(self, url):
  32. lang, m_type, episode_id = re.match(self._VALID_URL, url).groups()
  33. if episode_id.isdigit():
  34. episode_id = episode_id[:4] + '-' + episode_id[4:]
  35. is_video = m_type == 'video'
  36. episode = self._download_json(
  37. self._API_URL_TEMPLATE % (
  38. 'v' if is_video else 'r',
  39. 'clip' if episode_id[:4] == '9999' else 'esd',
  40. episode_id, lang, '/all' if is_video else ''),
  41. episode_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'][0]
  42. title = episode.get('sub_title_clean') or episode['sub_title']
  43. def get_clean_field(key):
  44. return episode.get(key + '_clean') or episode.get(key)
  45. series = get_clean_field('title')
  46. thumbnails = []
  47. for s, w, h in [('', 640, 360), ('_l', 1280, 720)]:
  48. img_path = episode.get('image' + s)
  49. if not img_path:
  50. continue
  51. thumbnails.append({
  52. 'id': '%dp' % h,
  53. 'height': h,
  54. 'width': w,
  55. 'url': 'https://www3.nhk.or.jp' + img_path,
  56. })
  57. info = {
  58. 'id': episode_id + '-' + lang,
  59. 'title': '%s - %s' % (series, title) if series and title else title,
  60. 'description': get_clean_field('description'),
  61. 'thumbnails': thumbnails,
  62. 'series': series,
  63. 'episode': title,
  64. }
  65. if is_video:
  66. info.update({
  67. '_type': 'url_transparent',
  68. 'ie_key': 'Piksel',
  69. 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + episode['vod_id'],
  70. })
  71. else:
  72. audio = episode['audio']
  73. audio_path = audio['audio']
  74. info['formats'] = self._extract_m3u8_formats(
  75. 'https://nhks-vh.akamaihd.net/i%s/master.m3u8' % audio_path,
  76. episode_id, 'm4a', m3u8_id='hls', fatal=False)
  77. for proto in ('rtmpt', 'rtmp'):
  78. info['formats'].append({
  79. 'ext': 'flv',
  80. 'format_id': proto,
  81. 'url': '%s://flv.nhk.or.jp/ondemand/mp4:flv%s' % (proto, audio_path),
  82. 'vcodec': 'none',
  83. })
  84. for f in info['formats']:
  85. f['language'] = lang
  86. return info