ninaprotocol.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none, mimetype2ext, parse_iso8601, url_or_none
  3. from ..utils.traversal import traverse_obj
  4. class NinaProtocolIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?ninaprotocol\.com/releases/(?P<id>[^/#?]+)'
  6. _TESTS = [{
  7. 'url': 'https://www.ninaprotocol.com/releases/3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ',
  8. 'info_dict': {
  9. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ',
  10. 'title': 'The Spatulas - March Chant',
  11. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  12. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  13. 'channel': 'ppm',
  14. 'description': 'md5:bb9f9d39d8f786449cd5d0ff7c5772db',
  15. 'album': 'The Spatulas - March Chant',
  16. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  17. 'timestamp': 1701417610,
  18. 'uploader': 'ppmrecs',
  19. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  20. 'display_id': 'the-spatulas-march-chant',
  21. 'upload_date': '20231201',
  22. 'album_artist': 'Post Present Medium ',
  23. },
  24. 'playlist': [{
  25. 'info_dict': {
  26. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ_1',
  27. 'title': 'March Chant In April',
  28. 'track': 'March Chant In April',
  29. 'ext': 'mp3',
  30. 'duration': 152,
  31. 'track_number': 1,
  32. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  33. 'uploader': 'ppmrecs',
  34. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  35. 'timestamp': 1701417610,
  36. 'channel': 'ppm',
  37. 'album': 'The Spatulas - March Chant',
  38. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  39. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  40. 'upload_date': '20231201',
  41. 'album_artist': 'Post Present Medium ',
  42. },
  43. }, {
  44. 'info_dict': {
  45. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ_2',
  46. 'title': 'Rescue Mission',
  47. 'track': 'Rescue Mission',
  48. 'ext': 'mp3',
  49. 'duration': 212,
  50. 'track_number': 2,
  51. 'album_artist': 'Post Present Medium ',
  52. 'uploader': 'ppmrecs',
  53. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  54. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  55. 'channel': 'ppm',
  56. 'upload_date': '20231201',
  57. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  58. 'timestamp': 1701417610,
  59. 'album': 'The Spatulas - March Chant',
  60. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  61. },
  62. }, {
  63. 'info_dict': {
  64. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ_3',
  65. 'title': 'Slinger Style',
  66. 'track': 'Slinger Style',
  67. 'ext': 'mp3',
  68. 'duration': 179,
  69. 'track_number': 3,
  70. 'timestamp': 1701417610,
  71. 'upload_date': '20231201',
  72. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  73. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  74. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  75. 'album_artist': 'Post Present Medium ',
  76. 'album': 'The Spatulas - March Chant',
  77. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  78. 'uploader': 'ppmrecs',
  79. 'channel': 'ppm',
  80. },
  81. }, {
  82. 'info_dict': {
  83. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ_4',
  84. 'title': 'Psychic Signal',
  85. 'track': 'Psychic Signal',
  86. 'ext': 'mp3',
  87. 'duration': 220,
  88. 'track_number': 4,
  89. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  90. 'upload_date': '20231201',
  91. 'album': 'The Spatulas - March Chant',
  92. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  93. 'timestamp': 1701417610,
  94. 'album_artist': 'Post Present Medium ',
  95. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  96. 'channel': 'ppm',
  97. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  98. 'uploader': 'ppmrecs',
  99. },
  100. }, {
  101. 'info_dict': {
  102. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ_5',
  103. 'title': 'Curvy Color',
  104. 'track': 'Curvy Color',
  105. 'ext': 'mp3',
  106. 'duration': 148,
  107. 'track_number': 5,
  108. 'timestamp': 1701417610,
  109. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  110. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  111. 'album': 'The Spatulas - March Chant',
  112. 'album_artist': 'Post Present Medium ',
  113. 'channel': 'ppm',
  114. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  115. 'uploader': 'ppmrecs',
  116. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  117. 'upload_date': '20231201',
  118. },
  119. }, {
  120. 'info_dict': {
  121. 'id': '3SvsMM3y4oTPZ5DXFJnLkCAqkxz34hjzFxqms1vu9XBJ_6',
  122. 'title': 'Caveman Star',
  123. 'track': 'Caveman Star',
  124. 'ext': 'mp3',
  125. 'duration': 121,
  126. 'track_number': 6,
  127. 'channel_id': '4ceG4zsb7VVxBTGPtZMqDZWGHo3VUg2xRvzC2b17ymWP',
  128. 'thumbnail': 'https://www.arweave.net/VyZA6CBeUuqP174khvSrD44Eosi3MLVyWN42uaQKg50',
  129. 'tags': ['punk', 'postpresentmedium', 'cambridge'],
  130. 'album_artist': 'Post Present Medium ',
  131. 'uploader': 'ppmrecs',
  132. 'timestamp': 1701417610,
  133. 'uploader_id': '2bGjgdKUddJoj2shYGqfNcUfoSoABP21RJoiwGMZDq3A',
  134. 'album': 'The Spatulas - March Chant',
  135. 'channel': 'ppm',
  136. 'upload_date': '20231201',
  137. },
  138. }],
  139. }, {
  140. 'url': 'https://www.ninaprotocol.com/releases/f-g-s-american-shield',
  141. 'info_dict': {
  142. 'id': '76PZnJwaMgViQHYfA4NYJXds7CmW6vHQKAtQUxGene6J',
  143. 'description': 'md5:63f08d5db558b4b36e1896f317062721',
  144. 'title': 'F.G.S. - American Shield',
  145. 'uploader_id': 'Ej3rozs11wYqFk1Gs6oggGCkGLz8GzBhmJfnUxf6gPci',
  146. 'channel_id': '6JuksCZPXuP16wJ1BUfwuukJzh42C7guhLrFPPkVJfyE',
  147. 'channel': 'tinkscough',
  148. 'tags': [],
  149. 'album_artist': 'F.G.S.',
  150. 'album': 'F.G.S. - American Shield',
  151. 'thumbnail': 'https://www.arweave.net/YJpgImkXLT9SbpFb576KuZ5pm6bdvs452LMs3Rx6lm8',
  152. 'display_id': 'f-g-s-american-shield',
  153. 'uploader': 'flannerysilva',
  154. 'timestamp': 1702395858,
  155. 'upload_date': '20231212',
  156. },
  157. 'playlist_count': 1,
  158. }, {
  159. 'url': 'https://www.ninaprotocol.com/releases/time-to-figure-things-out',
  160. 'info_dict': {
  161. 'id': '6Zi1nC5hj6b13NkpxVYwRhFy6mYA7oLBbe9DMrgGDcYh',
  162. 'display_id': 'time-to-figure-things-out',
  163. 'description': 'md5:960202ed01c3134bb8958f1008527e35',
  164. 'timestamp': 1706283607,
  165. 'title': 'DJ STEPDAD - time to figure things out',
  166. 'album_artist': 'DJ STEPDAD',
  167. 'uploader': 'tddvsss',
  168. 'upload_date': '20240126',
  169. 'album': 'time to figure things out',
  170. 'uploader_id': 'AXQNRgTyYsySyAMFDwxzumuGjfmoXshorCesjpquwCBi',
  171. 'thumbnail': 'https://www.arweave.net/O4i8bcKVqJVZvNeHHFp6r8knpFGh9ZwEgbeYacr4nss',
  172. 'tags': [],
  173. },
  174. 'playlist_count': 4,
  175. }]
  176. def _real_extract(self, url):
  177. video_id = self._match_id(url)
  178. release = self._download_json(
  179. f'https://api.ninaprotocol.com/v1/releases/{video_id}', video_id)['release']
  180. video_id = release.get('publicKey') or video_id
  181. common_info = traverse_obj(release, {
  182. 'album': ('metadata', 'properties', 'title', {str}),
  183. 'album_artist': ((('hub', 'data'), 'publisherAccount'), 'displayName', {str}),
  184. 'timestamp': ('datetime', {parse_iso8601}),
  185. 'thumbnail': ('metadata', 'image', {url_or_none}),
  186. 'uploader': ('publisherAccount', 'handle', {str}),
  187. 'uploader_id': ('publisherAccount', 'publicKey', {str}),
  188. 'channel': ('hub', 'handle', {str}),
  189. 'channel_id': ('hub', 'publicKey', {str}),
  190. }, get_all=False)
  191. common_info['tags'] = traverse_obj(release, ('metadata', 'properties', 'tags', ..., {str}))
  192. entries = []
  193. for track_num, track in enumerate(traverse_obj(release, (
  194. 'metadata', 'properties', 'files', lambda _, v: url_or_none(v['uri']))), 1):
  195. entries.append({
  196. 'id': f'{video_id}_{track_num}',
  197. 'url': track['uri'],
  198. **traverse_obj(track, {
  199. 'title': ('track_title', {str}),
  200. 'track': ('track_title', {str}),
  201. 'ext': ('type', {mimetype2ext}),
  202. 'track_number': ('track', {int_or_none}),
  203. 'duration': ('duration', {int_or_none}),
  204. }),
  205. 'vcodec': 'none',
  206. **common_info,
  207. })
  208. return {
  209. '_type': 'playlist',
  210. 'id': video_id,
  211. 'entries': entries,
  212. **traverse_obj(release, {
  213. 'display_id': ('slug', {str}),
  214. 'title': ('metadata', 'name', {str}),
  215. 'description': ('metadata', 'description', {str}),
  216. }),
  217. **common_info,
  218. }