]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hketv.py
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',
48 'geo_verification_proxy': '<HK proxy here>',
50 'skip': 'Geo restricted to HK',
54 '中文(繁體中文)': 'zh-Hant',
55 '中文(简体中文)': 'zh-Hans',
57 'Bahasa Indonesia': 'id',
58 '\u0939\u093f\u0928\u094d\u0926\u0940': 'hi',
59 '\u0928\u0947\u092a\u093e\u0932\u0940': 'ne',
61 '\u0e44\u0e17\u0e22': 'th',
62 '\u0627\u0631\u062f\u0648': 'ur',
68 _APPS_BASE_URL
= 'https://apps.hkedcity.net'
70 def _real_extract(self
, url
):
71 video_id
= self
._match
_id
(url
)
72 webpage
= self
._download
_webpage
(url
, video_id
)
75 self
._html
_search
_meta
(
76 ('ed_title', 'search.ed_title'), webpage
, default
=None)
77 or self
._search
_regex
(
78 r
'data-favorite_title_(?:eng|chi)=(["\'])(?P
<id>(?
:(?
!\
1).)+)\
1',
79 webpage, 'title
', default=None, group='url
')
80 or self._html_search_regex(
81 r'<h1
>([^
<]+)</h1
>', webpage, 'title
', default=None)
82 or self._og_search_title(webpage)
85 file_id = self._search_regex(
86 r'post_var\
[["\']file_id["\']\s
*\
]\s
*=\s
*(.+?
);',
88 curr_url = self._search_regex(
89 r'post_var\
[["\']curr_url["\']\s
*\
]\s
*=\s
*"(.+?)";',
98 response = self._download_json(
99 self._APPS_BASE_URL + '/media
/play
/handler
.php
', video_id,
100 data=urlencode_postdata(data),
101 headers=merge_dicts({
102 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
'},
103 self.geo_verification_headers()))
105 result = response['result
']
107 if not response.get('success
') or not response.get('access
'):
108 error = clean_html(response.get('access_err_msg
'))
109 if 'Video streaming
is not available
in your country
' in error:
110 self.raise_geo_restricted(
111 msg=error, countries=self._GEO_COUNTRIES)
113 raise ExtractorError(error, expected=True)
117 width = int_or_none(result.get('width
'))
118 height = int_or_none(result.get('height
'))
120 playlist0 = result['playlist
'][0]
121 for fmt in playlist0['sources
']:
122 file_url = urljoin(self._APPS_BASE_URL, fmt.get('file'))
125 # If we ever wanted to provide the final resolved URL that
126 # does not require cookies, albeit with a shorter lifespan:
127 # urlh = self._downloader.urlopen(file_url)
128 # resolved_url = urlh.url
129 label = fmt.get('label
')
130 h = self._FORMAT_HEIGHTS.get(label)
131 w = h * width // height if h and width and height else None
134 'ext
': fmt.get('type'),
141 tracks = try_get(playlist0, lambda x: x['tracks
'], list) or []
143 if not isinstance(track, dict):
145 track_kind = str_or_none(track.get('kind
'))
146 if not track_kind or not isinstance(track_kind, str):
148 if track_kind.lower() not in ('captions
', 'subtitles
'):
150 track_url = urljoin(self._APPS_BASE_URL, track.get('file'))
153 track_label = track.get('label
')
154 subtitles.setdefault(self._CC_LANGS.get(
155 track_label, track_label), []).append({
156 'url
': self._proto_relative_url(track_url),
161 emotion = self._download_json(
162 'https
://emocounter
.hkedcity
.net
/handler
.php
', video_id,
163 data=urlencode_postdata({
164 'action
': 'get_emotion
',
165 'data
[bucket_id
]': 'etv
',
166 'data
[identifier
]': video_id,
168 headers={'Content-Type': 'application/x-www-form-urlencoded'},
170 like_count = int_or_none(try_get(
171 emotion, lambda x: x['data
']['emotion_data
'][0]['count
']))
176 'description
': self._html_search_meta(
177 'description
', webpage, fatal=False),
178 'upload_date
': unified_strdate(self._html_search_meta(
179 'ed_date
', webpage, fatal=False), day_first=False),
180 'duration
': int_or_none(result.get('length
')),
182 'subtitles
': subtitles,
183 'thumbnail
': urljoin(self._APPS_BASE_URL, result.get('image
')),
184 'view_count
': parse_count(result.get('view_count
')),
185 'like_count
': like_count,