-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThe Code.py
More file actions
191 lines (148 loc) · 7.11 KB
/
The Code.py
File metadata and controls
191 lines (148 loc) · 7.11 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import os
import tkinter as tk
from tkinter import filedialog, messagebox
import webbrowser
import getpass
from PIL import Image, ImageTk
import requests
import tempfile
from io import BytesIO
import shutil # Import the shutil library for file copying
import threading # To run parallel tasks, it's just some optimization
class FileReplacerGUI:
def __init__(self, master):
self.master = master
master.title("Geometry Dash song replacer")
master.geometry('640x360')
master.resizable(False, False) # Lock the window size
self.image_path = os.path.join(tempfile.gettempdir(), 'anim.gif')
self.gif_frames = []
self.gif_frame_dur = 0
self.gif_frame_count = -1
self.background_image = None
gif_lb = tk.Label(self.master, image=self.background_image)
gif_lb.pack(fill=tk.BOTH)
self.gif_label = gif_lb
# Download and set background image
background_url = "https://media.tenor.com/ljZfH3ZkEqEAAAAd/cherry-blossom.gif"
self.set_background_from_url(background_url)
self.current_file_path = ""
self.new_file_path = ""
# Create buttons and labels with increased size and spacing
self.current_file_label = tk.Label(master, text="Current File:")
self.current_file_label.pack(pady=20)
self.current_file_button = tk.Button(master, text="Select File", command=self.select_current_file, height=3, width=20)
self.current_file_button.pack(pady=10)
self.new_file_label = tk.Label(master, text="New File Name:")
self.new_file_label.pack(pady=20)
self.new_file_entry = tk.Entry(master, width=50)
self.new_file_entry.pack(pady=10)
self.execute_button = tk.Button(master, text="Execute", command=self.execute, height=3, width=20)
self.execute_button.pack(pady=20)
# Load and display the Discord icon image
discord_icon_url = "https://cdn.discordapp.com/attachments/1026244641370144899/1153770135673376910/bmc.png"
image = self.load_image_from_url(discord_icon_url)
if image:
image = ImageTk.PhotoImage(image.resize((100, 100))) # Resize the image
self.discord_button = tk.Button(master, image=image, command=self.join_discord_server, bg='black', height=120, width=120)
self.discord_button.pack(pady=20)
self.discord_button.image = image # Keep a reference to prevent image garbage collection
def load_image_from_url(self, url):
try:
response = requests.get(url)
if response.status_code == 200:
image_data = response.content
return Image.open(BytesIO(image_data))
else:
print(f"Failed to load image from URL: {url}")
return None
except Exception as e:
print(f"Failed to load image: {e}")
return None
def set_background_from_url(self, url):
#The url.txt keeps the url of the downloaded background, so if the background download link is updated,
# the background stored on the system will get replaced.
url_path = os.path.join(tempfile.gettempdir(), 'url.txt')
#Verify if the bg is already downloaded and up-to-date, else it gets updated.
if os.path.exists(self.image_path) and os.path.exists(url_path) and url == open(url_path, 'r').read():
print("No need to download anything")
pass
else:
try:
response = requests.get(url)
if response.status_code == 200:
image_data = response.content
with open(self.image_path, 'wb') as image_file:
image_file.write(image_data)
with open(url_path, 'w') as url_file:
url_file.write(url)
print("Background downloaded !")
else:
print(f"Failed to download background image from URL: {url}")
except Exception as e:
print(f"Failed to set background image: {e}")
print()
print('Check your internet connection !')
print()
return None
#Display the bg
#self.prepare_gif() instead of the next line if you want the window to launch only when the bg is ready
threading.Thread(target=self.prepare_gif).start()
def prepare_gif(self):
#Open gif file
gif_file = Image.open(self.image_path)
#Store frames in gif_frames and duration in gif_frame_dur
for i in range(0, gif_file.n_frames):
gif_file.seek(i)
self.gif_frames.append(gif_file.copy())
self.gif_frame_dur = gif_file.info['duration']
self.play_gif()
def play_gif(self):
#If it's on the last frame, then go to the first
if self.gif_frame_count >= len(self.gif_frames) -1:
self.gif_frame_count = -1
self.gif_frame_count += 1
#Display current frame
self.background_image = ImageTk.PhotoImage(self.gif_frames[self.gif_frame_count])
self.gif_label.config(image=self.background_image)
self.gif_label.place(relwidth=1, relheight =1)
#Add a delay for the next frame to be displayed
self.master.after(self.gif_frame_dur, self.play_gif)
def select_current_file(self):
# Open a file dialog to select the file to replace
file_path = filedialog.askopenfilename()
if file_path.endswith('.mp3'):
self.current_file_path = file_path
self.current_file_label.config(text="Current File: " + file_path)
else:
messagebox.showerror("Error", "The selected file is not an MP3 file.")
def execute(self):
# Check that a file has been selected and a new file name has been entered
if self.current_file_path == "":
messagebox.showerror("Error", "No file selected")
return
if self.new_file_entry.get() == "":
messagebox.showerror("Error", "No new file name entered")
return
# Check that the selected file is an mp3 file
if not self.current_file_path.endswith('.mp3'):
messagebox.showerror("Error", "The selected file is not an MP3 file.")
return
# Get the new file name and create the new file path
new_file_name = self.new_file_entry.get()
if not new_file_name.endswith('.mp3'):
new_file_name += '.mp3'
new_file_path = os.path.join(f"C:/Users/{getpass.getuser()}/AppData/Local/GeometryDash", new_file_name)
# Copy the file instead of replacing it
try:
shutil.copy(self.current_file_path, new_file_path)
messagebox.showinfo("Success", "File copied successfully")
except Exception as e:
messagebox.showerror("Error", "Failed to copy file: " + str(e))
def join_discord_server(self):
# Open the Discord server in a web browser
webbrowser.open("https://discord.gg/nfyVQ762XM")
# Create the GUI
root = tk.Tk()
file_replacer_gui = FileReplacerGUI(root)
root.mainloop()