]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hketv.py
1 from .common
import InfoExtractor
2 from ..compat
import compat_str
17 class HKETVIE(InfoExtractor
):
19 IE_DESC
= '香港教育局教育電視 (HKETV) Educational Television, Hong Kong Educational Bureau'
21 _GEO_COUNTRIES
= ['HK']
22 _VALID_URL
= r
'https?://(?:www\.)?hkedcity\.net/etv/resource/(?P<id>[0-9]+)'
24 'url': 'https://www.hkedcity.net/etv/resource/2932360618',
25 'md5': 'f193712f5f7abb208ddef3c5ea6ed0b7',
29 'title': '喜閱一生(共享閱讀樂) (中、英文字幕可供選擇)',
30 'description': 'md5:d5286d05219ef50e0613311cbe96e560',
31 'upload_date': '20181024',
33 'subtitles': 'count:2',
35 'skip': 'Geo restricted to HK',
37 'url': 'https://www.hkedcity.net/etv/resource/972641418',
38 'md5': '1ed494c1c6cf7866a8290edad9b07dc9',
42 'title': '衣冠楚楚 (天使系列之一)',
43 'description': 'md5:10bb3d659421e74f58e5db5691627b0f',
44 'upload_date': '20070109',
49 'geo_verification_proxy': '<HK proxy here>',
51 'skip': 'Geo restricted to HK',
55 '中文(繁體中文)': 'zh-Hant',
56 '中文(简体中文)': 'zh-Hans',
58 'Bahasa Indonesia': 'id',
59 '\u0939\u093f\u0928\u094d\u0926\u0940': 'hi',
60 '\u0928\u0947\u092a\u093e\u0932\u0940': 'ne',
62 '\u0e44\u0e17\u0e22': 'th',
63 '\u0627\u0631\u062f\u0648': 'ur',
69 _APPS_BASE_URL
= 'https://apps.hkedcity.net'
71 def _real_extract(self
, url
):
72 video_id
= self
._match
_id
(url
)
73 webpage
= self
._download
_webpage
(url
, video_id
)
76 self
._html
_search
_meta
(
77 ('ed_title', 'search.ed_title'), webpage
, default
=None)
78 or self
._search
_regex
(
79 r
'data-favorite_title_(?:eng|chi)=(["\'])(?P
<id>(?
:(?
!\
1).)+)\
1',
80 webpage, 'title
', default=None, group='url
')
81 or self._html_search_regex(
82 r'<h1
>([^
<]+)</h1
>', webpage, 'title
', default=None)
83 or self._og_search_title(webpage)
86 file_id = self._search_regex(
87 r'post_var\
[["\']file_id["\']\s
*\
]\s
*=\s
*(.+?
);',
89 curr_url = self._search_regex(
90 r'post_var\
[["\']curr_url["\']\s
*\
]\s
*=\s
*"(.+?)";',
99 response = self._download_json(
100 self._APPS_BASE_URL + '/media
/play
/handler
.php
', video_id,
101 data=urlencode_postdata(data),
102 headers=merge_dicts({
103 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
'},
104 self.geo_verification_headers()))
106 result = response['result
']
108 if not response.get('success
') or not response.get('access
'):
109 error = clean_html(response.get('access_err_msg
'))
110 if 'Video streaming
is not available
in your country
' in error:
111 self.raise_geo_restricted(
112 msg=error, countries=self._GEO_COUNTRIES)
114 raise ExtractorError(error, expected=True)
118 width = int_or_none(result.get('width
'))
119 height = int_or_none(result.get('height
'))
121 playlist0 = result['playlist
'][0]
122 for fmt in playlist0['sources
']:
123 file_url = urljoin(self._APPS_BASE_URL, fmt.get('file'))
126 # If we ever wanted to provide the final resolved URL that
127 # does not require cookies, albeit with a shorter lifespan:
128 # urlh = self._downloader.urlopen(file_url)
129 # resolved_url = urlh.geturl()
130 label = fmt.get('label
')
131 h = self._FORMAT_HEIGHTS.get(label)
132 w = h * width // height if h and width and height else None
135 'ext
': fmt.get('type'),
140 self._sort_formats(formats)
143 tracks = try_get(playlist0, lambda x: x['tracks
'], list) or []
145 if not isinstance(track, dict):
147 track_kind = str_or_none(track.get('kind
'))
148 if not track_kind or not isinstance(track_kind, compat_str):
150 if track_kind.lower() not in ('captions
', 'subtitles
'):
152 track_url = urljoin(self._APPS_BASE_URL, track.get('file'))
155 track_label = track.get('label
')
156 subtitles.setdefault(self._CC_LANGS.get(
157 track_label, track_label), []).append({
158 'url
': self._proto_relative_url(track_url),
163 emotion = self._download_json(
164 'https
://emocounter
.hkedcity
.net
/handler
.php
', video_id,
165 data=urlencode_postdata({
166 'action
': 'get_emotion
',
167 'data
[bucket_id
]': 'etv
',
168 'data
[identifier
]': video_id,
170 headers={'Content-Type': 'application/x-www-form-urlencoded'},
172 like_count = int_or_none(try_get(
173 emotion, lambda x: x['data
']['emotion_data
'][0]['count
']))
178 'description
': self._html_search_meta(
179 'description
', webpage, fatal=False),
180 'upload_date
': unified_strdate(self._html_search_meta(
181 'ed_date
', webpage, fatal=False), day_first=False),
182 'duration
': int_or_none(result.get('length
')),
184 'subtitles
': subtitles,
185 'thumbnail
': urljoin(self._APPS_BASE_URL, result.get('image
')),
186 'view_count
': parse_count(result.get('view_count
')),
187 'like_count
': like_count,