mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
Restyle Move populate to new file (#48)
This commit is contained in:
@@ -10,9 +10,9 @@ from app import api
|
||||
from app import helpers
|
||||
from app import settings
|
||||
from app.lib import watchdoge
|
||||
from app.lib.populate import Populate
|
||||
from PIL import Image
|
||||
from progress.bar import Bar
|
||||
from app.lib.populate import Populate
|
||||
|
||||
|
||||
@helpers.background
|
||||
@@ -76,9 +76,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)
|
||||
@@ -100,8 +99,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)
|
||||
@@ -110,7 +108,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
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
from typing import Tuple
|
||||
from flask import Flask, send_from_directory
|
||||
|
||||
from flask import Flask
|
||||
from flask import send_from_directory
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@@ -10,12 +10,11 @@ from app import api
|
||||
from app import functions
|
||||
from app import instances
|
||||
from app import models
|
||||
from app import settings
|
||||
from app.lib import taglib
|
||||
from app.lib import trackslib
|
||||
from progress.bar import Bar
|
||||
|
||||
from app.lib import taglib
|
||||
from app import settings
|
||||
|
||||
|
||||
def get_all_albums() -> List[models.Album]:
|
||||
"""
|
||||
@@ -66,7 +65,8 @@ def find_album(albumtitle: str, artist: str) -> int or None:
|
||||
iter += 1
|
||||
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
|
||||
|
||||
if api.ALBUMS[mid].title < albumtitle:
|
||||
@@ -155,8 +155,7 @@ def create_album(track) -> models.Album:
|
||||
album["date"] = album_tracks[0]["date"]
|
||||
|
||||
album["artistimage"] = urllib.parse.quote_plus(
|
||||
album_tracks[0]["albumartist"] + ".webp"
|
||||
)
|
||||
album_tracks[0]["albumartist"] + ".webp")
|
||||
|
||||
album["image"] = get_album_image(album_tracks)
|
||||
|
||||
|
||||
+16
-16
@@ -1,15 +1,18 @@
|
||||
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 app.lib.albumslib import find_album, create_album
|
||||
|
||||
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.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:
|
||||
@@ -105,8 +108,7 @@ class Populate:
|
||||
if index is None:
|
||||
try:
|
||||
track = [
|
||||
track
|
||||
for track in self.tagged_tracks
|
||||
track for track in self.tagged_tracks
|
||||
if track["album"] == album["title"]
|
||||
and track["albumartist"] == album["artist"]
|
||||
][0]
|
||||
@@ -126,9 +128,8 @@ class Populate:
|
||||
|
||||
bar.next()
|
||||
bar.finish()
|
||||
Log(
|
||||
f"{exist_count} of {len(self.pre_albums)} albums were already in the database"
|
||||
)
|
||||
Log(f"{exist_count} of {len(self.pre_albums)} albums were already in the database"
|
||||
)
|
||||
|
||||
def create_tracks(self):
|
||||
"""
|
||||
@@ -150,9 +151,8 @@ class Populate:
|
||||
bar.next()
|
||||
bar.finish()
|
||||
|
||||
Log(
|
||||
f"Added {len(self.tagged_tracks) - failed_count} of {len(self.tagged_tracks)} new tracks and {len(self.albums)} new albums"
|
||||
)
|
||||
Log(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):
|
||||
"""
|
||||
|
||||
@@ -32,7 +32,7 @@ class Track:
|
||||
discnumber: int
|
||||
|
||||
def __init__(self, tags):
|
||||
|
||||
|
||||
self.trackid = tags["_id"]["$oid"]
|
||||
self.title = tags["title"]
|
||||
self.artists = tags["artists"].split(", ")
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
# 2. create symbolic links for each file in sites-available to sites-enable
|
||||
|
||||
sudo cp ./nginx-sites/* /etc/nginx/sites-available
|
||||
sudo ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled -f
|
||||
sudo ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled -f
|
||||
|
||||
+2
-3
@@ -6,8 +6,7 @@
|
||||
|
||||
gpath=$(poetry run which gunicorn)
|
||||
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"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user