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.

93 lines
3.6 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}|[^/]+?-\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. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/audio/j_art-20150903-1/',
  31. 'only_matching': True,
  32. }]
  33. _API_URL_TEMPLATE = 'https://api.nhk.or.jp/nhkworld/%sod%slist/v7a/episode/%s/%s/all%s.json'
  34. def _real_extract(self, url):
  35. lang, m_type, episode_id = re.match(self._VALID_URL, url).groups()
  36. if episode_id.isdigit():
  37. episode_id = episode_id[:4] + '-' + episode_id[4:]
  38. is_video = m_type == 'video'
  39. episode = self._download_json(
  40. self._API_URL_TEMPLATE % (
  41. 'v' if is_video else 'r',
  42. 'clip' if episode_id[:4] == '9999' else 'esd',
  43. episode_id, lang, '/all' if is_video else ''),
  44. episode_id, query={'apikey': 'EJfK8jdS57GqlupFgAfAAwr573q01y6k'})['data']['episodes'][0]
  45. title = episode.get('sub_title_clean') or episode['sub_title']
  46. def get_clean_field(key):
  47. return episode.get(key + '_clean') or episode.get(key)
  48. series = get_clean_field('title')
  49. thumbnails = []
  50. for s, w, h in [('', 640, 360), ('_l', 1280, 720)]:
  51. img_path = episode.get('image' + s)
  52. if not img_path:
  53. continue
  54. thumbnails.append({
  55. 'id': '%dp' % h,
  56. 'height': h,
  57. 'width': w,
  58. 'url': 'https://www3.nhk.or.jp' + img_path,
  59. })
  60. info = {
  61. 'id': episode_id + '-' + lang,
  62. 'title': '%s - %s' % (series, title) if series and title else title,
  63. 'description': get_clean_field('description'),
  64. 'thumbnails': thumbnails,
  65. 'series': series,
  66. 'episode': title,
  67. }
  68. if is_video:
  69. info.update({
  70. '_type': 'url_transparent',
  71. 'ie_key': 'Piksel',
  72. 'url': 'https://player.piksel.com/v/refid/nhkworld/prefid/' + episode['vod_id'],
  73. })
  74. else:
  75. audio = episode['audio']
  76. audio_path = audio['audio']
  77. info['formats'] = self._extract_m3u8_formats(
  78. 'https://nhkworld-vh.akamaihd.net/i%s/master.m3u8' % audio_path,
  79. episode_id, 'm4a', entry_protocol='m3u8_native',
  80. m3u8_id='hls', fatal=False)
  81. for f in info['formats']:
  82. f['language'] = lang
  83. return info