Restyle Save complete albums to the db for faster startup (#38)

This commit is contained in:
restyled-io[bot]
2022-04-21 10:25:56 +03:00
committed by GitHub
parent d98cc0547e
commit d1c83ef8b6
15 changed files with 82 additions and 76 deletions
+13 -16
View File
@@ -1,11 +1,11 @@
"""
This module contains functions for the server
"""
from dataclasses import asdict
import datetime
import os
import random
import time
from dataclasses import asdict
from io import BytesIO
from typing import List
@@ -18,12 +18,12 @@ from app import settings
from app.lib import albumslib
from app.lib import folderslib
from app.lib import watchdoge
from app.lib.taglib import get_tags
from app.lib.taglib import return_album_art
from app.logger import Log
from PIL import Image
from progress.bar import Bar
from app.logger import Log
from app.lib.taglib import get_tags, return_album_art
@helpers.background
def reindex_tracks():
@@ -60,7 +60,8 @@ def populate():
albums = []
folders = set()
files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"], full=True)[1]
files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"],
full=True)[1]
_bar = Bar("Checking files", max=len(files))
for track in db_tracks:
@@ -128,11 +129,8 @@ def populate():
end = time.time()
print(
str(datetime.timedelta(seconds=round(end - start)))
+ " elapsed for "
+ str(len(files))
+ " files"
)
str(datetime.timedelta(seconds=round(end - start))) + " elapsed for " +
str(len(files)) + " files")
def fetch_image_path(artist: str) -> str or None:
@@ -167,9 +165,8 @@ def fetch_artist_images():
_bar = Bar("Processing images", max=len(artists))
for artist in artists:
file_path = (
helpers.app_dir + "/images/artists/" + artist.replace("/", "::") + ".webp"
)
file_path = (helpers.app_dir + "/images/artists/" +
artist.replace("/", "::") + ".webp")
if not os.path.exists(file_path):
img_path = fetch_image_path(artist)
@@ -191,8 +188,7 @@ def fetch_album_bio(title: str, albumartist: str):
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
)
settings.LAST_FM_API_KEY, albumartist, title)
try:
response = requests.get(last_fm_url)
@@ -201,7 +197,8 @@ def fetch_album_bio(title: str, albumartist: str):
return None
try:
bio = data["album"]["wiki"]["summary"].split('<a href="https://www.last.fm/')[0]
bio = data["album"]["wiki"]["summary"].split(
'<a href="https://www.last.fm/')[0]
except KeyError:
bio = None