send processing album colors to a background thread

- use white color as default album page play button color
- return 404 if album is None on get_album_bio()
This commit is contained in:
geoffrey45
2022-07-02 08:21:10 +03:00
committed by Mungai Geoffrey
parent 34a214df22
commit 77a5d2b7c2
7 changed files with 44 additions and 68 deletions
+6 -1
View File
@@ -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}
+16 -7
View File
@@ -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")
+1 -1
View File
@@ -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