]>
Commit | Line | Data |
---|---|---|
05adfd88 | 1 | import functools |
c031b041 | 2 | import re |
05adfd88 | 3 | import uuid |
c031b041 | 4 | |
a4a554a7 | 5 | from .common import InfoExtractor |
47c914f9 S |
6 | from ..utils import ( |
7 | ExtractorError, | |
05adfd88 | 8 | OnDemandPagedList, |
9 | float_or_none, | |
10 | int_or_none, | |
11 | join_nonempty, | |
12 | parse_age_limit, | |
13 | parse_qs, | |
f4f9f6d0 | 14 | str_or_none, |
05adfd88 | 15 | unified_strdate, |
16 | url_or_none, | |
47c914f9 | 17 | ) |
05adfd88 | 18 | from ..utils.traversal import traverse_obj |
594601f5 | 19 | |
594601f5 | 20 | |
a4a554a7 | 21 | class OnDemandKoreaIE(InfoExtractor): |
05adfd88 | 22 | _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?:en/)?player/vod/[a-z0-9-]+\?(?:[^#]+&)?contentId=(?P<id>\d+)' |
4248dad9 | 23 | _GEO_COUNTRIES = ['US', 'CA'] |
05adfd88 | 24 | |
efef1714 | 25 | _TESTS = [{ |
05adfd88 | 26 | 'url': 'https://www.ondemandkorea.com/player/vod/ask-us-anything?contentId=686471', |
27 | 'md5': 'e2ff77255d989e3135bde0c5889fbce8', | |
594601f5 | 28 | 'info_dict': { |
05adfd88 | 29 | 'id': '686471', |
594601f5 | 30 | 'ext': 'mp4', |
05adfd88 | 31 | 'title': 'Ask Us Anything: Jung Sung-ho, Park Seul-gi, Kim Bo-min, Yang Seung-won', |
32 | 'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)', | |
33 | 'duration': 5486.955, | |
34 | 'release_date': '20220924', | |
35 | 'series': 'Ask Us Anything', | |
f4f9f6d0 | 36 | 'series_id': '11790', |
05adfd88 | 37 | 'episode_number': 351, |
38 | 'episode': 'Jung Sung-ho, Park Seul-gi, Kim Bo-min, Yang Seung-won', | |
594601f5 | 39 | }, |
efef1714 | 40 | }, { |
05adfd88 | 41 | 'url': 'https://www.ondemandkorea.com/player/vod/breakup-probation-a-week?contentId=1595796', |
42 | 'md5': '57266c720006962be7ff415b24775caa', | |
efef1714 | 43 | 'info_dict': { |
05adfd88 | 44 | 'id': '1595796', |
efef1714 | 45 | 'ext': 'mp4', |
05adfd88 | 46 | 'title': 'Breakup Probation, A Week: E08', |
47 | 'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)', | |
48 | 'duration': 1586.0, | |
49 | 'release_date': '20231001', | |
50 | 'series': 'Breakup Probation, A Week', | |
f4f9f6d0 | 51 | 'series_id': '22912', |
05adfd88 | 52 | 'episode_number': 8, |
53 | 'episode': 'E08', | |
efef1714 | 54 | }, |
05adfd88 | 55 | }, { |
56 | 'url': 'https://www.ondemandkorea.com/player/vod/the-outlaws?contentId=369531', | |
57 | 'md5': 'fa5523b87aa1f6d74fc622a97f2b47cd', | |
58 | 'info_dict': { | |
59 | 'id': '369531', | |
60 | 'ext': 'mp4', | |
61 | 'release_date': '20220519', | |
62 | 'duration': 7267.0, | |
63 | 'title': 'The Outlaws: Main Movie', | |
64 | 'thumbnail': r're:^https?://.*\.(jpg|jpeg|png)', | |
65 | 'age_limit': 18, | |
66 | }, | |
67 | }, { | |
68 | 'url': 'https://www.ondemandkorea.com/en/player/vod/capture-the-moment-how-is-that-possible?contentId=1605006', | |
69 | 'only_matching': True, | |
efef1714 | 70 | }] |
594601f5 | 71 | |
72 | def _real_extract(self, url): | |
73 | video_id = self._match_id(url) | |
05adfd88 | 74 | |
75 | data = self._download_json( | |
76 | f'https://odkmedia.io/odx/api/v3/playback/{video_id}/', video_id, fatal=False, | |
77 | headers={'service-name': 'odk'}, query={'did': str(uuid.uuid4())}, expected_status=(403, 404)) | |
78 | if not traverse_obj(data, ('result', {dict})): | |
79 | msg = traverse_obj(data, ('messages', '__default'), 'title', expected_type=str) | |
80 | raise ExtractorError(msg or 'Got empty response from playback API', expected=True) | |
81 | ||
82 | data = data['result'] | |
83 | ||
84 | def try_geo_bypass(url): | |
85 | return traverse_obj(url, ({parse_qs}, 'stream_url', 0, {url_or_none})) or url | |
86 | ||
05adfd88 | 87 | formats = [] |
88 | for m3u8_url in traverse_obj(data, (('sources', 'manifest'), ..., 'url', {url_or_none}, {try_geo_bypass})): | |
04a5e063 | 89 | mod_url = re.sub(r'_720(p?)\.m3u8', r'_1080\1.m3u8', m3u8_url) |
90 | if mod_url != m3u8_url: | |
91 | mod_format = self._extract_m3u8_formats( | |
92 | mod_url, video_id, note='Checking for higher quality format', | |
93 | errnote='No higher quality format found', fatal=False) | |
94 | if mod_format: | |
95 | formats.extend(mod_format) | |
96 | continue | |
97 | formats.extend(self._extract_m3u8_formats(m3u8_url, video_id, fatal=False)) | |
05adfd88 | 98 | |
99 | subtitles = {} | |
100 | for track in traverse_obj(data, ('text_tracks', lambda _, v: url_or_none(v['url']))): | |
101 | subtitles.setdefault(track.get('language', 'und'), []).append({ | |
102 | 'url': track['url'], | |
103 | 'ext': track.get('codec'), | |
104 | 'name': track.get('label'), | |
105 | }) | |
106 | ||
107 | def if_series(key=None): | |
108 | return lambda obj: obj[key] if key and obj['kind'] == 'series' else None | |
109 | ||
110 | return { | |
111 | 'id': video_id, | |
112 | 'title': join_nonempty( | |
113 | ('episode', 'program', 'title'), | |
114 | ('episode', 'title'), from_dict=data, delim=': '), | |
115 | **traverse_obj(data, { | |
116 | 'thumbnail': ('episode', 'images', 'thumbnail', {url_or_none}), | |
117 | 'release_date': ('episode', 'release_date', {lambda x: x.replace('-', '')}, {unified_strdate}), | |
118 | 'duration': ('duration', {functools.partial(float_or_none, scale=1000)}), | |
119 | 'age_limit': ('age_rating', 'name', {lambda x: x.replace('R', '')}, {parse_age_limit}), | |
120 | 'series': ('episode', {if_series(key='program')}, 'title'), | |
f4f9f6d0 | 121 | 'series_id': ('episode', {if_series(key='program')}, 'id', {str_or_none}), |
05adfd88 | 122 | 'episode': ('episode', {if_series(key='title')}), |
123 | 'episode_number': ('episode', {if_series(key='number')}, {int_or_none}), | |
124 | }, get_all=False), | |
125 | 'formats': formats, | |
126 | 'subtitles': subtitles, | |
127 | } | |
128 | ||
129 | ||
130 | class OnDemandKoreaProgramIE(InfoExtractor): | |
131 | _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?:en/)?player/vod/(?P<id>[a-z0-9-]+)(?:$|#)' | |
132 | _GEO_COUNTRIES = ['US', 'CA'] | |
133 | ||
134 | _TESTS = [{ | |
135 | 'url': 'https://www.ondemandkorea.com/player/vod/uskn-news', | |
136 | 'info_dict': { | |
137 | 'id': 'uskn-news', | |
138 | }, | |
139 | 'playlist_mincount': 755, | |
140 | }, { | |
141 | 'url': 'https://www.ondemandkorea.com/en/player/vod/the-land', | |
142 | 'info_dict': { | |
143 | 'id': 'the-land', | |
144 | }, | |
145 | 'playlist_count': 52, | |
146 | }] | |
147 | ||
148 | _PAGE_SIZE = 100 | |
149 | ||
150 | def _fetch_page(self, display_id, page): | |
151 | page += 1 | |
152 | page_data = self._download_json( | |
153 | f'https://odkmedia.io/odx/api/v3/program/{display_id}/episodes/', display_id, | |
154 | headers={'service-name': 'odk'}, query={ | |
155 | 'page': page, | |
156 | 'page_size': self._PAGE_SIZE, | |
157 | }, note=f'Downloading page {page}', expected_status=404) | |
158 | for episode in traverse_obj(page_data, ('result', 'results', ...)): | |
159 | yield self.url_result( | |
160 | f'https://www.ondemandkorea.com/player/vod/{display_id}?contentId={episode["id"]}', | |
161 | ie=OnDemandKoreaIE, video_title=episode.get('title')) | |
162 | ||
163 | def _real_extract(self, url): | |
164 | display_id = self._match_id(url) | |
165 | ||
166 | entries = OnDemandPagedList(functools.partial( | |
167 | self._fetch_page, display_id), self._PAGE_SIZE) | |
168 | ||
169 | return self.playlist_result(entries, display_id) |