1 from .common
import InfoExtractor
16 class HKETVIE(InfoExtractor
):
18 IE_DESC
= '香港教育局教育電視 (HKETV) Educational Television, Hong Kong Educational Bureau'
20 _GEO_COUNTRIES
= ['HK']
21 _VALID_URL
= r
'https?://(?:www\.)?hkedcity\.net/etv/resource/(?P<id>[0-9]+)'
23 'url': 'https://www.hkedcity.net/etv/resource/2932360618',
24 'md5': 'f193712f5f7abb208ddef3c5ea6ed0b7',
28 'title': '喜閱一生(共享閱讀樂) (中、英文字幕可供選擇)',
29 'description': 'md5:d5286d05219ef50e0613311cbe96e560',
30 'upload_date': '20181024',
32 'subtitles': 'count:2',
34 'skip': 'Geo restricted to HK',
36 'url': 'https://www.hkedcity.net/etv/resource/972641418',
37 'md5': '1ed494c1c6cf7866a8290edad9b07dc9',
41 'title': '衣冠楚楚 (天使系列之一)',
42 'description': 'md5:10bb3d659421e74f58e5db5691627b0f',
43 'upload_date': '20070109',
47 'skip': 'Geo restricted to HK',
51 '中文(繁體中文)': 'zh-Hant',
52 '中文(简体中文)': 'zh-Hans',
54 'Bahasa Indonesia': 'id',
55 '\u0939\u093f\u0928\u094d\u0926\u0940': 'hi',
56 '\u0928\u0947\u092a\u093e\u0932\u0940': 'ne',
58 '\u0e44\u0e17\u0e22': 'th',
59 '\u0627\u0631\u062f\u0648': 'ur',
65 _APPS_BASE_URL
= 'https://apps.hkedcity.net'
67 def _real_extract(self
, url
):
68 video_id
= self
._match
_id
(url
)
69 webpage
= self
._download
_webpage
(url
, video_id
)
72 self
._html
_search
_meta
(
73 ('ed_title', 'search.ed_title'), webpage
, default
=None)
74 or self
._search
_regex
(
75 r
'data-favorite_title_(?:eng|chi)=(["\'])(?P
<id>(?
:(?
!\
1).)+)\
1',
76 webpage, 'title
', default=None, group='url
')
77 or self._html_search_regex(
78 r'<h1
>([^
<]+)</h1
>', webpage, 'title
', default=None)
79 or self._og_search_title(webpage)
82 file_id = self._search_regex(
83 r'post_var\
[["\']file_id["\']\s
*\
]\s
*=\s
*(.+?
);',
85 curr_url = self._search_regex(
86 r'post_var\
[["\']curr_url["\']\s
*\
]\s
*=\s
*"(.+?)";',
95 response = self._download_json(
96 self._APPS_BASE_URL + '/media
/play
/handler
.php
', video_id,
97 data=urlencode_postdata(data),
99 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
'},
100 self.geo_verification_headers()))
102 result = response['result
']
104 if not response.get('success
') or not response.get('access
'):
105 error = clean_html(response.get('access_err_msg
'))
106 if 'Video streaming
is not available
in your country
' in error:
107 self.raise_geo_restricted(
108 msg=error, countries=self._GEO_COUNTRIES)
110 raise ExtractorError(error, expected=True)
114 width = int_or_none(result.get('width
'))
115 height = int_or_none(result.get('height
'))
117 playlist0 = result['playlist
'][0]
118 for fmt in playlist0['sources
']:
119 file_url = urljoin(self._APPS_BASE_URL, fmt.get('file'))
122 # If we ever wanted to provide the final resolved URL that
123 # does not require cookies, albeit with a shorter lifespan:
124 # urlh = self._downloader.urlopen(file_url)
125 # resolved_url = urlh.url
126 label = fmt.get('label
')
127 h = self._FORMAT_HEIGHTS.get(label)
128 w = h * width // height if h and width and height else None
131 'ext
': fmt.get('type'),
138 tracks = try_get(playlist0, lambda x: x['tracks
'], list) or []
140 if not isinstance(track, dict):
142 track_kind = str_or_none(track.get('kind
'))
143 if not track_kind or not isinstance(track_kind, str):
145 if track_kind.lower() not in ('captions
', 'subtitles
'):
147 track_url = urljoin(self._APPS_BASE_URL, track.get('file'))
150 track_label = track.get('label
')
151 subtitles.setdefault(self._CC_LANGS.get(
152 track_label, track_label), []).append({
153 'url
': self._proto_relative_url(track_url),
158 emotion = self._download_json(
159 'https
://emocounter
.hkedcity
.net
/handler
.php
', video_id,
160 data=urlencode_postdata({
161 'action
': 'get_emotion
',
162 'data
[bucket_id
]': 'etv
',
163 'data
[identifier
]': video_id,
165 headers={'Content
-Type
': 'application
/x
-www
-form
-urlencoded
'},
167 like_count = int_or_none(try_get(
168 emotion, lambda x: x['data
']['emotion_data
'][0]['count
']))
173 'description
': self._html_search_meta(
174 'description
', webpage, fatal=False),
175 'upload_date
': unified_strdate(self._html_search_meta(
176 'ed_date
', webpage, fatal=False), day_first=False),
177 'duration
': int_or_none(result.get('length
')),
179 'subtitles
': subtitles,
180 'thumbnail
': urljoin(self._APPS_BASE_URL, result.get('image
')),
181 'view_count
': parse_count(result.get('view_count
')),
182 'like_count
': like_count,