]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ondemandkorea.py
[ondemandkorea] Update `jw_config` regex (#2056)
[yt-dlp.git] / yt_dlp / extractor / ondemandkorea.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 ExtractorError,
9 js_to_json,
10 )
11
12
13 class OnDemandKoreaIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?P<id>[^/]+)\.html'
15 _GEO_COUNTRIES = ['US', 'CA']
16 _TESTS = [{
17 'url': 'https://www.ondemandkorea.com/ask-us-anything-e43.html',
18 'info_dict': {
19 'id': 'ask-us-anything-e43',
20 'ext': 'mp4',
21 'title': 'Ask Us Anything : Gain, Ji Soo - 09/24/2016',
22 'description': 'A talk show/game show with a school theme where celebrity guests appear as “transfer students.”',
23 'thumbnail': r're:^https?://.*\.jpg$',
24 },
25 'params': {
26 'skip_download': 'm3u8 download'
27 }
28 }, {
29 'url': 'https://www.ondemandkorea.com/confession-e01-1.html',
30 'info_dict': {
31 'id': 'confession-e01-1',
32 'ext': 'mp4',
33 'title': 'Confession : E01',
34 'description': 'Choi Do-hyun, a criminal attorney, is the son of a death row convict. Ever since Choi Pil-su got arrested for murder, Do-hyun has wanted to solve his ',
35 'thumbnail': r're:^https?://.*\.jpg$',
36 'subtitles': {
37 'English': 'mincount:1',
38 },
39 },
40 'params': {
41 'skip_download': 'm3u8 download'
42 }
43 }]
44
45 def _real_extract(self, url):
46 video_id = self._match_id(url)
47 webpage = self._download_webpage(url, video_id, fatal=False)
48
49 if not webpage:
50 # Page sometimes returns captcha page with HTTP 403
51 raise ExtractorError(
52 'Unable to access page. You may have been blocked.',
53 expected=True)
54
55 if 'msg_block_01.png' in webpage:
56 self.raise_geo_restricted(
57 msg='This content is not available in your region',
58 countries=self._GEO_COUNTRIES)
59
60 if 'This video is only available to ODK PLUS members.' in webpage:
61 raise ExtractorError(
62 'This video is only available to ODK PLUS members.',
63 expected=True)
64
65 if 'ODK PREMIUM Members Only' in webpage:
66 raise ExtractorError(
67 'This video is only available to ODK PREMIUM members.',
68 expected=True)
69
70 title = self._search_regex(
71 r'class=["\']episode_title["\'][^>]*>([^<]+)',
72 webpage, 'episode_title', fatal=False) or self._og_search_title(webpage)
73
74 jw_config = self._parse_json(
75 self._search_regex(
76 r'playlist\s*=\s*\[(?P<options>.+)];?$',
77 webpage, 'jw config', flags=re.MULTILINE, group='options'),
78 video_id, transform_source=js_to_json)
79 info = self._parse_jwplayer_data(
80 jw_config, video_id, require_title=False, m3u8_id='hls',
81 base_url=url)
82
83 info.update({
84 'title': title,
85 'description': self._og_search_description(webpage),
86 'thumbnail': self._og_search_thumbnail(webpage)
87 })
88 return info