Skip to content

Instantly share code, notes, and snippets.

@Alex1304
Last active June 16, 2024 05:57
Show Gist options
  • Save Alex1304/92be58e4c4c27b6d5e8aaf3264fa363a to your computer and use it in GitHub Desktop.
Save Alex1304/92be58e4c4c27b6d5e8aaf3264fa363a to your computer and use it in GitHub Desktop.
Script to assign title and artist tags to mp3 files of songs downloaded from Geometry Dash. Requires modules eyed3 for mp3 tag processing and wget for the redownload option.
#!/usr/bin/python3
from http.client import HTTPConnection
from urllib.parse import urlencode, unquote
import os
from os.path import sep
import eyed3
from argparse import ArgumentParser
def parse_args():
argparser = ArgumentParser()
argparser.add_argument('path_to_gd_songs')
argparser.add_argument('-r', '--redownload',
action='store_const',
const=True,
help='Re-download the MP3 files and apply tags on a fresh file')
return argparser.parse_args()
def fetch_song(songID):
conn = HTTPConnection('www.boomlings.com')
headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
params = { 'secret': 'Wmfd2893gb7', 'songID': songID }
conn.request('POST', '/database/getGJSongInfo.php', urlencode(params), headers)
try:
return conn.getresponse().read().decode()
except:
print('Warning: network request failed for song ' + songID)
return None
finally:
conn.close()
def parse_response(response):
if not response or response == '-1' or response == '-2':
return None
else:
tokens = response.split('~|~')
result = {}
fields = {
'1': 'id',
'2': 'title',
'3': 'unknown_3',
'4': 'artist',
'5': 'size',
'6': 'unknown_6',
'7': 'unknown_7',
'10': 'url'
}
for i in range(len(tokens)):
if i % 2 == 0:
if i + 1 < len(tokens):
result[fields[tokens[i]]] = tokens[i + 1]
else:
result[fields[tokens[i]]] = ''
return result
def fix_encoding(text):
try:
return text.encode('cp1252').decode('utf8')
except:
return text
def redownload_song(path, song):
os.remove(path)
import wget
print('Downloading song ' + song['id'] + '...')
wget.download(unquote(song['url']), path)
print()
if __name__ == '__main__':
args = parse_args()
successCount = 0
for filename in os.listdir(args.path_to_gd_songs):
if not filename.endswith('.mp3'):
continue
fullPath = args.path_to_gd_songs + sep + filename
songID = filename[:-4]
song = parse_response(fetch_song(songID))
if not song:
continue
if args.redownload:
redownload_song(fullPath, song)
mp3 = eyed3.load(fullPath)
mp3.initTag()
mp3.tag.version = (2, 4, 0)
mp3.tag.title = fix_encoding(song['title'])
mp3.tag.artist = fix_encoding(song['artist'])
mp3.tag.album = 'Newgrounds'
try:
mp3.tag.save()
print('Saved tags for ' + filename)
successCount += 1
except:
print('Warning: could not save tags for ' + filename)
print('Operation complete! Successfully updated tags for ' + str(successCount) + ' songs')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment