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