]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/hytale.py
[ie/getcourseru] Add extractors (#8873)
[yt-dlp.git] / yt_dlp / extractor / hytale.py
CommitLineData
2f1b7afe 1import re
2
3from .common import InfoExtractor
4from ..utils import traverse_obj
5
6
7class HytaleIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.)?hytale\.com/news/\d+/\d+/(?P<id>[a-z0-9-]+)'
9 _TESTS = [{
10 'url': 'https://hytale.com/news/2021/07/summer-2021-development-update',
11 'info_dict': {
12 'id': 'summer-2021-development-update',
13 'title': 'Summer 2021 Development Update',
14 },
15 'playlist_count': 4,
16 'playlist': [{
17 'md5': '0854ebe347d233ee19b86ab7b2ead610',
18 'info_dict': {
19 'id': 'ed51a2609d21bad6e14145c37c334999',
20 'ext': 'mp4',
21 'title': 'Avatar Personalization',
22 'thumbnail': r're:https://videodelivery\.net/\w+/thumbnails/thumbnail\.jpg',
23 }
24 }]
25 }, {
26 'url': 'https://www.hytale.com/news/2019/11/hytale-graphics-update',
27 'info_dict': {
28 'id': 'hytale-graphics-update',
29 'title': 'Hytale graphics update',
30 },
31 'playlist_count': 2,
32 }]
33
34 def _real_initialize(self):
35 media_webpage = self._download_webpage(
36 'https://hytale.com/media', None, note='Downloading list of media', fatal=False) or ''
37
38 clips_json = traverse_obj(
39 self._search_json(
40 r'window\.__INITIAL_COMPONENTS_STATE__\s*=\s*\[',
41 media_webpage, 'clips json', None),
42 ('media', 'clips')) or []
43
44 self._titles = {clip.get('src'): clip.get('caption') for clip in clips_json}
45
46 def _real_extract(self, url):
47 playlist_id = self._match_id(url)
48 webpage = self._download_webpage(url, playlist_id)
49 entries = [
50 self.url_result(
51 f'https://cloudflarestream.com/{video_hash}/manifest/video.mpd?parentOrigin=https%3A%2F%2Fhytale.com',
52 title=self._titles.get(video_hash), url_transparent=True)
53 for video_hash in re.findall(
54 r'<stream\s+class\s*=\s*"ql-video\s+cf-stream"\s+src\s*=\s*"([a-f0-9]{32})"',
55 webpage)
56 ]
57
58 return self.playlist_result(entries, playlist_id, self._og_search_title(webpage))