Restyle New album page design (#76)

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