2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..compat import compat_str
20 class HKETVIE(InfoExtractor):
22 IE_DESC = '香港教育局教育電視 (HKETV) Educational Television, Hong Kong Educational Bureau'
24 _GEO_COUNTRIES = ['HK']
25 _VALID_URL = r'https?://(?:www\.)?hkedcity\.net/etv/resource/(?P<id>[0-9]+)'
27 'url': 'https://www.hkedcity.net/etv/resource/2932360618',
28 'md5': 'f193712f5f7abb208ddef3c5ea6ed0b7',
32 'title': '喜閱一生(共享閱讀樂) (中、英文字幕可供選擇)',
33 'description': 'md5:d5286d05219ef50e0613311cbe96e560',
34 'upload_date': '20181024',
36 'subtitles': 'count:2',
38 'skip': 'Geo restricted to HK',
40 'url': 'https://www.hkedcity.net/etv/resource/972641418',
41 'md5': '1ed494c1c6cf7866a8290edad9b07dc9',
45 'title': '衣冠楚楚 (天使系列之一)',
46 'description': 'md5:10bb3d659421e74f58e5db5691627b0f',
47 'upload_date': '20070109',
52 'geo_verification_proxy': '<HK proxy here>',
54 'skip': 'Geo restricted to HK',
58 '中文(繁體中文)': 'zh-Hant',
59 '中文(简体中文)': 'zh-Hans',
61 'Bahasa Indonesia': 'id',
62 '\u0939\u093f\u0928\u094d\u0926\u0940': 'hi',
63 '\u0928\u0947\u092a\u093e\u0932\u0940': 'ne',
65 '\u0e44\u0e17\u0e22': 'th',
66 '\u0627\u0631\u062f\u0648': 'ur',
72 _APPS_BASE_URL = 'https://apps.hkedcity.net'
74 def _real_extract(self, url):
75 video_id = self._match_id(url)
76 webpage = self._download_webpage(url, video_id)
79 self._html_search_meta(
80 ('ed_title', 'search.ed_title'), webpage, default=None)
81 or self._search_regex(
82 r'data-favorite_title_(?:eng|chi)=(["\'])(?P<id>(?:(?!\1).)+)\1',
83 webpage, 'title', default=None, group='url')
84 or self._html_search_regex(
85 r'<h1>([^<]+)</h1>', webpage, 'title', default=None)
86 or self._og_search_title(webpage)
89 file_id = self._search_regex(
90 r'post_var\[["\']file_id["\']\s*\]\s*=\s*(.+?);',
92 curr_url = self._search_regex(
93 r'post_var\[["\']curr_url["\']\s*\]\s*=\s*"(.+?)";',
102 response = self._download_json(
103 self._APPS_BASE_URL + '/media/play/handler.php', video_id,
104 data=urlencode_postdata(data),
105 headers=merge_dicts({
106 'Content-Type': 'application/x-www-form-urlencoded'},
107 self.geo_verification_headers()))
109 result = response['result']
111 if not response.get('success') or not response.get('access'):
112 error = clean_html(response.get('access_err_msg'))
113 if 'Video streaming is not available in your country' in error:
114 self.raise_geo_restricted(
115 msg=error, countries=self._GEO_COUNTRIES)
117 raise ExtractorError(error, expected=True)
121 width = int_or_none(result.get('width'))
122 height = int_or_none(result.get('height'))
124 playlist0 = result['playlist'][0]
125 for fmt in playlist0['sources']:
126 file_url = urljoin(self._APPS_BASE_URL, fmt.get('file'))
129 # If we ever wanted to provide the final resolved URL that
130 # does not require cookies, albeit with a shorter lifespan:
131 # urlh = self._downloader.urlopen(file_url)
132 # resolved_url = urlh.geturl()
133 label = fmt.get('label')
134 h = self._FORMAT_HEIGHTS.get(label)
135 w = h * width // height if h and width and height else None
138 'ext': fmt.get('type'),
143 self._sort_formats(formats)
146 tracks = try_get(playlist0, lambda x: x['tracks'], list) or []
148 if not isinstance(track, dict):
150 track_kind = str_or_none(track.get('kind'))
151 if not track_kind or not isinstance(track_kind, compat_str):
153 if track_kind.lower() not in ('captions', 'subtitles'):
155 track_url = urljoin(self._APPS_BASE_URL, track.get('file'))
158 track_label = track.get('label')
159 subtitles.setdefault(self._CC_LANGS.get(
160 track_label, track_label), []).append({
161 'url': self._proto_relative_url(track_url),
166 emotion = self._download_json(
167 'https://emocounter.hkedcity.net/handler.php', video_id,
168 data=urlencode_postdata({
169 'action': 'get_emotion',
170 'data[bucket_id]': 'etv',
171 'data[identifier]': video_id,
173 headers={'Content-Type': 'application/x-www-form-urlencoded'},
175 like_count = int_or_none(try_get(
176 emotion, lambda x: x['data']['emotion_data'][0]['count']))
181 'description': self._html_search_meta(
182 'description', webpage, fatal=False),
183 'upload_date': unified_strdate(self._html_search_meta(
184 'ed_date', webpage, fatal=False), day_first=False),
185 'duration': int_or_none(result.get('length')),
187 'subtitles': subtitles,
188 'thumbnail': urljoin(self._APPS_BASE_URL, result.get('image')),
189 'view_count': parse_count(result.get('view_count')),
190 'like_count': like_count,