diff --git a/server/app/__init__.py b/server/app/__init__.py index 06f7e209..a1331bc6 100644 --- a/server/app/__init__.py +++ b/server/app/__init__.py @@ -19,13 +19,14 @@ def create_app(): cache.init_app(app) with app.app_context(): - from app.api import artist, track, search, folder, album + from app.api import artist, track, search, folder, album, playlist app.register_blueprint(album.album_bp, url_prefix="/") app.register_blueprint(artist.artist_bp, url_prefix="/") app.register_blueprint(track.track_bp, url_prefix="/") app.register_blueprint(search.search_bp, url_prefix="/") app.register_blueprint(folder.folder_bp, url_prefix="/") + app.register_blueprint(playlist.playlist_bp, url_prefix="/") return app diff --git a/server/app/api/__init__.py b/server/app/api/__init__.py index f863d7e4..cdb68159 100644 --- a/server/app/api/__init__.py +++ b/server/app/api/__init__.py @@ -10,6 +10,7 @@ from app import models, instances from app import functions, helpers, prep from app.lib import albumslib from app.lib import folderslib +from app.lib import playlistlib DB_TRACKS = instances.songs_instance.get_all_songs() @@ -20,6 +21,7 @@ TRACKS: List[models.Track] = [] PLAYLISTS: List[models.Playlist] = [] FOLDERS: List[models.Folder] = [] + @helpers.background def initialize() -> None: """ @@ -29,8 +31,8 @@ def initialize() -> None: prep.create_config_dir() albumslib.create_everything() folderslib.run_scandir() + playlistlib.create_all_playlists() functions.reindex_tracks() initialize() - diff --git a/server/app/api/folder.py b/server/app/api/folder.py index 42b77374..a02b1e95 100644 --- a/server/app/api/folder.py +++ b/server/app/api/folder.py @@ -30,7 +30,7 @@ def get_folder_tree(): songs = [] for track in api.TRACKS: - if track.folder + "/" == req_dir: + if track.folder == req_dir: songs.append(track) final_tracks = helpers.remove_duplicates(songs) diff --git a/server/app/api/playlist.py b/server/app/api/playlist.py index d8618a8b..f6d20dc0 100644 --- a/server/app/api/playlist.py +++ b/server/app/api/playlist.py @@ -11,22 +11,24 @@ playlist_bp = Blueprint("playlist", __name__, url_prefix="/") @playlist_bp.route("/playlists", methods=["GET"]) def get_all_playlists(): + print(api.PLAYLISTS) playlists = [] + for playlist in api.PLAYLISTS: - del playlist.tracks + playlist.tracks = [] playlists.append(playlist) - return playlists + return {"data": playlists} -@playlist_bp.route("/playlist/new") +@playlist_bp.route("/playlist/new", methods=["POST"]) def create_playlist(): data = request.get_json() - playlist = {"name": data["name"], "description": data["description"], "tracks": []} + playlist = {"name": data["name"], "description": [], "tracks": []} instances.playlist_instance.insert_playlist(playlist) - return 200 + return {"msg": "success"} @playlist_bp.route("/playlist//add", methods=["POST"]) diff --git a/server/app/functions.py b/server/app/functions.py index ae9cbb70..66a02804 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -26,6 +26,7 @@ from app import settings, models from app.lib import albumslib from app import api from app.lib import watchdoge +from app.lib import folderslib @helpers.background @@ -61,7 +62,6 @@ def populate(): start = time.time() s, files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"], full=True) - # pprint(s) _bar = Bar("Processing files", max=len(files)) for file in files: @@ -74,7 +74,8 @@ def populate(): _bar.finish() albumslib.create_everything() - + folderslib.run_scandir() + end = time.time() print( @@ -340,7 +341,7 @@ def get_tags(fullpath: str) -> dict: "length": round(audio.info.length), "bitrate": round(int(audio.info.bitrate) / 1000), "filepath": fullpath, - "folder": os.path.dirname(fullpath), + "folder": os.path.dirname(fullpath) + "/", } return tags diff --git a/server/app/lib/folderslib.py b/server/app/lib/folderslib.py index 4411b4dd..ba9f2984 100644 --- a/server/app/lib/folderslib.py +++ b/server/app/lib/folderslib.py @@ -29,11 +29,11 @@ def create_folder(foldername: str) -> models.Folder: return models.Folder(folder) -def create_all_folders(foldernames: List[str]) -> List[models.Folder]: +def create_all_folders() -> List[models.Folder]: folders_: List[models.Folder] = [] - _bar = Bar("Creating folders", max=len(foldernames)) + _bar = Bar("Creating folders", max=len(api.VALID_FOLDERS)) - for foldername in foldernames: + for foldername in api.VALID_FOLDERS: folder = create_folder(foldername) folders_.append(folder) _bar.next() @@ -61,11 +61,17 @@ def get_subdirs(foldername: str) -> List[models.Folder]: @helpers.background def run_scandir(): + """ + Initiates the creation of all folder objects for each folder with a track in it. + + Runs in a background thread after every 5 minutes. + It calls the + """ flag = False while flag is False: get_valid_folders() - folders_ = create_all_folders(api.VALID_FOLDERS) + folders_ = create_all_folders() """Create all the folder objects before clearing api.FOLDERS""" api.FOLDERS.clear() diff --git a/src/App.vue b/src/App.vue index d913b1f1..9be2d5f8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,7 @@