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.

54 lines
2.1 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import ExtractorError
  4. class NhkVodIE(InfoExtractor):
  5. _VALID_URL = r'https?://www3\.nhk\.or\.jp/nhkworld/en/(?:vod|ondemand)/(?P<id>[^/]+/[^/?#&]+)'
  6. _TESTS = [{
  7. # Videos available only for a limited period of time. Visit
  8. # http://www3.nhk.or.jp/nhkworld/en/vod/ for working samples.
  9. 'url': 'http://www3.nhk.or.jp/nhkworld/en/vod/tokyofashion/20160815',
  10. 'info_dict': {
  11. 'id': 'A1bnNiNTE6nY3jLllS-BIISfcC_PpvF5',
  12. 'ext': 'flv',
  13. 'title': 'TOKYO FASHION EXPRESS - The Kimono as Global Fashion',
  14. 'description': 'md5:db338ee6ce8204f415b754782f819824',
  15. 'series': 'TOKYO FASHION EXPRESS',
  16. 'episode': 'The Kimono as Global Fashion',
  17. },
  18. 'skip': 'Videos available only for a limited period of time',
  19. }, {
  20. 'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2015173/',
  21. 'only_matching': True,
  22. }]
  23. _API_URL = 'http://api.nhk.or.jp/nhkworld/vodesdlist/v1/all/all/all.json?apikey=EJfK8jdS57GqlupFgAfAAwr573q01y6k'
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. data = self._download_json(self._API_URL, video_id)
  27. try:
  28. episode = next(
  29. e for e in data['data']['episodes']
  30. if e.get('url') and video_id in e['url'])
  31. except StopIteration:
  32. raise ExtractorError('Unable to find episode')
  33. embed_code = episode['vod_id']
  34. title = episode.get('sub_title_clean') or episode['sub_title']
  35. description = episode.get('description_clean') or episode.get('description')
  36. series = episode.get('title_clean') or episode.get('title')
  37. return {
  38. '_type': 'url_transparent',
  39. 'ie_key': 'Ooyala',
  40. 'url': 'ooyala:%s' % embed_code,
  41. 'title': '%s - %s' % (series, title) if series and title else title,
  42. 'description': description,
  43. 'series': series,
  44. 'episode': title,
  45. }