break settings.py into classes

This commit is contained in:
geoffrey45
2023-03-26 08:25:00 +03:00
parent 79029ae346
commit 357afeb700
22 changed files with 102 additions and 96 deletions
+5 -5
View File
@@ -42,8 +42,8 @@ def get_artist_image_link(artist: str):
# TODO: Move network calls to utils/network.py
class DownloadImage:
def __init__(self, url: str, name: str) -> None:
sm_path = Path(settings.ARTIST_IMG_SM_PATH) / name
lg_path = Path(settings.ARTIST_IMG_LG_PATH) / name
sm_path = Path(settings.Paths.ARTIST_IMG_SM_PATH) / name
lg_path = Path(settings.Paths.ARTIST_IMG_LG_PATH) / name
img = self.download(url)
@@ -64,7 +64,7 @@ class DownloadImage:
"""
img.save(lg_path, format="webp")
sm_size = settings.SM_ARTIST_IMG_SIZE
sm_size = settings.Defaults.SM_ARTIST_IMG_SIZE
img.resize((sm_size, sm_size), Image.ANTIALIAS).save(sm_path, format="webp")
@@ -86,7 +86,7 @@ class CheckArtistImages:
:param artist: The artist name
"""
img_path = Path(settings.ARTIST_IMG_SM_PATH) / f"{artist.artisthash}.webp"
img_path = Path(settings.Paths.ARTIST_IMG_SM_PATH) / f"{artist.artisthash}.webp"
if img_path.exists():
return
@@ -99,7 +99,7 @@ class CheckArtistImages:
# def fetch_album_bio(title: str, albumartist: str) -> str | None: """ Returns the album bio for a given album. """
# last_fm_url = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key={}&artist={}&album={
# }&format=json".format( settings.LAST_FM_API_KEY, albumartist, title )
# }&format=json".format( settings.Paths.LAST_FM_API_KEY, albumartist, title )
# try:
# response = requests.get(last_fm_url)
+2 -2
View File
@@ -56,7 +56,7 @@ class ProcessAlbumColors:
@staticmethod
def process_color(album: Album):
path = Path(settings.SM_THUMB_PATH) / album.image
path = Path(settings.Paths.SM_THUMB_PATH) / album.image
if not path.exists():
return
@@ -78,7 +78,7 @@ class ProcessArtistColors:
@staticmethod
def process_color(artist: Artist):
path = Path(settings.ARTIST_IMG_SM_PATH) / artist.image
path = Path(settings.Paths.ARTIST_IMG_SM_PATH) / artist.image
if not path.exists():
return
+3 -3
View File
@@ -16,7 +16,7 @@ def create_thumbnail(image: Any, img_path: str) -> str:
Creates a 250 x 250 thumbnail from a playlist image
"""
thumb_path = "thumb_" + img_path
full_thumb_path = os.path.join(settings.APP_DIR, "images", "playlists", thumb_path)
full_thumb_path = os.path.join(settings.Paths.APP_DIR, "images", "playlists", thumb_path)
aspect_ratio = image.width / image.height
@@ -33,7 +33,7 @@ def create_gif_thumbnail(image: Any, img_path: str):
Creates a 250 x 250 thumbnail from a playlist image
"""
thumb_path = "thumb_" + img_path
full_thumb_path = os.path.join(settings.APP_DIR, "images", "playlists", thumb_path)
full_thumb_path = os.path.join(settings.Paths.APP_DIR, "images", "playlists", thumb_path)
frames = []
@@ -60,7 +60,7 @@ def save_p_image(file, pid: str):
filename = pid + str(random_str) + ".webp"
full_img_path = os.path.join(settings.PLAYLIST_IMG_PATH, filename)
full_img_path = os.path.join(settings.Paths.PLAYLIST_IMG_PATH, filename)
if file.content_type == "image/gif":
frames = []
+1 -1
View File
@@ -55,7 +55,7 @@ class Populate:
try:
if dirs_to_scan[0] == "$home":
dirs_to_scan = [settings.USER_HOME_DIR]
dirs_to_scan = [settings.Paths.USER_HOME_DIR]
except IndexError:
pass
+5 -5
View File
@@ -5,7 +5,7 @@ from io import BytesIO
from PIL import Image, UnidentifiedImageError
from tinytag import TinyTag
from app import settings
from app.settings import Defaults, Paths
from app.utils.hashing import create_hash
from app.utils.parsers import parse_title_from_filename, parse_artist_from_filename
from app.utils.wintools import win_replace_slash
@@ -27,11 +27,11 @@ def extract_thumb(filepath: str, webp_path: str) -> bool:
"""
Extracts the thumbnail from an audio file. Returns the path to the thumbnail.
"""
img_path = os.path.join(settings.LG_THUMBS_PATH, webp_path)
sm_img_path = os.path.join(settings.SM_THUMB_PATH, webp_path)
img_path = os.path.join(Paths.LG_THUMBS_PATH, webp_path)
sm_img_path = os.path.join(Paths.SM_THUMB_PATH, webp_path)
tsize = settings.THUMB_SIZE
sm_tsize = settings.SM_THUMB_SIZE
tsize = Defaults.THUMB_SIZE
sm_tsize = Defaults.SM_THUMB_SIZE
def save_image(img: Image.Image):
img.resize((sm_tsize, sm_tsize), Image.ANTIALIAS).save(sm_img_path, "webp")
+1 -1
View File
@@ -70,7 +70,7 @@ class Watcher:
# dirs = [settings.USER_HOME_DIR]
if any([d == "$home" for d in dirs]):
dirs = [settings.USER_HOME_DIR]
dirs = [settings.Paths.USER_HOME_DIR]
event_handler = Handler(root_dirs=dirs, dir_map=dir_map)