hytale.py 2.1 KB

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