mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
major refactors
- add album page store - show loaders in beforeEnter guards - show bitrate on now playing card - etc
This commit is contained in:
+12
-5
@@ -7,6 +7,7 @@ from app import api
|
||||
from app import helpers, cache
|
||||
from app import functions
|
||||
from app.lib import albumslib, trackslib
|
||||
|
||||
album_bp = Blueprint("album", __name__, url_prefix="")
|
||||
|
||||
|
||||
@@ -44,12 +45,18 @@ def get_album_tracks():
|
||||
return {"songs": songs, "info": album}
|
||||
|
||||
|
||||
@album_bp.route("/album/<title>/<artist>/bio")
|
||||
@cache.cached()
|
||||
def get_album_bio(title, artist):
|
||||
@album_bp.route("/album/bio", methods=["POST"])
|
||||
def get_album_bio():
|
||||
"""Returns the album bio for the given album."""
|
||||
bio = functions.get_album_bio(title, artist)
|
||||
return {"bio": bio}, 200
|
||||
data = request.get_json()
|
||||
print(data)
|
||||
|
||||
bio = functions.get_album_bio(data["album"], data["albumartist"])
|
||||
|
||||
if bio is not None:
|
||||
return {"bio": bio}
|
||||
else:
|
||||
return {"bio": "No bio found."}, 404
|
||||
|
||||
|
||||
@album_bp.route("/album/artists", methods=["POST"])
|
||||
|
||||
@@ -21,6 +21,7 @@ def get_all_playlists():
|
||||
playlists = []
|
||||
|
||||
for pl in ppp:
|
||||
pl.count = len(pl.tracks)
|
||||
pl.tracks = []
|
||||
playlists.append(pl)
|
||||
|
||||
@@ -33,7 +34,7 @@ def create_playlist():
|
||||
|
||||
playlist = {
|
||||
"name": data["name"],
|
||||
"description": [],
|
||||
"description": "",
|
||||
"tracks": [],
|
||||
"count": 0,
|
||||
"lastUpdated": 0,
|
||||
@@ -74,6 +75,7 @@ def add_track_to_playlist(playlist_id: str):
|
||||
def get_single_p_info(playlist_id: str):
|
||||
for p in api.PLAYLISTS:
|
||||
if p.playlistid == playlist_id:
|
||||
p.count = len(p.tracks)
|
||||
return {"data": p}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ Contains all the track routes.
|
||||
|
||||
from flask import Blueprint, send_file
|
||||
|
||||
from app import instances
|
||||
from app import instances, api
|
||||
|
||||
track_bp = Blueprint("track", __name__, url_prefix="/")
|
||||
|
||||
@@ -15,7 +15,11 @@ def send_track_file(trackid):
|
||||
Returns an audio file that matches the passed id to the client.
|
||||
"""
|
||||
try:
|
||||
filepath = instances.songs_instance.get_song_by_id(trackid)["filepath"]
|
||||
filepath = [
|
||||
file["filepath"]
|
||||
for file in api.PRE_TRACKS
|
||||
if file["_id"]["$oid"] == trackid
|
||||
][0]
|
||||
return send_file(filepath, mimetype="audio/mp3")
|
||||
except FileNotFoundError:
|
||||
return "File not found", 404
|
||||
|
||||
@@ -147,7 +147,7 @@ def use_defaults() -> str:
|
||||
"""
|
||||
Returns a path to a random image in the defaults directory.
|
||||
"""
|
||||
path = str(random.randint(0, 10)) + ".webp"
|
||||
path = "defaults/" + str(random.randint(0, 20)) + ".webp"
|
||||
return path
|
||||
|
||||
|
||||
@@ -266,14 +266,14 @@ def parse_album_artist_tag(audio):
|
||||
return albumartist
|
||||
|
||||
|
||||
def parse_album_tag(audio):
|
||||
def parse_album_tag(audio, full_path: str):
|
||||
"""
|
||||
Parses the album tag from an audio file.
|
||||
"""
|
||||
try:
|
||||
album = audio["album"][0]
|
||||
except (KeyError, IndexError):
|
||||
album = "Unknown"
|
||||
album = full_path.split("/")[-1]
|
||||
|
||||
return album
|
||||
|
||||
@@ -339,7 +339,7 @@ def get_tags(fullpath: str) -> dict:
|
||||
"artists": parse_artist_tag(audio),
|
||||
"title": parse_title_tag(audio, fullpath),
|
||||
"albumartist": parse_album_artist_tag(audio),
|
||||
"album": parse_album_tag(audio),
|
||||
"album": parse_album_tag(audio, fullpath),
|
||||
"genre": parse_genre_tag(audio),
|
||||
"date": parse_date_tag(audio)[:4],
|
||||
"tracknumber": parse_track_number(audio),
|
||||
@@ -365,16 +365,13 @@ def get_album_bio(title: str, albumartist: str):
|
||||
response = requests.get(last_fm_url)
|
||||
data = response.json()
|
||||
except:
|
||||
return "None"
|
||||
return None
|
||||
|
||||
try:
|
||||
bio = data["album"]["wiki"]["summary"].split('<a href="https://www.last.fm/')[0]
|
||||
except KeyError:
|
||||
bio = None
|
||||
|
||||
if bio is None:
|
||||
return "None"
|
||||
|
||||
return bio
|
||||
|
||||
|
||||
|
||||
@@ -54,3 +54,4 @@ def get_track_by_id(trackid: str) -> models.Track:
|
||||
for track in api.TRACKS:
|
||||
if track.trackid == trackid:
|
||||
return track
|
||||
|
||||
|
||||
@@ -60,19 +60,24 @@ def add_track(filepath: str) -> None:
|
||||
api.TRACKS.append(models.Track(tags))
|
||||
|
||||
folder = folderslib.create_folder(tags["folder"])
|
||||
print(f"💙💙 {tags['folder']}")
|
||||
print(folder)
|
||||
|
||||
if folder not in api.FOLDERS:
|
||||
api.FOLDERS.append(folder)
|
||||
print(f"added folder {folder.path}")
|
||||
|
||||
|
||||
def remove_track(filepath: str) -> None:
|
||||
"""
|
||||
Removes a track from the music dict.
|
||||
"""
|
||||
print(filepath)
|
||||
fpath = filepath.split("/")[-1]
|
||||
|
||||
try:
|
||||
trackid = instances.songs_instance.get_song_by_path(filepath)["_id"]["$oid"]
|
||||
except TypeError:
|
||||
print(f"💙 Watchdog Error: Error removing track {filepath} TypeError")
|
||||
return
|
||||
|
||||
instances.songs_instance.remove_song_by_id(trackid)
|
||||
@@ -81,6 +86,10 @@ def remove_track(filepath: str) -> None:
|
||||
if track.trackid == trackid:
|
||||
api.TRACKS.remove(track)
|
||||
|
||||
for folder in api.FOLDERS:
|
||||
if folder.path == filepath.replace(fpath, ""):
|
||||
api.FOLDERS.remove(folder)
|
||||
|
||||
|
||||
class Handler(PatternMatchingEventHandler):
|
||||
files_to_process = []
|
||||
|
||||
+14
-10
@@ -69,6 +69,16 @@ class Album:
|
||||
self.image = settings.IMG_THUMB_URI + tags["image"]
|
||||
|
||||
|
||||
def get_p_track(ptrack):
|
||||
for track in api.TRACKS:
|
||||
if (
|
||||
track.title == ptrack["title"]
|
||||
and track.artists == ptrack["artists"]
|
||||
and ptrack["album"] == track.album
|
||||
):
|
||||
return track
|
||||
|
||||
|
||||
def create_playlist_tracks(playlist_tracks: List) -> List[Track]:
|
||||
"""
|
||||
Creates a list of model.Track objects from a list of playlist track dicts.
|
||||
@@ -76,13 +86,9 @@ def create_playlist_tracks(playlist_tracks: List) -> List[Track]:
|
||||
tracks: List[Track] = []
|
||||
|
||||
for t in playlist_tracks:
|
||||
for track in api.TRACKS:
|
||||
if (
|
||||
track.title == t["title"]
|
||||
and track.artists == t["artists"]
|
||||
and track.album == t["album"]
|
||||
):
|
||||
tracks.append(track)
|
||||
track = get_p_track(t)
|
||||
if track is not None:
|
||||
tracks.append(track)
|
||||
|
||||
return tracks
|
||||
|
||||
@@ -96,8 +102,8 @@ class Playlist:
|
||||
description: str
|
||||
image: str
|
||||
tracks: List[Track]
|
||||
count: int
|
||||
lastUpdated: int
|
||||
count: int = 0
|
||||
"""A list of track objects in the playlist"""
|
||||
|
||||
def __init__(self, data):
|
||||
@@ -106,11 +112,9 @@ class Playlist:
|
||||
self.description = data["description"]
|
||||
self.image = ""
|
||||
self.tracks = create_playlist_tracks(data["tracks"])
|
||||
self.count = len(data["tracks"])
|
||||
self.lastUpdated = data["lastUpdated"]
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Folder:
|
||||
name: str
|
||||
|
||||
Reference in New Issue
Block a user