fourzerostudio.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from .common import InfoExtractor
  2. from ..utils import traverse_obj, unified_timestamp
  3. class FourZeroStudioArchiveIE(InfoExtractor):
  4. _VALID_URL = r'https?://0000\.studio/(?P<uploader_id>[^/]+)/broadcasts/(?P<id>[^/]+)/archive'
  5. IE_NAME = '0000studio:archive'
  6. _TESTS = [{
  7. 'url': 'https://0000.studio/mumeijiten/broadcasts/1290f433-fce0-4909-a24a-5f7df09665dc/archive',
  8. 'info_dict': {
  9. 'id': '1290f433-fce0-4909-a24a-5f7df09665dc',
  10. 'title': 'noteで『canape』様へのファンレターを執筆します。(数秘術その2)',
  11. 'timestamp': 1653802534,
  12. 'release_timestamp': 1653796604,
  13. 'thumbnails': 'count:1',
  14. 'comments': 'count:7',
  15. 'uploader': '『中崎雄心』の執務室。',
  16. 'uploader_id': 'mumeijiten',
  17. }
  18. }]
  19. def _real_extract(self, url):
  20. video_id, uploader_id = self._match_valid_url(url).group('id', 'uploader_id')
  21. webpage = self._download_webpage(url, video_id)
  22. nuxt_data = self._search_nuxt_data(webpage, video_id, traverse=None)
  23. pcb = traverse_obj(nuxt_data, ('ssrRefs', lambda _, v: v['__typename'] == 'PublicCreatorBroadcast'), get_all=False)
  24. uploader_internal_id = traverse_obj(nuxt_data, (
  25. 'ssrRefs', lambda _, v: v['__typename'] == 'PublicUser', 'id'), get_all=False)
  26. formats, subs = self._extract_m3u8_formats_and_subtitles(pcb['archiveUrl'], video_id, ext='mp4')
  27. return {
  28. 'id': video_id,
  29. 'title': pcb.get('title'),
  30. 'age_limit': 18 if pcb.get('isAdult') else None,
  31. 'timestamp': unified_timestamp(pcb.get('finishTime')),
  32. 'release_timestamp': unified_timestamp(pcb.get('createdAt')),
  33. 'thumbnails': [{
  34. 'url': pcb['thumbnailUrl'],
  35. 'ext': 'png',
  36. }] if pcb.get('thumbnailUrl') else None,
  37. 'formats': formats,
  38. 'subtitles': subs,
  39. 'comments': [{
  40. 'author': c.get('username'),
  41. 'author_id': c.get('postedUserId'),
  42. 'author_thumbnail': c.get('userThumbnailUrl'),
  43. 'id': c.get('id'),
  44. 'text': c.get('body'),
  45. 'timestamp': unified_timestamp(c.get('createdAt')),
  46. 'like_count': c.get('likeCount'),
  47. 'is_favorited': c.get('isLikedByOwner'),
  48. 'author_is_uploader': c.get('postedUserId') == uploader_internal_id,
  49. } for c in traverse_obj(nuxt_data, (
  50. 'ssrRefs', ..., lambda _, v: v['__typename'] == 'PublicCreatorBroadcastComment')) or []],
  51. 'uploader_id': uploader_id,
  52. 'uploader': traverse_obj(nuxt_data, (
  53. 'ssrRefs', lambda _, v: v['__typename'] == 'PublicUser', 'username'), get_all=False),
  54. }
  55. class FourZeroStudioClipIE(InfoExtractor):
  56. _VALID_URL = r'https?://0000\.studio/(?P<uploader_id>[^/]+)/archive-clip/(?P<id>[^/]+)'
  57. IE_NAME = '0000studio:clip'
  58. _TESTS = [{
  59. 'url': 'https://0000.studio/soeji/archive-clip/e46b0278-24cd-40a8-92e1-b8fc2b21f34f',
  60. 'info_dict': {
  61. 'id': 'e46b0278-24cd-40a8-92e1-b8fc2b21f34f',
  62. 'title': 'わたベーさんからイラスト差し入れいただきました。ありがとうございました!',
  63. 'timestamp': 1652109105,
  64. 'like_count': 1,
  65. 'uploader': 'ソエジマケイタ',
  66. 'uploader_id': 'soeji',
  67. }
  68. }]
  69. def _real_extract(self, url):
  70. video_id, uploader_id = self._match_valid_url(url).group('id', 'uploader_id')
  71. webpage = self._download_webpage(url, video_id)
  72. nuxt_data = self._search_nuxt_data(webpage, video_id, traverse=None)
  73. clip_info = traverse_obj(nuxt_data, ('ssrRefs', lambda _, v: v['__typename'] == 'PublicCreatorArchivedClip'), get_all=False)
  74. info = next((
  75. m for m in self._parse_html5_media_entries(url, webpage, video_id)
  76. if 'mp4' in traverse_obj(m, ('formats', ..., 'ext'))
  77. ), None)
  78. if not info:
  79. self.report_warning('Failed to find a desired media element. Falling back to using NUXT data.')
  80. info = {
  81. 'formats': [{
  82. 'ext': 'mp4',
  83. 'url': url,
  84. } for url in clip_info.get('mediaFiles') or [] if url],
  85. }
  86. return {
  87. **info,
  88. 'id': video_id,
  89. 'title': clip_info.get('clipComment'),
  90. 'timestamp': unified_timestamp(clip_info.get('createdAt')),
  91. 'like_count': clip_info.get('likeCount'),
  92. 'uploader_id': uploader_id,
  93. 'uploader': traverse_obj(nuxt_data, (
  94. 'ssrRefs', lambda _, v: v['__typename'] == 'PublicUser', 'username'), get_all=False),
  95. }