mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +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 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
|
||||||
|
|
||||||
|
|||||||
@@ -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__)
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
+16
-16
@@ -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,9 +128,8 @@ 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,9 +151,8 @@ 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):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Track:
|
|||||||
discnumber: int
|
discnumber: int
|
||||||
|
|
||||||
def __init__(self, tags):
|
def __init__(self, tags):
|
||||||
|
|
||||||
self.trackid = tags["_id"]["$oid"]
|
self.trackid = tags["_id"]["$oid"]
|
||||||
self.title = tags["title"]
|
self.title = tags["title"]
|
||||||
self.artists = tags["artists"].split(", ")
|
self.artists = tags["artists"].split(", ")
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
# 2. create symbolic links for each file in sites-available to sites-enable
|
# 2. create symbolic links for each file in sites-available to sites-enable
|
||||||
|
|
||||||
sudo cp ./nginx-sites/* /etc/nginx/sites-available
|
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)
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user