Restyle Move populate to new file (#48)

This commit is contained in:
restyled-io[bot]
2022-05-04 01:42:26 +03:00
committed by GitHub
parent 4c09350b41
commit 559b36bd7b
7 changed files with 34 additions and 35 deletions
+6 -7
View File
@@ -10,9 +10,9 @@ from app import api
from app import helpers from app import helpers
from app import settings from app import settings
from app.lib import watchdoge from app.lib import watchdoge
from app.lib.populate import Populate
from PIL import Image from PIL import Image
from progress.bar import Bar from progress.bar import Bar
from app.lib.populate import Populate
@helpers.background @helpers.background
@@ -76,9 +76,8 @@ def fetch_artist_images():
_bar = Bar("Processing images", max=len(artists)) _bar = Bar("Processing images", max=len(artists))
for artist in artists: for artist in artists:
file_path = ( file_path = (helpers.app_dir + "/images/artists/" +
helpers.app_dir + "/images/artists/" + artist.replace("/", "::") + ".webp" artist.replace("/", "::") + ".webp")
)
if not os.path.exists(file_path): if not os.path.exists(file_path):
img_path = fetch_image_path(artist) img_path = fetch_image_path(artist)
@@ -100,8 +99,7 @@ def fetch_album_bio(title: str, albumartist: str):
Returns the album bio for a given album. 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( 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: try:
response = requests.get(last_fm_url) response = requests.get(last_fm_url)
@@ -110,7 +108,8 @@ def fetch_album_bio(title: str, albumartist: str):
return None return None
try: 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: except KeyError:
bio = None bio = None
+3 -1
View File
@@ -1,6 +1,8 @@
import os import os
from typing import Tuple from typing import Tuple
from flask import Flask, send_from_directory
from flask import Flask
from flask import send_from_directory
app = Flask(__name__) app = Flask(__name__)
+5 -6
View File
@@ -10,12 +10,11 @@ from app import api
from app import functions from app import functions
from app import instances from app import instances
from app import models from app import models
from app import settings
from app.lib import taglib
from app.lib import trackslib from app.lib import trackslib
from progress.bar import Bar from progress.bar import Bar
from app.lib import taglib
from app import settings
def get_all_albums() -> List[models.Album]: def get_all_albums() -> List[models.Album]:
""" """
@@ -66,7 +65,8 @@ def find_album(albumtitle: str, artist: str) -> int or None:
iter += 1 iter += 1
mid = (left + right) // 2 mid = (left + right) // 2
if api.ALBUMS[mid].title == albumtitle and api.ALBUMS[mid].artist == artist: if api.ALBUMS[mid].title == albumtitle and api.ALBUMS[
mid].artist == artist:
return mid return mid
if api.ALBUMS[mid].title < albumtitle: if api.ALBUMS[mid].title < albumtitle:
@@ -155,8 +155,7 @@ def create_album(track) -> models.Album:
album["date"] = album_tracks[0]["date"] album["date"] = album_tracks[0]["date"]
album["artistimage"] = urllib.parse.quote_plus( album["artistimage"] = urllib.parse.quote_plus(
album_tracks[0]["albumartist"] + ".webp" album_tracks[0]["albumartist"] + ".webp")
)
album["image"] = get_album_image(album_tracks) album["image"] = get_album_image(album_tracks)
+14 -14
View File
@@ -1,15 +1,18 @@
from dataclasses import asdict from dataclasses import asdict
from app.helpers import run_fast_scandir
from app import settings
from app.instances import tracks_instance, album_instance
from progress.bar import Bar
from app.logger import Log
from app.lib.taglib import get_tags
from os import path from os import path
from app.lib.albumslib import find_album, create_album
from app import api from app import api
from app.models import Track from app import settings
from app.helpers import run_fast_scandir
from app.instances import album_instance
from app.instances import tracks_instance
from app.lib import folderslib from app.lib import folderslib
from app.lib.albumslib import create_album
from app.lib.albumslib import find_album
from app.lib.taglib import get_tags
from app.logger import Log
from app.models import Track
from progress.bar import Bar
class Populate: class Populate:
@@ -105,8 +108,7 @@ class Populate:
if index is None: if index is None:
try: try:
track = [ track = [
track track for track in self.tagged_tracks
for track in self.tagged_tracks
if track["album"] == album["title"] if track["album"] == album["title"]
and track["albumartist"] == album["artist"] and track["albumartist"] == album["artist"]
][0] ][0]
@@ -126,8 +128,7 @@ class Populate:
bar.next() bar.next()
bar.finish() bar.finish()
Log( Log(f"{exist_count} of {len(self.pre_albums)} albums were already in the database"
f"{exist_count} of {len(self.pre_albums)} albums were already in the database"
) )
def create_tracks(self): def create_tracks(self):
@@ -150,8 +151,7 @@ class Populate:
bar.next() bar.next()
bar.finish() bar.finish()
Log( Log(f"Added {len(self.tagged_tracks) - failed_count} of {len(self.tagged_tracks)} new tracks and {len(self.albums)} new albums"
f"Added {len(self.tagged_tracks) - failed_count} of {len(self.tagged_tracks)} new tracks and {len(self.albums)} new albums"
) )
def create_folders(self): def create_folders(self):
+2 -3
View File
@@ -6,8 +6,7 @@
gpath=$(poetry run which gunicorn) gpath=$(poetry run which gunicorn)
cd app cd app
$gpath -b 0.0.0.0:9877 -w 4 --threads=2 "imgserver:app" & "$gpath" -b 0.0.0.0:9877 -w 4 --threads=2 "imgserver:app" &
echo "Booted image server" echo "Booted image server"
cd ../ cd ../
$gpath -b 0.0.0.0:9876 -w 1 --threads=4 "manage:create_app()" #--log-level=debug "$gpath" -b 0.0.0.0:9876 -w 1 --threads=4 "manage:create_app()" #--log-level=debug