move fetching album bio to a class

This commit is contained in:
geoffrey45
2022-05-10 13:17:01 +03:00
parent 8dfa6834ad
commit d52c8ac8fe
2 changed files with 23 additions and 14 deletions
+17 -8
View File
@@ -6,6 +6,7 @@ import time
from io import BytesIO
import requests
from tqdm import tqdm
from app import api
from app import helpers
from app import settings
@@ -73,15 +74,14 @@ def fetch_artist_images():
artists = []
for song in api.DB_TRACKS:
for song in tqdm(api.DB_TRACKS, desc="Gathering artists"):
this_artists = song["artists"].split(", ")
for artist in this_artists:
if artist not in artists:
artists.append(artist)
_bar = Bar("Processing images", max=len(artists))
for artist in artists:
for artist in tqdm(artists, desc="Fetching images"):
file_path = (
helpers.app_dir + "/images/artists/" + artist.replace("/", "::") + ".webp"
)
@@ -96,12 +96,8 @@ def fetch_artist_images():
except requests.exceptions.ConnectionError:
time.sleep(5)
_bar.next()
_bar.finish()
def fetch_album_bio(title: str, albumartist: str):
def fetch_album_bio(title: str, albumartist: str) -> str | None:
"""
Returns the album bio for a given album.
"""
@@ -123,6 +119,19 @@ def fetch_album_bio(title: str, albumartist: str):
return bio
class FetchAlbumBio:
"""
Returns the album bio for a given album.
"""
def __init__(self, title: str, albumartist: str):
self.title = title
self.albumartist = albumartist
def __call__(self):
return fetch_album_bio(self.title, self.albumartist)
# TODO
# - Move the populate function to a new file and probably into a new class
# - Start movement from functional programming to OOP to OOP