mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
Restyle New album page design (#76)
This commit is contained in:
committed by
Mungai Geoffrey
parent
7d59993203
commit
714775a67e
@@ -6,12 +6,12 @@ from typing import List
|
||||
|
||||
from app import api
|
||||
from app import helpers
|
||||
from app import instances
|
||||
from app import models
|
||||
from app.functions import FetchAlbumBio
|
||||
from app.lib import albumslib
|
||||
from flask import Blueprint
|
||||
from flask import request
|
||||
from app.functions import FetchAlbumBio
|
||||
from app import instances
|
||||
|
||||
album_bp = Blueprint("album", __name__, url_prefix="")
|
||||
|
||||
@@ -64,12 +64,8 @@ def get_album():
|
||||
except AttributeError:
|
||||
album.duration = 0
|
||||
|
||||
if (
|
||||
album.count == 1
|
||||
and tracks[0].title == album.title
|
||||
and tracks[0].tracknumber == 1
|
||||
and tracks[0].disknumber == 1
|
||||
):
|
||||
if (album.count == 1 and tracks[0].title == album.title
|
||||
and tracks[0].tracknumber == 1 and tracks[0].disknumber == 1):
|
||||
album.is_single = True
|
||||
|
||||
return {"tracks": tracks, "info": album}
|
||||
|
||||
@@ -3,14 +3,14 @@ Contains all the search routes.
|
||||
"""
|
||||
from pprint import pprint
|
||||
from typing import List
|
||||
|
||||
from app import helpers
|
||||
from app import models
|
||||
from app import serializer
|
||||
from app.lib import searchlib
|
||||
from flask import Blueprint
|
||||
from flask import request
|
||||
|
||||
from app import models
|
||||
from app import serializer
|
||||
|
||||
search_bp = Blueprint("search", __name__, url_prefix="/")
|
||||
|
||||
SEARCH_RESULTS = {
|
||||
@@ -197,20 +197,20 @@ def search_load_more():
|
||||
if type == "tracks":
|
||||
t = SearchResults.tracks
|
||||
return {
|
||||
"tracks": t[index : index + 5],
|
||||
"tracks": t[index:index + 5],
|
||||
"more": len(t) > index + 5,
|
||||
}
|
||||
|
||||
elif type == "albums":
|
||||
a = SearchResults.albums
|
||||
return {
|
||||
"albums": a[index : index + 6],
|
||||
"albums": a[index:index + 6],
|
||||
"more": len(a) > index + 6,
|
||||
}
|
||||
|
||||
elif type == "artists":
|
||||
a = SearchResults.artists
|
||||
return {
|
||||
"artists": a[index : index + 6],
|
||||
"artists": a[index:index + 6],
|
||||
"more": len(a) > index + 6,
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ This file contains the Album class for interacting with
|
||||
album documents in MongoDB.
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
from app.db.mongodb import convert_many
|
||||
from app.db.mongodb import convert_one
|
||||
from app.db.mongodb import MongoAlbums
|
||||
@@ -21,8 +22,13 @@ class Albums(MongoAlbums):
|
||||
"""
|
||||
album = album.__dict__
|
||||
return self.collection.update_one(
|
||||
{"album": album["title"], "artist": album["artist"]},
|
||||
{"$set": album},
|
||||
{
|
||||
"album": album["title"],
|
||||
"artist": album["artist"]
|
||||
},
|
||||
{
|
||||
"$set": album
|
||||
},
|
||||
upsert=True,
|
||||
).upserted_id
|
||||
|
||||
@@ -67,5 +73,7 @@ class Albums(MongoAlbums):
|
||||
"""
|
||||
self.collection.update_one(
|
||||
{"hash": hash},
|
||||
{"$set": {"colors": colors}},
|
||||
{"$set": {
|
||||
"colors": colors
|
||||
}},
|
||||
)
|
||||
|
||||
+15
-15
@@ -7,19 +7,21 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from PIL import Image
|
||||
|
||||
from app import helpers, settings
|
||||
from app import helpers
|
||||
from app import settings
|
||||
from app.lib import trackslib
|
||||
from app.lib import watchdoge
|
||||
from app.lib.albumslib import ValidateAlbumThumbs
|
||||
from app.lib import trackslib
|
||||
from app.lib.populate import CreateAlbums, Populate
|
||||
from app.lib.playlistlib import ValidatePlaylistThumbs
|
||||
from app.lib.colorlib import ProcessAlbumColors
|
||||
from app.lib.playlistlib import ValidatePlaylistThumbs
|
||||
from app.lib.populate import CreateAlbums
|
||||
from app.lib.populate import Populate
|
||||
from app.logger import get_logger
|
||||
from PIL import Image
|
||||
|
||||
log = get_logger()
|
||||
|
||||
|
||||
@helpers.background
|
||||
def run_checks():
|
||||
"""
|
||||
@@ -77,6 +79,7 @@ class getArtistImage:
|
||||
|
||||
|
||||
class useImageDownloader:
|
||||
|
||||
def __init__(self, url: str, dest: str) -> None:
|
||||
self.url = url
|
||||
self.dest = dest
|
||||
@@ -93,6 +96,7 @@ class useImageDownloader:
|
||||
|
||||
|
||||
class CheckArtistImages:
|
||||
|
||||
def __init__(self):
|
||||
self.artists: list[str] = []
|
||||
print("Checking for artist images")
|
||||
@@ -117,12 +121,8 @@ class CheckArtistImages:
|
||||
:param artistname: The artist name
|
||||
"""
|
||||
|
||||
img_path = (
|
||||
settings.APP_DIR
|
||||
+ "/images/artists/"
|
||||
+ helpers.create_safe_name(artistname)
|
||||
+ ".webp"
|
||||
)
|
||||
img_path = (settings.APP_DIR + "/images/artists/" +
|
||||
helpers.create_safe_name(artistname) + ".webp")
|
||||
|
||||
if cls.check_if_exists(img_path):
|
||||
return "exists"
|
||||
@@ -149,8 +149,7 @@ 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
|
||||
)
|
||||
settings.LAST_FM_API_KEY, albumartist, title)
|
||||
|
||||
try:
|
||||
response = requests.get(last_fm_url)
|
||||
@@ -159,7 +158,8 @@ def fetch_album_bio(title: str, albumartist: str) -> str | None:
|
||||
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
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ This module contains mini functions for the server.
|
||||
import os
|
||||
import threading
|
||||
from datetime import datetime
|
||||
from typing import Dict, Set
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Set
|
||||
|
||||
import requests
|
||||
|
||||
from app import models
|
||||
from app import instances
|
||||
from app import models
|
||||
|
||||
|
||||
def background(func):
|
||||
@@ -51,6 +51,7 @@ def run_fast_scandir(__dir: str, full=False) -> Dict[List[str], List[str]]:
|
||||
|
||||
|
||||
class RemoveDuplicates:
|
||||
|
||||
def __init__(self, tracklist: List[models.Track]) -> None:
|
||||
self.tracklist = tracklist
|
||||
|
||||
@@ -102,7 +103,8 @@ class UseBisection:
|
||||
items.
|
||||
"""
|
||||
|
||||
def __init__(self, source: List, search_from: str, queries: List[str]) -> None:
|
||||
def __init__(self, source: List, search_from: str,
|
||||
queries: List[str]) -> None:
|
||||
self.source_list = source
|
||||
self.queries_list = queries
|
||||
self.attr = search_from
|
||||
@@ -132,6 +134,7 @@ class UseBisection:
|
||||
|
||||
|
||||
class Get:
|
||||
|
||||
@staticmethod
|
||||
def get_all_tracks() -> List[models.Track]:
|
||||
"""
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import colorgram
|
||||
from app import instances
|
||||
|
||||
|
||||
from app.helpers import Get
|
||||
from app import settings
|
||||
from app.models import Album
|
||||
from app.helpers import Get
|
||||
from app.logger import get_logger
|
||||
from app.models import Album
|
||||
|
||||
log = get_logger()
|
||||
|
||||
@@ -27,6 +25,7 @@ def get_image_colors(image: str) -> list:
|
||||
|
||||
|
||||
class ProcessAlbumColors:
|
||||
|
||||
def __init__(self) -> None:
|
||||
log.info("Processing album colors")
|
||||
all_albums = Get.get_all_albums()
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
from dataclasses import dataclass
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
from app import instances
|
||||
from app import settings
|
||||
from app.logger import logg
|
||||
from app.helpers import Get, UseBisection, create_album_hash
|
||||
from app.helpers import create_album_hash
|
||||
from app.helpers import Get
|
||||
from app.helpers import run_fast_scandir
|
||||
from app.helpers import UseBisection
|
||||
from app.instances import tracks_instance
|
||||
from app.lib.albumslib import create_album
|
||||
from app.lib.taglib import get_tags
|
||||
from app.models import Album, Track
|
||||
from app.logger import logg
|
||||
from app.models import Album
|
||||
from app.models import Track
|
||||
from tqdm import tqdm
|
||||
|
||||
from app import instances
|
||||
|
||||
|
||||
class Populate:
|
||||
"""
|
||||
@@ -76,6 +78,7 @@ class PreAlbum:
|
||||
|
||||
|
||||
class CreateAlbums:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.db_tracks = Get.get_all_tracks()
|
||||
self.db_albums = Get.get_all_albums()
|
||||
@@ -119,7 +122,8 @@ class CreateAlbums:
|
||||
return prealbums
|
||||
|
||||
@staticmethod
|
||||
def filter_processed(albums: List[Album], prealbums: List[PreAlbum]) -> List[dict]:
|
||||
def filter_processed(albums: List[Album],
|
||||
prealbums: List[PreAlbum]) -> List[dict]:
|
||||
to_process = []
|
||||
|
||||
for p in tqdm(prealbums, desc="Filtering processed albums"):
|
||||
|
||||
@@ -37,6 +37,7 @@ class Limit:
|
||||
|
||||
|
||||
class SearchTracks:
|
||||
|
||||
def __init__(self, tracks: List[models.Track], query: str) -> None:
|
||||
self.query = query
|
||||
self.tracks = tracks
|
||||
@@ -59,6 +60,7 @@ class SearchTracks:
|
||||
|
||||
|
||||
class SearchArtists:
|
||||
|
||||
def __init__(self, artists: set[str], query: str) -> None:
|
||||
self.query = query
|
||||
self.artists = artists
|
||||
@@ -88,6 +90,7 @@ class SearchArtists:
|
||||
|
||||
|
||||
class SearchAlbums:
|
||||
|
||||
def __init__(self, albums: List[models.Album], query: str) -> None:
|
||||
self.query = query
|
||||
self.albums = albums
|
||||
@@ -118,6 +121,7 @@ class SearchAlbums:
|
||||
|
||||
|
||||
class SearchPlaylists:
|
||||
|
||||
def __init__(self, playlists: List[models.Playlist], query: str) -> None:
|
||||
self.playlists = playlists
|
||||
self.query = query
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
|
||||
|
||||
class CustomFormatter(logging.Formatter):
|
||||
|
||||
grey = "\x1b[38;20m"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""
|
||||
Contains all the models for objects generation and typing.
|
||||
"""
|
||||
from dataclasses import dataclass, field
|
||||
import random
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import field
|
||||
from typing import List
|
||||
|
||||
from app import helpers
|
||||
@@ -48,9 +49,8 @@ class Track:
|
||||
self.image = tags["albumhash"] + ".webp"
|
||||
self.tracknumber = int(tags["tracknumber"])
|
||||
|
||||
self.uniq_hash = self.create_unique_hash(
|
||||
"".join(self.artists), self.album, self.title
|
||||
)
|
||||
self.uniq_hash = self.create_unique_hash("".join(self.artists),
|
||||
self.album, self.title)
|
||||
|
||||
@staticmethod
|
||||
def create_unique_hash(*args):
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"""
|
||||
Contains default configs
|
||||
"""
|
||||
import os
|
||||
import multiprocessing
|
||||
|
||||
import os
|
||||
|
||||
# paths
|
||||
CONFIG_FOLDER = ".alice"
|
||||
@@ -28,7 +27,6 @@ LAST_FM_API_KEY = "762db7a44a9e6fb5585661f5f2bdf23a"
|
||||
|
||||
CPU_COUNT = multiprocessing.cpu_count()
|
||||
|
||||
|
||||
THUMB_SIZE: int = 400
|
||||
"""
|
||||
The size of extracted in pixels
|
||||
|
||||
Reference in New Issue
Block a user