mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
refactor references to use new image server
This commit is contained in:
@@ -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}
|
||||
|
||||
|
||||
|
||||
@@ -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/<path>")
|
||||
def send_thumbnail(path: str):
|
||||
fpath = join(THUMB_PATH, path)
|
||||
exists = os.path.exists(fpath)
|
||||
@app.route("/t/<imgpath>")
|
||||
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/<path>")
|
||||
def send_artist_image(path: str):
|
||||
@app.route("/a/<imgpath>")
|
||||
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/<imgpath>')
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -148,10 +148,9 @@ def create_album(track) -> models.Album:
|
||||
"artist": track["albumartist"],
|
||||
}
|
||||
|
||||
|
||||
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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user