From cd9c62d1ca042f346f5a17fb27e980b78580baf9 Mon Sep 17 00:00:00 2001 From: ping Date: Tue, 27 Sep 2016 13:29:21 +0800 Subject: [PATCH 1/3] [ondemandkorea] New extractor for ondemandkorea.com --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/ondemandkorea.py | 55 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 youtube_dl/extractor/ondemandkorea.py diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 23fd2a308..cf623cc84 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -638,6 +638,7 @@ from .nuvid import NuvidIE from .odatv import OdaTVIE from .odnoklassniki import OdnoklassnikiIE from .oktoberfesttv import OktoberfestTVIE +from .ondemandkorea import OnDemandKoreaIE from .onet import ( OnetIE, OnetChannelIE, diff --git a/youtube_dl/extractor/ondemandkorea.py b/youtube_dl/extractor/ondemandkorea.py new file mode 100644 index 000000000..28f5852e8 --- /dev/null +++ b/youtube_dl/extractor/ondemandkorea.py @@ -0,0 +1,55 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import json +import re + +from .common import InfoExtractor +from ..utils import ExtractorError + + +class OnDemandKoreaIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?P[^/]+)\.html' + _TEST = { + 'url': 'http://www.ondemandkorea.com/ask-us-anything-e43.html', + 'info_dict': { + 'id': 'ask-us-anything-e43', + 'ext': 'mp4', + 'title': 'Ask Us Anything : E43', + 'thumbnail': 're:^https?://.*\.jpg$', + }, + 'params': { + 'skip_download': 'm3u8 download' + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id, fatal=False) + + if not webpage: + # Page sometimes returns captcha page with HTTP 403 + raise ExtractorError('Unable to access page. You may have been blocked.', expected=True) + + if 'msg_block_01.png' in webpage: + raise ExtractorError('This content is not available in your region.', expected=True) + + title = self._og_search_title(webpage) + thumbnail = self._og_search_thumbnail(webpage) + + manifest_url = self._search_regex(r'file:\s"(https?://[\S].+?/manifest\.m3u8)', webpage, 'manifest') + formats = self._extract_m3u8_formats(manifest_url, video_id, 'mp4', m3u8_id='hls') + self._sort_formats(formats) + + subs = re.findall(r'file:\s\'(?P[^\']+\.vtt)\',\s+label:\s+\'(?P[^\']+)\'', webpage) + subtitles = {} + for sub in subs: + subtitles[sub[1]] = [{'url': 'http://www.ondemandkorea.com' + sub[0], 'ext': 'vtt'}] + + return { + 'id': video_id, + 'title': title, + 'thumbnail': thumbnail, + 'formats': formats, + 'subtitles': subtitles, + } From 75b6ee6f972348a705acdbe37619d121e363a30e Mon Sep 17 00:00:00 2001 From: ping Date: Tue, 27 Sep 2016 13:47:23 +0800 Subject: [PATCH 2/3] Add detection for premium videos --- youtube_dl/extractor/ondemandkorea.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/youtube_dl/extractor/ondemandkorea.py b/youtube_dl/extractor/ondemandkorea.py index 28f5852e8..10c5fd0b8 100644 --- a/youtube_dl/extractor/ondemandkorea.py +++ b/youtube_dl/extractor/ondemandkorea.py @@ -34,6 +34,9 @@ class OnDemandKoreaIE(InfoExtractor): if 'msg_block_01.png' in webpage: raise ExtractorError('This content is not available in your region.', expected=True) + if 'This video is only available to ODK PLUS members.' in webpage: + raise ExtractorError('This video is only available to ODK PLUS members.', expected=True) + title = self._og_search_title(webpage) thumbnail = self._og_search_thumbnail(webpage) From dae8fd80ed0440f683eb4dd300fe5c5c408ce3bb Mon Sep 17 00:00:00 2001 From: ping Date: Tue, 27 Sep 2016 16:26:16 +0800 Subject: [PATCH 3/3] Make subtitle ext based on sub link --- youtube_dl/extractor/ondemandkorea.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/ondemandkorea.py b/youtube_dl/extractor/ondemandkorea.py index 10c5fd0b8..125c310c8 100644 --- a/youtube_dl/extractor/ondemandkorea.py +++ b/youtube_dl/extractor/ondemandkorea.py @@ -47,7 +47,7 @@ class OnDemandKoreaIE(InfoExtractor): subs = re.findall(r'file:\s\'(?P[^\']+\.vtt)\',\s+label:\s+\'(?P[^\']+)\'', webpage) subtitles = {} for sub in subs: - subtitles[sub[1]] = [{'url': 'http://www.ondemandkorea.com' + sub[0], 'ext': 'vtt'}] + subtitles[sub[1]] = [{'url': 'http://www.ondemandkorea.com' + sub[0], 'ext': sub[0][-3:]}] return { 'id': video_id,