diff --git a/server/app/api/playlist.py b/server/app/api/playlist.py index d7da2058..99b96736 100644 --- a/server/app/api/playlist.py +++ b/server/app/api/playlist.py @@ -21,7 +21,8 @@ TrackExistsInPlaylist = exceptions.TrackExistsInPlaylist @playlist_bp.route("/playlists", methods=["GET"]) def get_all_playlists(): playlists = [ - serializer.Playlist(p, construct_last_updated=False) for p in api.PLAYLISTS + serializer.Playlist(p, construct_last_updated=False) + for p in api.PLAYLISTS ] playlists.sort( key=lambda p: datetime.strptime(p.lastUpdated, "%Y-%m-%d %H:%M:%S"), @@ -40,7 +41,7 @@ def create_playlist(): "pre_tracks": [], "lastUpdated": data["lastUpdated"], "image": "", - "thumb": "" + "thumb": "", } try: @@ -101,7 +102,7 @@ def update_playlist(playlistid: str): "description": str(data.get("description").strip()), "lastUpdated": str(data.get("lastUpdated")), "image": None, - "thumb": None + "thumb": None, } for p in api.PLAYLISTS: @@ -114,7 +115,7 @@ def update_playlist(playlistid: str): else: playlist["image"] = p.image.split("/")[-1] - playlist['thumb'] = p.thumb.split("/")[-1] + playlist["thumb"] = p.thumb.split("/")[-1] p.update_playlist(playlist) instances.playlist_instance.update_playlist(playlistid, playlist) diff --git a/server/app/db/albums.py b/server/app/db/albums.py index ff4a7375..885ea45f 100644 --- a/server/app/db/albums.py +++ b/server/app/db/albums.py @@ -1,8 +1,7 @@ """ -This file contains the Album class for interacting with +This file contains the Album class for interacting with album documents in MongoDB. """ - from app import db from bson import ObjectId @@ -24,8 +23,13 @@ class Albums(db.Mongo): Inserts a new album object into the database. """ return self.collection.update_one( - {"album": album["album"], "artist": album["artist"]}, - {"$set": album}, + { + "album": album["album"], + "artist": album["artist"] + }, + { + "$set": album + }, upsert=True, ).upserted_id diff --git a/server/app/db/artists.py b/server/app/db/artists.py index 165d5d87..4f82428d 100644 --- a/server/app/db/artists.py +++ b/server/app/db/artists.py @@ -1,7 +1,6 @@ """ This file contains the Artists class for interacting with artist documents in MongoDB. """ - from app import db from bson import ObjectId @@ -19,9 +18,10 @@ class Artists(db.Mongo): """ Inserts an artist into the database. """ - self.collection.update_one( - artist_obj, {"$set": artist_obj}, upsert=True - ).upserted_id + self.collection.update_one(artist_obj, { + "$set": artist_obj + }, + upsert=True).upserted_id def get_all_artists(self) -> list: """ diff --git a/server/app/db/trackcolors.py b/server/app/db/trackcolors.py index 16a402af..fc52c4ca 100644 --- a/server/app/db/trackcolors.py +++ b/server/app/db/trackcolors.py @@ -1,7 +1,6 @@ """ This file contains the TrackColors class for interacting with Track colors documents in MongoDB. """ - from app import db @@ -19,8 +18,12 @@ class TrackColors(db.Mongo): Inserts a new track object into the database. """ return self.collection.update_one( - {"filepath": track_color["filepath"]}, - {"$set": track_color}, + { + "filepath": track_color["filepath"] + }, + { + "$set": track_color + }, upsert=True, ).upserted_id diff --git a/server/app/db/tracks.py b/server/app/db/tracks.py index 5a552c72..1dbcdca9 100644 --- a/server/app/db/tracks.py +++ b/server/app/db/tracks.py @@ -1,7 +1,6 @@ """ This file contains the AllSongs class for interacting with track documents in MongoDB. """ - from app import db from bson import ObjectId @@ -25,9 +24,12 @@ class AllSongs(db.Mongo): """ Inserts a new track object into the database. """ - return self.collection.update_one( - {"filepath": song_obj["filepath"]}, {"$set": song_obj}, upsert=True - ).upserted_id + return self.collection.update_one({ + "filepath": song_obj["filepath"] + }, { + "$set": song_obj + }, + upsert=True).upserted_id def get_all_songs(self) -> list: """ @@ -53,21 +55,33 @@ class AllSongs(db.Mongo): """ Returns all the songs matching the albums in the query params (using regex). """ - songs = self.collection.find({"album": {"$regex": query, "$options": "i"}}) + songs = self.collection.find( + {"album": { + "$regex": query, + "$options": "i" + }}) return convert_many(songs) def search_songs_by_artist(self, query: str) -> list: """ Returns all the songs matching the artists in the query params. """ - songs = self.collection.find({"artists": {"$regex": query, "$options": "i"}}) + songs = self.collection.find( + {"artists": { + "$regex": query, + "$options": "i" + }}) return convert_many(songs) def find_song_by_title(self, query: str) -> list: """ Finds all the tracks matching the title in the query params. """ - song = self.collection.find({"title": {"$regex": query, "$options": "i"}}) + song = self.collection.find( + {"title": { + "$regex": query, + "$options": "i" + }}) return convert_many(song) def find_songs_by_album(self, name: str, artist: str) -> list: @@ -81,7 +95,9 @@ class AllSongs(db.Mongo): """ Returns a sorted list of all the tracks exactly matching the folder in the query params """ - songs = self.collection.find({"folder": query}).sort("title", db.pymongo.ASCENDING) + songs = self.collection.find({ + "folder": query + }).sort("title", db.pymongo.ASCENDING) return convert_many(songs) def find_songs_by_folder_og(self, query: str) -> list: @@ -103,8 +119,10 @@ class AllSongs(db.Mongo): Returns a list of all the tracks containing the albumartist in the query params. """ songs = self.collection.find( - {"albumartist": {"$regex": query, "$options": "i"}} - ) + {"albumartist": { + "$regex": query, + "$options": "i" + }}) return convert_many(songs) def get_song_by_path(self, path: str) -> dict: diff --git a/server/app/lib/folderslib.py b/server/app/lib/folderslib.py index bc8f0117..1035dd3d 100644 --- a/server/app/lib/folderslib.py +++ b/server/app/lib/folderslib.py @@ -1,6 +1,9 @@ import time from typing import List -from app import api, helpers, models + +from app import api +from app import helpers +from app import models from progress.bar import Bar diff --git a/server/app/lib/playlistlib.py b/server/app/lib/playlistlib.py index 102f7bb1..bbc8b7b1 100644 --- a/server/app/lib/playlistlib.py +++ b/server/app/lib/playlistlib.py @@ -35,7 +35,8 @@ def add_track(playlistid: str, trackid: str): try: playlist.add_track(track) - instances.playlist_instance.add_track_to_playlist(playlistid, track) + instances.playlist_instance.add_track_to_playlist( + playlistid, track) return except TrackExistsInPlaylist as error: raise error @@ -68,7 +69,8 @@ def create_thumbnail(image: any, img_path: str) -> str: Creates a 250 x 250 thumbnail from a playlist image """ thumb_path = "thumb_" + img_path - full_thumb_path = os.path.join(settings.APP_DIR, "images", "playlists", thumb_path) + full_thumb_path = os.path.join(settings.APP_DIR, "images", "playlists", + thumb_path) aspect_ratio = image.width / image.height @@ -86,11 +88,13 @@ def save_p_image(file: datastructures.FileStorage, pid: str): """ img = Image.open(file) - random_str = "".join(random.choices(string.ascii_letters + string.digits, k=5)) + random_str = "".join( + random.choices(string.ascii_letters + string.digits, k=5)) img_path = pid + str(random_str) + ".webp" - full_img_path = os.path.join(settings.APP_DIR, "images", "playlists", img_path) + full_img_path = os.path.join(settings.APP_DIR, "images", "playlists", + img_path) if file.content_type == "image/gif": frames = [] diff --git a/server/app/models.py b/server/app/models.py index 39800c65..e59a29d4 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -73,11 +73,9 @@ class Album: 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 - ): + if (track.title == ptrack["title"] + and track.artists == ptrack["artists"] + and ptrack["album"] == track.album): return track