diff --git a/server/app/albumslib.py b/server/app/albumslib.py index 84a82777..728182f7 100644 --- a/server/app/albumslib.py +++ b/server/app/albumslib.py @@ -1,3 +1,4 @@ +import urllib from typing import List from app import models, functions, helpers from app import trackslib, api @@ -44,6 +45,37 @@ def get_album_image(album: list) -> str: return functions.use_defaults() +def get_album_tracks(album: str, artist: str) -> List: + return [ + track + for track in api.DB_TRACKS + if track["album"] == album and track["albumartist"] == artist + ] + + +def create_album(track) -> models.Album: + """ + Generates and returns an album object from a track object. + """ + album = { + "album": track["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( + album_tracks[0]["albumartist"] + ".webp" + ) + + album["image"] = get_album_image(album_tracks) + + return models.Album(album) + + def find_album(albumtitle, artist): for album in api.ALBUMS: if album.album == albumtitle and album.artist == artist: diff --git a/server/app/api.py b/server/app/api.py index 86f2eafa..9284c788 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -10,11 +10,13 @@ from app import trackslib bp = Blueprint("api", __name__, url_prefix="") functions.start_watchdog() +DB_TRACKS = instances.songs_instance.get_all_songs() ALBUMS: List[models.Album] = [] TRACKS: List[models.Track] = [] home_dir = helpers.home_dir + @helpers.background def initialize() -> None: """ @@ -201,7 +203,7 @@ def get_artist_data(artist: str): @bp.route("/f/") -@cache.cached() +# @cache.cached() def get_folder_tree(folder: str): """ Returns a list of all the folders and tracks in the given folder. @@ -251,11 +253,9 @@ def get_folder_tree(folder: str): @bp.route("/albums") def get_albums(): """returns all the albums""" - s = instances.songs_instance.get_all_songs() - albums = [] - for song in s: + for song in DB_TRACKS: al_obj = {"name": song["album"], "artist": song["artists"]} if al_obj not in albums: diff --git a/server/app/functions.py b/server/app/functions.py index 9b7e7d77..f90b3cdb 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -100,11 +100,9 @@ def fetch_image_path(artist: str) -> str or None: def populate_images(): """populates the artists images""" - all_songs = instances.songs_instance.get_all_songs() - artists = [] - for song in all_songs: + for song in api.DB_TRACKS: this_artists = song["artists"].split(", ") for artist in this_artists: @@ -170,10 +168,9 @@ def return_album_art(filepath): def save_t_colors(): - tracks = instances.songs_instance.get_all_songs() - _bar = Bar("Processing image colors", max=len(tracks)) + _bar = Bar("Processing image colors", max=len(api.DB_TRACKS)) - for track in tracks: + for track in api.DB_TRACKS: filepath = track["filepath"] album_art = return_album_art(filepath) @@ -366,38 +363,14 @@ def get_album_bio(title: str, albumartist: str): def get_all_albums() -> List[models.Album]: + """ + Returns a list of album objects for all albums in the database. + """ print("processing albums started ...") - all_tracks = instances.songs_instance.get_all_songs() - album_dicts = [] - albums = [] + albums: List[models.Album] = [] - for track in all_tracks: - album_dict = { - "album": track["album"], - "artist": track["albumartist"], - } + for track in api.DB_TRACKS: + albums.append(albumslib.create_album(track)) - if album_dict not in album_dicts: - album_dicts.append(album_dict) - - for album in album_dicts: - album_tracks = [ - track - for track in all_tracks - if track["album"] == album["album"] - and track["albumartist"] == album["artist"] - ] - - album["count"] = len(album_tracks) - album["duration"] = albumslib.get_album_duration(album_tracks) - album["date"] = album_tracks[0]["date"] - album["artistimage"] = urllib.parse.quote_plus( - album_tracks[0]["albumartist"] + ".webp" - ) - - album["image"] = albumslib.get_album_image(album_tracks) - - albums.append(album) - - return [models.Album(album) for album in albums] + return albums diff --git a/server/app/models.py b/server/app/models.py index 61e8c612..4c335e28 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -334,5 +334,5 @@ class Album: self.count = tags["count"] self.duration = tags["duration"] self.date = tags["date"] - self.artistimage = "http://127.0.0.1:8900/images/artists/" + tags["artistimage"] - self.image = "http://127.0.0.1:8900/images/thumbnails/" + tags["image"] + self.artistimage = "http://0.0.0.0:8900/images/artists/" + tags["artistimage"] + self.image = "http://0.0.0.0:8900/images/thumbnails/" + tags["image"] diff --git a/server/app/trackslib.py b/server/app/trackslib.py index 82b47468..f7fcaa3e 100644 --- a/server/app/trackslib.py +++ b/server/app/trackslib.py @@ -12,17 +12,13 @@ def create_all_tracks() -> List[models.Track]: print("Getting all songs...") tracks: list[models.Track] = [] - for track in instances.songs_instance.get_all_songs(): - # print(track) - # print(albumslib.ALBUMS) + for track in api.DB_TRACKS: try: os.chmod(track["filepath"], 0o755) except FileNotFoundError: instances.songs_instance.remove_song_by_filepath(track["filepath"]) album = albumslib.find_album(track["album"], track["albumartist"]) - # print(album) - # print(track["album"], track["albumartist"]) track["image"] = album.image diff --git a/server/app/watchdoge.py b/server/app/watchdoge.py index bfc4db31..22ea1ec6 100644 --- a/server/app/watchdoge.py +++ b/server/app/watchdoge.py @@ -7,6 +7,7 @@ from watchdog.events import PatternMatchingEventHandler from app import instances, functions from app import api, models +from app import albumslib class OnMyWatch: @@ -35,14 +36,18 @@ def add_track(filepath: str) -> None: Processes the audio tags for a given file ands add them to the music dict. """ tags = functions.get_tags(filepath) - print(tags) if tags is not None: instances.songs_instance.insert_song(tags) - track_obj = instances.songs_instance.get_song_by_path(tags["filepath"]) + track = instances.songs_instance.get_song_by_path(tags["filepath"]) + + api.DB_TRACKS.append(track) + album = albumslib.create_album(track) + api.ALBUMS.append(album) + + track["image"] = album.image + api.TRACKS.append(models.Track(track)) - track = models.Track(track_obj) - api.TRACKS.extend(track) def remove_track(filepath: str) -> None: diff --git a/src/App.vue b/src/App.vue index 92b70bb0..d913b1f1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,7 +9,7 @@
- +
@@ -30,7 +30,7 @@ import BottomBar from "@/components/BottomBar/BottomBar.vue"; import perks from "@/composables/perks.js"; import Main from "./components/RightSideBar/Main.vue"; -import AlbumArt from "./components/LeftSidebar/AlbumArt.vue"; +import nowPlaying from "./components/LeftSidebar/nowPlaying.vue"; import NavBar from "./components/nav/NavBar.vue"; import Tabs from "./components/RightSideBar/Tabs.vue"; import SearchInput from "./components/RightSideBar/SearchInput.vue"; diff --git a/src/assets/icons/tag.svg b/src/assets/icons/tag.svg new file mode 100644 index 00000000..5bdb1cf9 --- /dev/null +++ b/src/assets/icons/tag.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/BottomBar/BottomBar.vue b/src/components/BottomBar/BottomBar.vue index 18d483c0..4fa78421 100644 --- a/src/components/BottomBar/BottomBar.vue +++ b/src/components/BottomBar/BottomBar.vue @@ -1,4 +1,4 @@ -