diff --git a/server/app/functions.py b/server/app/functions.py index 7d5509bf..561760be 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -27,7 +27,9 @@ def reindex_tracks(): Populate() CreateAlbums() - CheckArtistImages()() + + if helpers.Ping()(): + CheckArtistImages()() time.sleep(60) @@ -73,7 +75,6 @@ class useImageDownloader: img.save(self.dest, format="webp") img.close() except requests.exceptions.ConnectionError: - print("🔴🔴🔴🔴🔴🔴🔴") time.sleep(5) @@ -102,7 +103,7 @@ class CheckArtistImages: """ img_path = ( - helpers.app_dir + settings.APP_DIR + "/images/artists/" + helpers.create_safe_name(artistname) + ".webp" @@ -115,14 +116,15 @@ class CheckArtistImages: if url is None: return - useImageDownloader(url, img_path)() def __call__(self): self.artists = helpers.Get.get_all_artists() with ThreadPoolExecutor() as pool: - pool.map(self.download_image, self.artists) + iter = pool.map(self.download_image, self.artists) + for i in iter: + pass print("Done fetching images") diff --git a/server/app/helpers.py b/server/app/helpers.py index ea11a63b..102e2b49 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -8,12 +8,12 @@ from datetime import datetime from typing import Dict, Set from typing import List +import requests + from app import models from app import settings from app import instances -app_dir = settings.APP_DIR - def background(func): """ @@ -73,6 +73,7 @@ def remove_duplicates(tracklist: List[models.Track]) -> List[models.Track]: return tracklist + def is_valid_file(filename: str) -> bool: """ Checks if a file is valid. Returns True if it is, False if it isn't. @@ -97,7 +98,7 @@ def check_artist_image(image: str) -> str: Checks if the artist image is valid. """ img_name = image.replace("/", "::") + ".webp" - + app_dir = settings.APP_DIR if not os.path.exists(os.path.join(app_dir, "images", "artists", img_name)): return use_memoji() else: @@ -194,3 +195,15 @@ class Get: """ p = instances.playlist_instance.get_all_playlists() return [models.Playlist(p) for p in p] + + +class Ping: + """Checks if there is a connection to the internet by pinging google.com""" + + @staticmethod + def __call__() -> bool: + try: + requests.get("https://google.com") + return True + except requests.exceptions.ConnectionError: + return False diff --git a/server/app/lib/folderslib.py b/server/app/lib/folderslib.py index 81217298..b5872736 100644 --- a/server/app/lib/folderslib.py +++ b/server/app/lib/folderslib.py @@ -14,11 +14,11 @@ class Dir: is_sym: bool -def get_folder_track_count(foldername: str) -> int: +def get_folder_track_count(path: str) -> int: """ Returns the number of files associated with a folder. """ - tracks = instances.tracks_instance.find_tracks_inside_path_regex(foldername) + tracks = instances.tracks_instance.find_tracks_inside_path_regex(path) return len(tracks) diff --git a/server/app/lib/populate.py b/server/app/lib/populate.py index 5ca7d31c..6fa2aead 100644 --- a/server/app/lib/populate.py +++ b/server/app/lib/populate.py @@ -89,10 +89,23 @@ class CreateAlbums: prealbums = self.filter_processed(self.db_albums, prealbums) print(f"📌 {len(prealbums)}") + s = time.time() albums = [] + for album in tqdm(prealbums, desc="Creating albums"): a = self.create_album(album) - albums.append(a) + if a is not None: + albums.append(a) + + # with ThreadPoolExecutor() as pool: + # iterator = pool.map(self.create_album, prealbums) + + # for i in iterator: + # if i is not None: + # albums.append(i) + + d = time.time() - s + Log(f"Created {len(albums)} albums in {d} seconds") if len(albums) > 0: instances.album_instance.insert_many(albums) @@ -131,15 +144,20 @@ class CreateAlbums: hash = album.hash album = {"image": None} + iter = 0 while album["image"] is None: track = UseBisection(self.db_tracks, "albumhash", [hash])()[0] if track is not None: + iter += 1 album = create_album(track) self.db_tracks.remove(track) else: album["image"] = hash - - album = Album(album) - return album + try: + album = Album(album) + return album + except KeyError: + print(f"📌 {iter}") + print(album) diff --git a/server/assets/default.webp b/server/assets/default.webp new file mode 100644 index 00000000..d9795fa9 Binary files /dev/null and b/server/assets/default.webp differ diff --git a/server/start.sh b/server/start.sh index 2bac5a6a..c6c0e46a 100755 --- a/server/start.sh +++ b/server/start.sh @@ -8,7 +8,7 @@ gpath=$(poetry run which gunicorn) while getopts ':s' opt; do case $opt in s) - echo "🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴" + echo "Starting Alice server" cd "./app" "$gpath" -b 0.0.0.0:9877 -w 4 --threads=2 "imgserver:app" & cd ../