-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnodes.py
146 lines (110 loc) · 5.21 KB
/
nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
import datetime
from .suno.suno import *
# Assuming folder_paths module with get_save_image_path function is available
import folder_paths
class SunoAIGenerator:
def __init__(self):
self.suno_client = Suno()
self.output_dir = os.path.join(folder_paths.get_output_directory(), 'suno_ai_songs')
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"default": "Enter your song idea here"}),
"custom": ("BOOLEAN", {"default": False}),
"tags": ("STRING", {"default": ""}),
"instrumental": ("BOOLEAN", {"default": True}),
"filename_prefix": ("STRING", {"default": "SunoAI_"}),
},
"optional": {},
}
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING")
RETURN_NAMES = ("MP3 URL 1", "MP3 URL 2", "Local Path 1", "Local Path 2")
FUNCTION = "generate_songs"
OUTPUT_NODE = True
CATEGORY = "Gentle_SunoAI"
def generate_songs(self, prompt, custom, tags, instrumental,filename_prefix):
try:
generated_songs = self.suno_client.songs.generate(
prompt, custom, tags, instrumental
)
# if len(generated_songs) < 2:
# raise Exception("Suno API returned less than 2 songs.")
song1, song2 = generated_songs[:2]
url1, url2 = song1.audio_url, song2.audio_url
# Get output path information
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
_datetime = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
custom_suffix = "_sunoai" # Use "_sunoai" suffix
# Download and rename songs
audio_paths = {} # Dictionary to store audio paths
for i, song in enumerate([song1, song2]):
file = f"{filename}_{_datetime}_{custom_suffix}_{i+1}.mp3"
audio_path = os.path.join(full_output_folder, file)
download(song, root=full_output_folder, name=file)
audio_paths[song.id] = audio_path # Store path with song ID as key
# ... rest of your code
return url1, url2, audio_paths[song1.id], audio_paths[song2.id]
except Exception as e:
print(f"Error generating songs: {e}")
return "", "", "", ""
class SunoAIGeneratorNotSafe:
def __init__(self):
self.output_dir = os.path.join(folder_paths.get_output_directory(), 'suno_ai_songs')
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"default": "Enter your song idea here"}),
"custom": ("BOOLEAN", {"default": False}),
"tags": ("STRING", {"default": ""}),
"instrumental": ("BOOLEAN", {"default": True}),
"filename_prefix": ("STRING", {"default": "SunoAI_"}),
"suno_cookie":("STRING", {"multiline": True,}),
},
"optional": {},
}
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING")
RETURN_NAMES = ("MP3 URL 1", "MP3 URL 2", "Local Path 1", "Local Path 2")
FUNCTION = "generate_songs"
OUTPUT_NODE = True
CATEGORY = "Gentle_SunoAI"
def generate_songs(self, prompt, custom, tags, instrumental,filename_prefix,suno_cookie):
try:
suno_client = Suno(cookie=suno_cookie)
generated_songs = suno_client.songs.generate(
prompt, custom, tags, instrumental
)
# if len(generated_songs) < 2:
# raise Exception("Suno API returned less than 2 songs.")
song1, song2 = generated_songs[:2]
url1, url2 = song1.audio_url, song2.audio_url
# Get output path information
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
_datetime = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
custom_suffix = "_sunoai" # Use "_sunoai" suffix
# Download and rename songs
audio_paths = {} # Dictionary to store audio paths
for i, song in enumerate([song1, song2]):
file = f"{filename}_{_datetime}_{custom_suffix}_{i+1}.mp3"
audio_path = os.path.join(full_output_folder, file)
download(song, root=full_output_folder, name=file)
audio_paths[song.id] = audio_path # Store path with song ID as key
# ... rest of your code
return url1, url2, audio_paths[song1.id], audio_paths[song2.id]
except Exception as e:
print(f"Error generating songs: {e}")
return "", "", "", ""
NODE_CLASS_MAPPINGS = {
"GentlemanHu_SunoAI": SunoAIGenerator,
"GentlemanHu_SunoAI_NotSafe" :SunoAIGeneratorNotSafe
}
NODE_DISPLAY_NAME_MAPPINGS = {
"GentlemanHu_SunoAI": "SunoAIGenerator",
"GentlemanHu_SunoAI_NotSafe":"SunoAIGeneratorNotSafe"
}