diff --git a/server/app/api/album.py b/server/app/api/album.py index a572aed..d937b71 100644 --- a/server/app/api/album.py +++ b/server/app/api/album.py @@ -44,6 +44,9 @@ def get_album_tracks(): index = albumslib.find_album(album, artist) album = api.ALBUMS[index] + album.count = len(songs) + album.duration = albumslib.get_album_duration(songs) + return {"songs": songs, "info": album} diff --git a/server/app/imgserver/__init__.py b/server/app/imgserver/__init__.py index 6edd8f3..96999d0 100644 --- a/server/app/imgserver/__init__.py +++ b/server/app/imgserver/__init__.py @@ -1,4 +1,4 @@ -import os +from os import path from typing import Tuple from flask import Flask @@ -8,14 +8,15 @@ app = Flask(__name__) def join(*args: Tuple[str]) -> str: - return os.path.join(*args) + return path.join(*args) -HOME = os.path.expanduser("~") -ROOT_PATH = os.path.join(HOME, ".alice", "images") +HOME = path.expanduser("~") +ROOT_PATH = path.join(HOME, ".alice", "images") THUMB_PATH = join(ROOT_PATH, "thumbnails") ARTIST_PATH = join(ROOT_PATH, "artists") +PLAYLIST_PATH = join(ROOT_PATH, "playlists") @app.route("/") @@ -23,28 +24,42 @@ def hello(): return "Hello mf" -@app.route("/thumb/") -def send_thumbnail(path: str): - fpath = join(THUMB_PATH, path) - exists = os.path.exists(fpath) +@app.route("/t/") +def send_thumbnail(imgpath: str): + fpath = join(THUMB_PATH, imgpath) + exists = path.exists(fpath) if exists: - return send_from_directory(THUMB_PATH, path) + return send_from_directory(THUMB_PATH, imgpath) return {"msg": "Not found"}, 404 -@app.route("/artist/") -def send_artist_image(path: str): +@app.route("/a/") +def send_artist_image(imgpath: str): print(ARTIST_PATH) - fpath = join(ARTIST_PATH, path) - exists = os.path.exists(fpath) + fpath = join(ARTIST_PATH, imgpath) + exists = path.exists(fpath) if exists: - return send_from_directory(ARTIST_PATH, path) + return send_from_directory(ARTIST_PATH, imgpath) return {"msg": "Not found"}, 404 +@app.route("/p/") +def send_playlist_image(imgpath: str): + fpath = join(PLAYLIST_PATH, imgpath) + exists = path.exists(fpath) + + if exists: + return send_from_directory(PLAYLIST_PATH, imgpath) + + return {"msg": "Not found"}, 404 + + +# TODO +# Return Fallback images instead of JSON + if __name__ == "__main__": app.run(threaded=True, port=9877) diff --git a/server/app/lib/albumslib.py b/server/app/lib/albumslib.py index 46d6f4a..3c67348 100644 --- a/server/app/lib/albumslib.py +++ b/server/app/lib/albumslib.py @@ -77,7 +77,7 @@ def find_album(albumtitle: str, artist: str) -> int or None: return None -def get_album_duration(album: list) -> int: +def get_album_duration(album: List[models.Track]) -> int: """ Gets the duration of an album. """ @@ -85,7 +85,7 @@ def get_album_duration(album: list) -> int: album_duration = 0 for track in album: - album_duration += track["length"] + album_duration += track.length return album_duration @@ -150,8 +150,6 @@ def create_album(track) -> models.Album: album_tracks = get_album_tracks(album["album"], album["artist"]) - album["count"] = len(album_tracks) - album["duration"] = get_album_duration(album_tracks) album["date"] = album_tracks[0]["date"] album["artistimage"] = urllib.parse.quote_plus( diff --git a/server/app/models.py b/server/app/models.py index 27e8c45..4717ad6 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -56,17 +56,15 @@ class Album: title: str artist: str - count: int - duration: int date: int artistimage: str image: str + count: int = 0 + duration: int = 0 def __init__(self, tags): self.title = tags["album"] self.artist = tags["artist"] - self.count = tags["count"] - self.duration = tags["duration"] self.date = tags["date"] self.artistimage = tags["artistimage"] self.image = tags["image"] @@ -128,9 +126,9 @@ class Playlist: def create_img_link(self, image: str): if image: - return settings.IMG_PLAYLIST_URI + image + return image - return settings.IMG_PLAYLIST_URI + "default.webp" + return "default.webp" def update_count(self): self.count = len(self._pre_tracks) diff --git a/src/components/AlbumView/Header.vue b/src/components/AlbumView/Header.vue index 3f88940..c7dd82f 100644 --- a/src/components/AlbumView/Header.vue +++ b/src/components/AlbumView/Header.vue @@ -5,7 +5,7 @@
@@ -32,7 +32,9 @@ import perks from "../../composables/perks.js"; import { AlbumInfo } from "../../interfaces.js"; import PlayBtnRect from "../shared/PlayBtnRect.vue"; import { playSources } from "../../composables/enums"; +import { paths } from "../../config"; +const imguri = paths.images.thumb const props = defineProps<{ album: AlbumInfo; }>(); diff --git a/src/components/LeftSidebar/SongCard.vue b/src/components/LeftSidebar/SongCard.vue index 90662f7..4836c64 100644 --- a/src/components/LeftSidebar/SongCard.vue +++ b/src/components/LeftSidebar/SongCard.vue @@ -6,7 +6,7 @@
@@ -36,6 +36,9 @@