patrlim-musicshite/main.py

53 lines
No EOL
1.4 KiB
Python

import os, requests, json
filelist = os.listdir()
jsonfile = open("songs.json", "w", encoding="utf-8")
jsonfile.write('{\n "songs":[\n')
i = 0
for file in filelist:
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 }")
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"')