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