diff --git a/assets/populate.py b/assets/populate.py index 387c914..4b06513 100755 --- a/assets/populate.py +++ b/assets/populate.py @@ -4,6 +4,7 @@ import sys import os import requests import glob +from mido import MidiFile from configparser import ConfigParser url = os.environ.get("API_URL") @@ -20,16 +21,16 @@ def getOrCreateAlbum(name, artistId): return out["id"] def getOrCreateGenre(names): - ids = [] - for name in names.split(","): - res = requests.post(f"{url}/genre", json={ - "name": name, - }) - out = res.json() - print(out) - ids += [out["id"]] - #TODO handle multiple genres - return ids[0] + ids = [] + for name in names.split(","): + res = requests.post(f"{url}/genre", json={ + "name": name, + }) + out = res.json() + print(out) + ids += [out["id"]] + #TODO handle multiple genres + return ids[0] def getOrCreateArtist(name): res = requests.post(f"{url}/artist", json={ @@ -42,8 +43,10 @@ def getOrCreateArtist(name): def populateFile(path, midi, mxl): config = ConfigParser() config.read(path) + mid = MidiFile(midi) metadata = config["Metadata"]; difficulties = dict(config["Difficulties"]) + difficulties["length"] = round((mid.length), 2) artistId = getOrCreateArtist(metadata["Artist"]) print(f"Populating {metadata['Name']}") res = requests.post(f"{url}/song", json={ @@ -58,7 +61,6 @@ def populateFile(path, midi, mxl): }) print(res.json()) - def main(): global url if url == None: diff --git a/front/components/DurationComponent.tsx b/front/components/DurationComponent.tsx new file mode 100644 index 0000000..830471f --- /dev/null +++ b/front/components/DurationComponent.tsx @@ -0,0 +1,35 @@ +import { HStack, Icon, Text } from 'native-base'; +import { MaterialIcons } from '@expo/vector-icons'; + +type DurationComponentProps = { + length: number | undefined; +}; + +const DurationComponent = ({ length }: DurationComponentProps) => { + const minutes = Math.floor((length ?? 0) / 60); + const seconds = Math.round((length ?? 0) - minutes * 60); + + return ( + + + + {length ? `${minutes}'${seconds}` : "--'--"} + + + ); +}; + +export default DurationComponent; diff --git a/front/components/FavSongRow.tsx b/front/components/FavSongRow.tsx index c015b2a..db1b060 100644 --- a/front/components/FavSongRow.tsx +++ b/front/components/FavSongRow.tsx @@ -4,6 +4,7 @@ import TextButton from './TextButton'; import { LikedSongWithDetails } from '../models/LikedSong'; import { MaterialIcons } from '@expo/vector-icons'; import API from '../API'; +import DurationComponent from './DurationComponent'; type FavSongRowProps = { FavSong: LikedSongWithDetails; // TODO: remove Song @@ -54,6 +55,7 @@ const FavSongRow = ({ FavSong, onPress }: FavSongRowProps) => { > {FavSong.addedDate.toLocaleDateString()} + { > {song.artistId ?? 'artist'} + {/* */} + ) => { } /> +