diff --git a/server/app/api/album.py b/server/app/api/album.py index f4ec080e..1a616a70 100644 --- a/server/app/api/album.py +++ b/server/app/api/album.py @@ -80,12 +80,17 @@ def get_album_bio(): """Returns the album bio for the given album.""" data = request.get_json() album_hash = data["hash"] + err_msg = {"bio": "No bio found"} album = instances.album_instance.find_album_by_hash(album_hash) + + if album is None: + return err_msg, 404 + bio = FetchAlbumBio(album["title"], album["artist"])() if bio is None: - return {"bio": "No bio found."}, 404 + return err_msg, 404 return {"bio": bio} diff --git a/server/app/functions.py b/server/app/functions.py index 4bccdd64..3e8ab7e8 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -16,13 +16,16 @@ from app.lib import trackslib from app.lib.populate import CreateAlbums, Populate from app.lib.playlistlib import ValidatePlaylistThumbs from app.lib.colorlib import ProcessAlbumColors +from app.logger import get_logger +log = get_logger() @helpers.background def run_checks(): """ Checks for new songs every 5 minutes. """ + ValidateAlbumThumbs() while True: trackslib.validate_tracks() @@ -33,9 +36,12 @@ def run_checks(): if helpers.Ping()(): CheckArtistImages()() - ValidateAlbumThumbs() + @helpers.background + def process_album_colors(): + ProcessAlbumColors() + ValidatePlaylistThumbs() - ProcessAlbumColors() + process_album_colors() time.sleep(300) @@ -80,14 +86,17 @@ class useImageDownloader: img = Image.open(BytesIO(requests.get(self.url).content)) img.save(self.dest, format="webp") img.close() + return "fetched image" except requests.exceptions.ConnectionError: time.sleep(5) + return "connection error" class CheckArtistImages: def __init__(self): self.artists: list[str] = [] print("Checking for artist images") + log.info("Checking artist images") @staticmethod def check_if_exists(img_path: str): @@ -116,21 +125,21 @@ class CheckArtistImages: ) if cls.check_if_exists(img_path): - return + return "exists" url = getArtistImage(artistname)() if url is None: - return - useImageDownloader(url, img_path)() + return "url is none" + + return useImageDownloader(url, img_path)() def __call__(self): self.artists = helpers.Get.get_all_artists() with ThreadPoolExecutor() as pool: iter = pool.map(self.download_image, self.artists) - for i in iter: - pass + [print(i) for i in iter] print("Done fetching images") diff --git a/server/app/lib/populate.py b/server/app/lib/populate.py index 417e5e7a..81c8774f 100644 --- a/server/app/lib/populate.py +++ b/server/app/lib/populate.py @@ -144,7 +144,7 @@ class CreateAlbums: album = create_album(track) self.db_tracks.remove(track) else: - album["image"] = hash + album["image"] = hash + ".webp" try: album = Album(album) return album diff --git a/src/components/AlbumView/Header.vue b/src/components/AlbumView/Header.vue index 270a4899..91975789 100644 --- a/src/components/AlbumView/Header.vue +++ b/src/components/AlbumView/Header.vue @@ -78,16 +78,14 @@ function isLight(rgb: string = props.album.colors[0]) { const [r, g, b] = rgb.match(/\d+/g)!.map(Number); const brightness = (r * 299 + g * 587 + b * 114) / 1000; - return brightness > 170; + return brightness > 150; } function getButtonColor(colors: string[] = props.album.colors) { const base_color = colors[0]; - console.log(colors.length); - if (colors.length === 0) return { color: "#000" }; + if (colors.length === 0) return { color: "#fff", isDark: true }; for (let i = 0; i < colors.length; i++) { - // if (isLight(colors[i])) break; if (theyContrast(base_color, colors[i])) { return { color: colors[i], @@ -97,7 +95,8 @@ function getButtonColor(colors: string[] = props.album.colors) { } return { - color: "#000", + color: "#fff", + isDark: true, }; } @@ -124,10 +123,6 @@ function rgbToArray(rgb: string) { function theyContrast(color1: string, color2: string) { return contrast(rgbToArray(color1), rgbToArray(color2)) > 3; } - -console.log( - contrast(rgbToArray(props.album.colors[0]), rgbToArray(props.album.colors[3])) -);