suno.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package dto
  2. import (
  3. "encoding/json"
  4. )
  5. type TaskData interface {
  6. SunoDataResponse | []SunoDataResponse | string | any
  7. }
  8. type SunoSubmitReq struct {
  9. GptDescriptionPrompt string `json:"gpt_description_prompt,omitempty"`
  10. Prompt string `json:"prompt,omitempty"`
  11. Mv string `json:"mv,omitempty"`
  12. Title string `json:"title,omitempty"`
  13. Tags string `json:"tags,omitempty"`
  14. ContinueAt float64 `json:"continue_at,omitempty"`
  15. TaskID string `json:"task_id,omitempty"`
  16. ContinueClipId string `json:"continue_clip_id,omitempty"`
  17. MakeInstrumental bool `json:"make_instrumental"`
  18. }
  19. type FetchReq struct {
  20. IDs []string `json:"ids"`
  21. }
  22. type SunoDataResponse struct {
  23. TaskID string `json:"task_id" gorm:"type:varchar(50);index"`
  24. Action string `json:"action" gorm:"type:varchar(40);index"` // 任务类型, song, lyrics, description-mode
  25. Status string `json:"status" gorm:"type:varchar(20);index"` // 任务状态, submitted, queueing, processing, success, failed
  26. FailReason string `json:"fail_reason"`
  27. SubmitTime int64 `json:"submit_time" gorm:"index"`
  28. StartTime int64 `json:"start_time" gorm:"index"`
  29. FinishTime int64 `json:"finish_time" gorm:"index"`
  30. Data json.RawMessage `json:"data" gorm:"type:json"`
  31. }
  32. type SunoSong struct {
  33. ID string `json:"id"`
  34. VideoURL string `json:"video_url"`
  35. AudioURL string `json:"audio_url"`
  36. ImageURL string `json:"image_url"`
  37. ImageLargeURL string `json:"image_large_url"`
  38. MajorModelVersion string `json:"major_model_version"`
  39. ModelName string `json:"model_name"`
  40. Status string `json:"status"`
  41. Title string `json:"title"`
  42. Text string `json:"text"`
  43. Metadata SunoMetadata `json:"metadata"`
  44. }
  45. type SunoMetadata struct {
  46. Tags string `json:"tags"`
  47. Prompt string `json:"prompt"`
  48. GPTDescriptionPrompt interface{} `json:"gpt_description_prompt"`
  49. AudioPromptID interface{} `json:"audio_prompt_id"`
  50. Duration interface{} `json:"duration"`
  51. ErrorType interface{} `json:"error_type"`
  52. ErrorMessage interface{} `json:"error_message"`
  53. }
  54. type SunoLyrics struct {
  55. ID string `json:"id"`
  56. Status string `json:"status"`
  57. Title string `json:"title"`
  58. Text string `json:"text"`
  59. }
  60. const TaskSuccessCode = "success"
  61. type TaskResponse[T TaskData] struct {
  62. Code string `json:"code"`
  63. Message string `json:"message"`
  64. Data T `json:"data"`
  65. }
  66. func (t *TaskResponse[T]) IsSuccess() bool {
  67. return t.Code == TaskSuccessCode
  68. }
  69. type TaskDto struct {
  70. TaskID string `json:"task_id"` // 第三方id,不一定有/ song id\ Task id
  71. Action string `json:"action"` // 任务类型, song, lyrics, description-mode
  72. Status string `json:"status"` // 任务状态, submitted, queueing, processing, success, failed
  73. FailReason string `json:"fail_reason"`
  74. SubmitTime int64 `json:"submit_time"`
  75. StartTime int64 `json:"start_time"`
  76. FinishTime int64 `json:"finish_time"`
  77. Progress string `json:"progress"`
  78. Data json.RawMessage `json:"data"`
  79. }
  80. type SunoGoAPISubmitReq struct {
  81. CustomMode bool `json:"custom_mode"`
  82. Input SunoGoAPISubmitReqInput `json:"input"`
  83. NotifyHook string `json:"notify_hook,omitempty"`
  84. }
  85. type SunoGoAPISubmitReqInput struct {
  86. GptDescriptionPrompt string `json:"gpt_description_prompt"`
  87. Prompt string `json:"prompt"`
  88. Mv string `json:"mv"`
  89. Title string `json:"title"`
  90. Tags string `json:"tags"`
  91. ContinueAt float64 `json:"continue_at"`
  92. TaskID string `json:"task_id"`
  93. ContinueClipId string `json:"continue_clip_id"`
  94. MakeInstrumental bool `json:"make_instrumental"`
  95. }
  96. type GoAPITaskResponse[T any] struct {
  97. Code int `json:"code"`
  98. Message string `json:"message"`
  99. Data T `json:"data"`
  100. ErrorMessage string `json:"error_message,omitempty"`
  101. }
  102. type GoAPITaskResponseData struct {
  103. TaskID string `json:"task_id"`
  104. }
  105. type GoAPIFetchResponseData struct {
  106. TaskID string `json:"task_id"`
  107. Status string `json:"status"`
  108. Input string `json:"input"`
  109. Clips map[string]SunoSong `json:"clips"`
  110. }