]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ondemandkorea.py
[jwplatform] Improve duration extraction
[yt-dlp.git] / youtube_dl / extractor / ondemandkorea.py
CommitLineData
594601f5 1# coding: utf-8
2from __future__ import unicode_literals
3
4import json
5import re
6
7from .common import InfoExtractor
8from ..utils import ExtractorError
9
10
11class OnDemandKoreaIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?P<id>[^/]+)\.html'
13 _TEST = {
14 'url': 'http://www.ondemandkorea.com/ask-us-anything-e43.html',
15 'info_dict': {
16 'id': 'ask-us-anything-e43',
17 'ext': 'mp4',
18 'title': 'Ask Us Anything : E43',
19 'thumbnail': 're:^https?://.*\.jpg$',
20 },
21 'params': {
22 'skip_download': 'm3u8 download'
23 }
24 }
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id, fatal=False)
29
30 if not webpage:
31 # Page sometimes returns captcha page with HTTP 403
32 raise ExtractorError('Unable to access page. You may have been blocked.', expected=True)
33
34 if 'msg_block_01.png' in webpage:
35 raise ExtractorError('This content is not available in your region.', expected=True)
36
37 if 'This video is only available to ODK PLUS members.' in webpage:
38 raise ExtractorError('This video is only available to ODK PLUS members.', expected=True)
39
40 title = self._og_search_title(webpage)
41 thumbnail = self._og_search_thumbnail(webpage)
42
43 manifest_url = self._search_regex(r'file:\s"(https?://[\S].+?/manifest\.m3u8)', webpage, 'manifest')
44 formats = self._extract_m3u8_formats(manifest_url, video_id, 'mp4', m3u8_id='hls')
45 self._sort_formats(formats)
46
47 subs = re.findall(r'file:\s\'(?P<file>[^\']+\.vtt)\',\s+label:\s+\'(?P<lang>[^\']+)\'', webpage)
48 subtitles = {}
49 for sub in subs:
50 subtitles[sub[1]] = [{'url': 'http://www.ondemandkorea.com' + sub[0], 'ext': sub[0][-3:]}]
51
52 return {
53 'id': video_id,
54 'title': title,
55 'thumbnail': thumbnail,
56 'formats': formats,
57 'subtitles': subtitles,
58 }