hytale.py 2.2 KB

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