holodex.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from .common import InfoExtractor
  2. from .youtube import YoutubeIE
  3. from ..utils import traverse_obj
  4. class HolodexIE(InfoExtractor):
  5. _VALID_URL = r'''(?x)https?://(?:www\.|staging\.)?holodex\.net/(?:
  6. api/v2/playlist/(?P<playlist>\d+)|
  7. watch/(?P<id>[\w-]{11})(?:\?(?:[^#]+&)?playlist=(?P<playlist2>\d+))?
  8. )'''
  9. _TESTS = [{
  10. 'url': 'https://holodex.net/watch/9kQ2GtvDV3s',
  11. 'md5': 'be5ffce2f0feae8ba4c01553abc0f175',
  12. 'info_dict': {
  13. 'ext': 'mp4',
  14. 'id': '9kQ2GtvDV3s',
  15. 'title': '【おちゃめ機能】ホロライブが吹っ切れた【24人で歌ってみた】',
  16. 'channel_id': 'UCJFZiqLMntJufDCHc6bQixg',
  17. 'playable_in_embed': True,
  18. 'tags': 'count:43',
  19. 'age_limit': 0,
  20. 'live_status': 'not_live',
  21. 'description': 'md5:040e866c09dc4ab899b36479f4b7c7a2',
  22. 'channel_url': 'https://www.youtube.com/channel/UCJFZiqLMntJufDCHc6bQixg',
  23. 'upload_date': '20200406',
  24. 'uploader_url': 'http://www.youtube.com/channel/UCJFZiqLMntJufDCHc6bQixg',
  25. 'view_count': int,
  26. 'channel': 'hololive ホロライブ - VTuber Group',
  27. 'categories': ['Music'],
  28. 'uploader': 'hololive ホロライブ - VTuber Group',
  29. 'channel_follower_count': int,
  30. 'uploader_id': 'UCJFZiqLMntJufDCHc6bQixg',
  31. 'availability': 'public',
  32. 'thumbnail': 'https://i.ytimg.com/vi_webp/9kQ2GtvDV3s/maxresdefault.webp',
  33. 'duration': 263,
  34. 'like_count': int,
  35. },
  36. }, {
  37. 'url': 'https://holodex.net/api/v2/playlist/239',
  38. 'info_dict': {
  39. 'id': '239',
  40. 'title': 'Songs/Videos that made fall into the rabbit hole (from my google activity history)',
  41. },
  42. 'playlist_count': 14,
  43. }, {
  44. 'url': 'https://holodex.net/watch/_m2mQyaofjI?foo=bar&playlist=69',
  45. 'info_dict': {
  46. 'id': '69',
  47. 'title': '拿著金斧頭的藍髮大姊姊',
  48. },
  49. 'playlist_count': 3,
  50. }, {
  51. 'url': 'https://holodex.net/watch/_m2mQyaofjI?playlist=69',
  52. 'info_dict': {
  53. 'id': '_m2mQyaofjI',
  54. 'ext': 'mp4',
  55. 'playable_in_embed': True,
  56. 'like_count': int,
  57. 'uploader': 'Ernst / エンスト',
  58. 'duration': 11,
  59. 'uploader_url': 'http://www.youtube.com/channel/UCqSX4PPZY0cyetqKVY_wRVA',
  60. 'categories': ['Entertainment'],
  61. 'title': '【星街すいせい】星街向你獻上晚安',
  62. 'upload_date': '20210705',
  63. 'description': 'md5:8b8ffb157bae77f2d109021a0b577d4a',
  64. 'channel': 'Ernst / エンスト',
  65. 'channel_id': 'UCqSX4PPZY0cyetqKVY_wRVA',
  66. 'channel_follower_count': int,
  67. 'view_count': int,
  68. 'tags': [],
  69. 'live_status': 'not_live',
  70. 'channel_url': 'https://www.youtube.com/channel/UCqSX4PPZY0cyetqKVY_wRVA',
  71. 'availability': 'public',
  72. 'thumbnail': 'https://i.ytimg.com/vi_webp/_m2mQyaofjI/maxresdefault.webp',
  73. 'age_limit': 0,
  74. 'uploader_id': 'UCqSX4PPZY0cyetqKVY_wRVA',
  75. 'comment_count': int,
  76. },
  77. 'params': {'noplaylist': True},
  78. }, {
  79. 'url': 'https://staging.holodex.net/api/v2/playlist/125',
  80. 'only_matching': True,
  81. }, {
  82. 'url': 'https://staging.holodex.net/watch/rJJTJA_T_b0?playlist=25',
  83. 'only_matching': True,
  84. }, {
  85. 'url': 'https://staging.holodex.net/watch/s1ifBeukThg',
  86. 'only_matching': True,
  87. }]
  88. def _real_extract(self, url):
  89. video_id, playlist_id, pl_id2 = self._match_valid_url(url).group('id', 'playlist', 'playlist2')
  90. playlist_id = playlist_id or pl_id2
  91. if not self._yes_playlist(playlist_id, video_id):
  92. return self.url_result(f'https://www.youtube.com/watch?v={video_id}', YoutubeIE)
  93. data = self._download_json(f'https://holodex.net/api/v2/playlist/{playlist_id}', playlist_id)
  94. return self.playlist_from_matches(
  95. traverse_obj(data, ('videos', ..., 'id')), playlist_id, data.get('name'), ie=YoutubeIE)