mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
refactor UI layout
This commit is contained in:
+2
-1
@@ -11,7 +11,8 @@ bp = Blueprint("api", __name__, url_prefix="")
|
||||
|
||||
home_dir = helpers.home_dir
|
||||
|
||||
all_the_f_music = helpers.get_all_songs()
|
||||
all_the_f_albums = helpers.create_all_albums()
|
||||
all_the_f_music = helpers.create_all_tracks()
|
||||
|
||||
|
||||
def initialize() -> None:
|
||||
|
||||
+6
-11
@@ -20,6 +20,7 @@ from app import helpers
|
||||
from app import instances
|
||||
from app import api
|
||||
from app import models
|
||||
import urllib
|
||||
|
||||
|
||||
def populate():
|
||||
@@ -41,7 +42,7 @@ def populate():
|
||||
if tags is not None:
|
||||
instances.songs_instance.insert_song(tags)
|
||||
|
||||
api.all_the_f_music = helpers.get_all_songs()
|
||||
api.all_the_f_music = helpers.create_all_tracks()
|
||||
|
||||
print("\n check done")
|
||||
end = time.time()
|
||||
@@ -165,7 +166,7 @@ def extract_thumb(audio_file_path: str) -> str:
|
||||
"""
|
||||
Extracts the thumbnail from an audio file. Returns the path to the thumbnail.
|
||||
"""
|
||||
webp_path = audio_file_path.split("/")[-1] + ".webp"
|
||||
webp_path = urllib.parse.quote_plus(audio_file_path.split("/")[-1] + ".webp")
|
||||
img_path = os.path.join(helpers.app_dir, "images", "thumbnails", webp_path)
|
||||
|
||||
if os.path.exists(img_path):
|
||||
@@ -366,17 +367,11 @@ def get_all_albums():
|
||||
album["count"] = len(album_tracks)
|
||||
album["duration"] = helpers.get_album_duration(album_tracks)
|
||||
album["date"] = album_tracks[0]["date"]
|
||||
album["artistimage"] = (
|
||||
"http://127.0.0.1:8900/images/artists/"
|
||||
+ album_tracks[0]["albumartist"].replace("/", "::")
|
||||
+ ".webp"
|
||||
album["artistimage"] = urllib.parse.quote_plus(
|
||||
album_tracks[0]["albumartist"] + ".webp"
|
||||
)
|
||||
|
||||
if len(album_tracks) == 1:
|
||||
album["image"] = extract_thumb(album_tracks[0]["filepath"])
|
||||
|
||||
if len(album_tracks) > 1:
|
||||
album["image"] = helpers.get_album_image(album_tracks)
|
||||
album["image"] = helpers.get_album_image(album_tracks)
|
||||
|
||||
instances.album_instance.insert_album(album)
|
||||
|
||||
|
||||
+17
-2
@@ -146,7 +146,7 @@ def create_config_dir() -> None:
|
||||
os.chmod(path, 0o755)
|
||||
|
||||
|
||||
def get_all_songs() -> List[models.Track]:
|
||||
def create_all_tracks() -> List[models.Track]:
|
||||
"""
|
||||
Gets all songs under the ~/ directory.
|
||||
"""
|
||||
@@ -160,11 +160,26 @@ def get_all_songs() -> List[models.Track]:
|
||||
except FileNotFoundError:
|
||||
instances.songs_instance.remove_song_by_filepath(track["filepath"])
|
||||
|
||||
album = instances.album_instance.get_album_by_name(track['album', track['albumartist']])
|
||||
|
||||
if album is None:
|
||||
track['albumid'] = album['albumid']
|
||||
track['image'] = album['image']
|
||||
tracks.append(models.Track(track))
|
||||
|
||||
return tracks
|
||||
|
||||
|
||||
def create_all_albums() -> List[models.Album]:
|
||||
"""Creates album objects for all albums"""
|
||||
albums: list[models.Album] = []
|
||||
|
||||
for album in instances.album_instance.get_all_albums():
|
||||
albums.append(models.Album(album))
|
||||
|
||||
return albums
|
||||
|
||||
|
||||
def extract_colors(image) -> list:
|
||||
"""Extracts 2 of the most dominant colors from an image."""
|
||||
try:
|
||||
@@ -208,4 +223,4 @@ def get_album_image(album: list) -> str:
|
||||
if img is not None:
|
||||
return img
|
||||
|
||||
return functions.use_defaults()
|
||||
return functions.use_defaults()
|
||||
|
||||
+19
-10
@@ -237,6 +237,7 @@ class Track:
|
||||
"""
|
||||
|
||||
trackid: str
|
||||
albumid: str
|
||||
title: str
|
||||
artists: str
|
||||
albumartist: str
|
||||
@@ -244,7 +245,6 @@ class Track:
|
||||
folder: str
|
||||
filepath: str
|
||||
length: int
|
||||
date: int
|
||||
genre: str
|
||||
bitrate: int
|
||||
image: str
|
||||
@@ -260,7 +260,6 @@ class Track:
|
||||
self.folder = tags["folder"]
|
||||
self.filepath = tags["filepath"]
|
||||
self.length = tags["length"]
|
||||
self.date = tags["date"]
|
||||
self.genre = tags["genre"]
|
||||
self.bitrate = tags["bitrate"]
|
||||
self.image = "http://127.0.0.1:8900/images/thumbnails/" + tags["image"]
|
||||
@@ -287,6 +286,13 @@ class Albums(Mongo):
|
||||
upsert=True,
|
||||
).upserted_id
|
||||
|
||||
def get_all_albums(self) -> list:
|
||||
"""
|
||||
Returns all the albums in the database.
|
||||
"""
|
||||
albums = self.collection.find()
|
||||
return convert_many(albums)
|
||||
|
||||
def get_album_by_id(self, id: str) -> dict:
|
||||
"""
|
||||
Returns a single album matching the id in the query params.
|
||||
@@ -294,11 +300,11 @@ class Albums(Mongo):
|
||||
album = self.collection.find_one({"_id": ObjectId(id)})
|
||||
return convert_one(album)
|
||||
|
||||
def get_album_by_name(self, name: str) -> dict:
|
||||
def get_album_by_name(self, name: str, artist: str) -> dict:
|
||||
"""
|
||||
Returns a single album matching the name in the query params.
|
||||
"""
|
||||
album = self.collection.find_one({"album": name})
|
||||
album = self.collection.find_one({"album": name, "artist": artist})
|
||||
return convert_one(album)
|
||||
|
||||
def get_album_by_artist(self, name: str) -> dict:
|
||||
@@ -318,15 +324,18 @@ class Album:
|
||||
albumid: str
|
||||
album: str
|
||||
artist: str
|
||||
albumartist: str
|
||||
year: int
|
||||
count: int
|
||||
duration: int
|
||||
date: int
|
||||
artistimage: str
|
||||
image: str
|
||||
tracks: list
|
||||
|
||||
def __init__(self, tags):
|
||||
self.albumid = tags["_id"]["$oid"]
|
||||
self.album = tags["album"]
|
||||
self.artist = tags["artist"]
|
||||
self.albumartist = tags["albumartist"]
|
||||
self.year = tags["year"]
|
||||
self.image = ""
|
||||
self.count = tags["count"]
|
||||
self.duration = tags["duration"]
|
||||
self.date = tags["date"]
|
||||
self.artistimage = tags["artistimage"]
|
||||
self.image = tags["image"]
|
||||
|
||||
Reference in New Issue
Block a user