diff --git a/server/app/api/__init__.py b/server/app/api/__init__.py index cdb68159..15a64f0e 100644 --- a/server/app/api/__init__.py +++ b/server/app/api/__init__.py @@ -13,7 +13,7 @@ from app.lib import folderslib from app.lib import playlistlib -DB_TRACKS = instances.songs_instance.get_all_songs() +PRE_TRACKS = instances.songs_instance.get_all_songs() VALID_FOLDERS: Set[str] = set() ALBUMS: List[models.Album] = [] diff --git a/server/app/api/album.py b/server/app/api/album.py index 2c94c5c1..af052de8 100644 --- a/server/app/api/album.py +++ b/server/app/api/album.py @@ -21,7 +21,7 @@ def get_albums(): """returns all the albums""" albums = [] - for song in api.DB_TRACKS: + for song in api.PRE_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 66a02804..ddecae4a 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -18,6 +18,7 @@ from mutagen.id3 import ID3 from mutagen.flac import FLAC from progress.bar import Bar from PIL import Image + # from pprint import pprint from app import helpers @@ -64,9 +65,13 @@ def populate(): s, files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"], full=True) _bar = Bar("Processing files", max=len(files)) + for file in files: tags = get_tags(file) + if tags not in api.PRE_TRACKS: + api.PRE_TRACKS.append(tags) + if tags is not None: instances.songs_instance.insert_song(tags) @@ -75,7 +80,7 @@ def populate(): albumslib.create_everything() folderslib.run_scandir() - + end = time.time() print( @@ -109,7 +114,7 @@ def populate_images(): artists = [] - for song in api.DB_TRACKS: + for song in api.PRE_TRACKS: this_artists = song["artists"].split(", ") for artist in this_artists: @@ -178,9 +183,9 @@ def return_album_art(filepath): def save_t_colors(): - _bar = Bar("Processing image colors", max=len(api.DB_TRACKS)) + _bar = Bar("Processing image colors", max=len(api.PRE_TRACKS)) - for track in api.DB_TRACKS: + for track in api.PRE_TRACKS: filepath = track["filepath"] album_art = return_album_art(filepath) @@ -376,12 +381,10 @@ def get_all_albums() -> List[models.Album]: """ Returns a list of album objects for all albums in the database. """ - print("processing albums started ...") - albums: List[models.Album] = [] - _bar = Bar("Creating albums", max=len(api.DB_TRACKS)) - for track in api.DB_TRACKS: + _bar = Bar("Creating albums", max=len(api.PRE_TRACKS)) + for track in api.PRE_TRACKS: xx = albumslib.create_album(track) if xx not in albums: albums.append(xx) diff --git a/server/app/lib/albumslib.py b/server/app/lib/albumslib.py index 23ea59dd..19bf2d2f 100644 --- a/server/app/lib/albumslib.py +++ b/server/app/lib/albumslib.py @@ -51,7 +51,7 @@ def get_album_image(album: list) -> str: def get_album_tracks(album: str, artist: str) -> List: return [ track - for track in api.DB_TRACKS + for track in api.PRE_TRACKS if track["album"] == album and track["albumartist"] == artist ] diff --git a/server/app/lib/folderslib.py b/server/app/lib/folderslib.py index ba9f2984..1e0bee3d 100644 --- a/server/app/lib/folderslib.py +++ b/server/app/lib/folderslib.py @@ -17,7 +17,6 @@ def get_folder_track_count(foldername: str) -> int: return len(track_list) - def create_folder(foldername: str) -> models.Folder: """Create a single Folder object""" folder = { @@ -55,7 +54,6 @@ def get_subdirs(foldername: str) -> List[models.Folder]: if str1 != "": subdirs.add(foldername + str1) - return [create_folder(dir) for dir in subdirs] @@ -65,16 +63,11 @@ 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 + It calls the """ - flag = False + get_valid_folders() + folders_ = create_all_folders() + """Create all the folder objects before clearing api.FOLDERS""" - while flag is False: - get_valid_folders() - folders_ = create_all_folders() - """Create all the folder objects before clearing api.FOLDERS""" - - api.FOLDERS.clear() - api.FOLDERS.extend(folders_) - - time.sleep(300) + api.FOLDERS.clear() + api.FOLDERS.extend(folders_) diff --git a/server/app/lib/trackslib.py b/server/app/lib/trackslib.py index 0579579b..5f7a0ec7 100644 --- a/server/app/lib/trackslib.py +++ b/server/app/lib/trackslib.py @@ -7,7 +7,7 @@ from typing import List from app import models, instances from app.lib import albumslib from app.helpers import remove_duplicates -from app import api, helpers +from app import api from progress.bar import Bar @@ -17,10 +17,9 @@ def create_all_tracks() -> List[models.Track]: """ tracks: list[models.Track] = [] - timer = helpers.Timer() - - _bar = Bar("Creating tracks", max=len(api.DB_TRACKS)) - for track in api.DB_TRACKS: + _bar = Bar("Creating tracks", max=len(api.PRE_TRACKS)) + + for track in api.PRE_TRACKS: try: os.chmod(track["filepath"], 0o755) except FileNotFoundError: @@ -33,10 +32,10 @@ def create_all_tracks() -> List[models.Track]: tracks.append(models.Track(track)) _bar.next() + _bar.finish() + api.TRACKS.clear() api.TRACKS.extend(tracks) - _bar.finish() - print(f"Created all songs in {timer.stop()}") def get_album_tracks(albumname, artist): @@ -53,5 +52,5 @@ def get_album_tracks(albumname, artist): def get_track_by_id(trackid: str) -> models.Track: """Returns api track matching an id""" for track in api.TRACKS: - if track.id == trackid: + if track.trackid == trackid: return track