patrlim-musicshite/main.py

53 lines
1.4 KiB
Python
Raw Normal View History

import os, requests, json
2024-06-10 20:48:19 +01:00
filelist = os.listdir()
jsonfile = open("songs.json", "w", encoding="utf-8")
jsonfile.write('{\n "songs":[\n')
2024-06-10 20:48:19 +01:00
i = 0
for file in filelist:
2024-06-10 20:48:19 +01:00
i += 1
if file[-4:] != ".ogg":
continue
jsonfile.write(" {\n" + ' "name":' + '"' + file.replace(".ogg","") + '",' + "\n")
jsonfile.write(' "url":' + '"' + 'https://github.com/patrlim/musicshite/raw/main/' + file.replace(" ","%20") + '"' + "\n }")
2024-06-10 20:48:19 +01:00
if i != len(os.listdir()):
jsonfile.write(",")
jsonfile.write("\n")
jsonfile.write(' ]\n}')
url = 'https://git.merith.xyz/patrlim/musicshite/raw/branch/main/songs.json'
response = requests.get(url)
if response.status_code == 200:
file_content = response.content
with open('oldsongs.json', 'wb') as f:
f.write(file_content)
else:
quit(-1)
cloudjson = open("oldsongs.json", "r", encoding="utf-8")
oldjson = ""
for line in cloudjson:
oldjson += line
cloudjsondict = json.loads(oldjson)
newfiles = []
cloudjson.close()
os.remove("oldsongs.json")
for file in filelist:
found = False
for song in cloudjsondict['songs']:
if file == song['name']+".ogg":
found = True
continue
if not found:
if file[0] == ".":
continue
os.system('git add "' + file + '"')
os.system('git commit -m "Automated Commit From Python For ResoMusic"')