populate.py updated with midi length
This commit is contained in:
+18
-10
@@ -4,6 +4,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import glob
|
import glob
|
||||||
|
from mido import MidiFile
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
url = os.environ.get("API_URL")
|
url = os.environ.get("API_URL")
|
||||||
@@ -20,16 +21,16 @@ def getOrCreateAlbum(name, artistId):
|
|||||||
return out["id"]
|
return out["id"]
|
||||||
|
|
||||||
def getOrCreateGenre(names):
|
def getOrCreateGenre(names):
|
||||||
ids = []
|
ids = []
|
||||||
for name in names.split(","):
|
for name in names.split(","):
|
||||||
res = requests.post(f"{url}/genre", json={
|
res = requests.post(f"{url}/genre", json={
|
||||||
"name": name,
|
"name": name,
|
||||||
})
|
})
|
||||||
out = res.json()
|
out = res.json()
|
||||||
print(out)
|
print(out)
|
||||||
ids += [out["id"]]
|
ids += [out["id"]]
|
||||||
#TODO handle multiple genres
|
#TODO handle multiple genres
|
||||||
return ids[0]
|
return ids[0]
|
||||||
|
|
||||||
def getOrCreateArtist(name):
|
def getOrCreateArtist(name):
|
||||||
res = requests.post(f"{url}/artist", json={
|
res = requests.post(f"{url}/artist", json={
|
||||||
@@ -42,8 +43,10 @@ def getOrCreateArtist(name):
|
|||||||
def populateFile(path, midi, mxl):
|
def populateFile(path, midi, mxl):
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(path)
|
config.read(path)
|
||||||
|
mid = MidiFile(midi)
|
||||||
metadata = config["Metadata"];
|
metadata = config["Metadata"];
|
||||||
difficulties = dict(config["Difficulties"])
|
difficulties = dict(config["Difficulties"])
|
||||||
|
difficulties["length"] = round((mid.length), 2)
|
||||||
artistId = getOrCreateArtist(metadata["Artist"])
|
artistId = getOrCreateArtist(metadata["Artist"])
|
||||||
print(f"Populating {metadata['Name']}")
|
print(f"Populating {metadata['Name']}")
|
||||||
res = requests.post(f"{url}/song", json={
|
res = requests.post(f"{url}/song", json={
|
||||||
@@ -58,6 +61,11 @@ def populateFile(path, midi, mxl):
|
|||||||
})
|
})
|
||||||
print(res.json())
|
print(res.json())
|
||||||
|
|
||||||
|
def addLenghtToIni(path):
|
||||||
|
mid = MidiFile(file)
|
||||||
|
lenght = round((mid.length), 2)
|
||||||
|
print(f"song file: {file} lenght: {lenght}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global url
|
global url
|
||||||
|
|||||||
Reference in New Issue
Block a user