diff --git a/app/api/album.py b/app/api/album.py index 8d6bc354..dfd70769 100644 --- a/app/api/album.py +++ b/app/api/album.py @@ -2,21 +2,21 @@ Contains all the album routes. """ -from dataclasses import asdict import random +from dataclasses import asdict from flask import Blueprint, request +from app.db.sqlite.albums import SQLiteAlbumMethods as adb +from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb +from app.db.sqlite.lastfm.similar_artists import \ + SQLiteLastFMSimilarArtists as lastfmdb from app.models import FavType, Track +from app.serializers.album import serialize_for_card from app.serializers.track import track_serializer from app.store.albums import AlbumStore from app.store.tracks import TrackStore -from app.db.sqlite.albums import SQLiteAlbumMethods as adb -from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb -from app.db.sqlite.lastfm.similar_artists import SQLiteLastFMSimilarArtists as lastfmdb - from app.utils.hashing import create_hash -from app.serializers.album import serialize_for_card from app.utils.remove_duplicates import remove_duplicates get_albums_by_albumartist = adb.get_albums_by_albumartist @@ -210,4 +210,4 @@ def get_similar_albums(): except ValueError: pass - return {"albums": [serialize_for_card(a) for a in albums]} + return {"albums": [serialize_for_card(a) for a in albums[:limit]]} diff --git a/app/api/artist.py b/app/api/artist.py index c1a589b4..4f63b544 100644 --- a/app/api/artist.py +++ b/app/api/artist.py @@ -321,7 +321,6 @@ def get_similar_artists(artisthash: str): similar = ArtistStore.get_artists_by_hashes(result.get_artist_hash_set()) - # print(similar) if len(similar) > limit: similar = random.sample(similar, limit) diff --git a/app/api/imgserver.py b/app/api/imgserver.py index c4298972..04e949d9 100644 --- a/app/api/imgserver.py +++ b/app/api/imgserver.py @@ -22,6 +22,17 @@ def send_fallback_img(filename: str = "default.webp"): return send_from_directory(path, filename) +@api.route("/t/o/") +def send_original_thumbnail(imgpath: str): + path = Paths.get_original_thumb_path() + fpath = Path(path) / imgpath + + if fpath.exists(): + return send_from_directory(path, imgpath) + + return send_fallback_img() + + @api.route("/t/") def send_lg_thumbnail(imgpath: str): path = Paths.get_lg_thumb_path() diff --git a/app/lib/populate.py b/app/lib/populate.py index 784eab16..28a6e9dc 100644 --- a/app/lib/populate.py +++ b/app/lib/populate.py @@ -241,7 +241,6 @@ def save_similar_artists(artist: Artist): if len(artist_.similar_artist_hashes) == 0: return - print(artist.artisthash, artist.name) lastfmdb.insert_one(artist_) diff --git a/app/lib/searchlib.py b/app/lib/searchlib.py index 465ab9b2..9fc14d23 100644 --- a/app/lib/searchlib.py +++ b/app/lib/searchlib.py @@ -140,7 +140,6 @@ def get_titles(items: _type): text = item.og_title elif isinstance(item, models.Album): text = item.title - # print(text) elif isinstance(item, models.Artist): text = item.name else: diff --git a/app/lib/taglib.py b/app/lib/taglib.py index a27da35a..ecae79c1 100644 --- a/app/lib/taglib.py +++ b/app/lib/taglib.py @@ -28,18 +28,20 @@ def extract_thumb(filepath: str, webp_path: str) -> bool: """ Extracts the thumbnail from an audio file. Returns the path to the thumbnail. """ - img_path = os.path.join(Paths.get_lg_thumb_path(), webp_path) + original_img_path = os.path.join(Paths.get_original_thumb_path(), webp_path) + lg_img_path = os.path.join(Paths.get_lg_thumb_path(), webp_path) sm_img_path = os.path.join(Paths.get_sm_thumb_path(), webp_path) tsize = Defaults.THUMB_SIZE sm_tsize = Defaults.SM_THUMB_SIZE def save_image(img: Image.Image): + img.save(original_img_path, "webp") + img.resize((tsize, tsize), Image.ANTIALIAS).save(lg_img_path, "webp") img.resize((sm_tsize, sm_tsize), Image.ANTIALIAS).save(sm_img_path, "webp") - img.resize((tsize, tsize), Image.ANTIALIAS).save(img_path, "webp") - if os.path.exists(img_path): - img_size = os.path.getsize(img_path) + if os.path.exists(lg_img_path): + img_size = os.path.getsize(lg_img_path) if img_size > 0: return True diff --git a/app/requests/artists.py b/app/requests/artists.py index 8c78f517..dc329821 100644 --- a/app/requests/artists.py +++ b/app/requests/artists.py @@ -6,7 +6,7 @@ import requests from app import settings from app.utils.hashing import create_hash -from requests import ConnectionError, ReadTimeout +from requests import ConnectionError, HTTPError, ReadTimeout import urllib.parse @@ -19,7 +19,7 @@ def fetch_similar_artists(name: str): try: response = requests.get(url, timeout=10) response.raise_for_status() - except (ConnectionError, ReadTimeout): + except (ConnectionError, ReadTimeout, HTTPError): return [] data = response.json() diff --git a/app/serializers/track.py b/app/serializers/track.py index d9b5d250..40a7b843 100644 --- a/app/serializers/track.py +++ b/app/serializers/track.py @@ -16,6 +16,8 @@ def track_serializer(track: Track, _remove: set = {}, retain_disc=False) -> dict to_remove.union("disc", "track") to_remove.update(key for key in album_dict.keys() if key.startswith("is_")) + to_remove.remove('is_favorite') + for key in to_remove: album_dict.pop(key, None) diff --git a/app/settings.py b/app/settings.py index df38dc44..68ae4200 100644 --- a/app/settings.py +++ b/app/settings.py @@ -27,7 +27,9 @@ class Paths: @classmethod def get_config_folder(cls): - return "swingmusic" if cls.get_config_dir() != cls.USER_HOME_DIR else ".swingmusic" + return ( + "swingmusic" if cls.get_config_dir() != cls.USER_HOME_DIR else ".swingmusic" + ) @classmethod def get_app_dir(cls): @@ -65,6 +67,10 @@ class Paths: def get_lg_thumb_path(cls): return join(cls.get_thumbs_path(), "large") + @classmethod + def get_original_thumb_path(cls): + return join(cls.get_thumbs_path(), "original") + @classmethod def get_assets_path(cls): return join(Paths.get_app_dir(), "assets") @@ -73,8 +79,8 @@ class Paths: # defaults class Defaults: THUMB_SIZE = 400 - SM_THUMB_SIZE = 64 - SM_ARTIST_IMG_SIZE = 64 + SM_THUMB_SIZE = 144 + SM_ARTIST_IMG_SIZE = 144 """ The size of extracted images in pixels """ @@ -166,14 +172,14 @@ class FromFlags: class ParserFlags(Enum): - EXTRACT_FEAT = 'EXTRACT_FEAT' - REMOVE_PROD = 'REMOVE_PROD' - CLEAN_ALBUM_TITLE = 'CLEAN_ALBUM_TITLE' - SHOW_ALBUM_VERSION = 'SHOW_ALBUM_VERSION' - REMOVE_REMASTER_FROM_TRACK = 'REMOVE_REMASTER_FROM_TRACK' - DO_PERIODIC_SCANS = 'DO_PERIODIC_SCANS' - PERIODIC_SCAN_INTERVAL = 'PERIODIC_SCAN_INTERVAL' - MERGE_ALBUM_VERSIONS = 'MERGE_ALBUM_VERSIONS' + EXTRACT_FEAT = "EXTRACT_FEAT" + REMOVE_PROD = "REMOVE_PROD" + CLEAN_ALBUM_TITLE = "CLEAN_ALBUM_TITLE" + SHOW_ALBUM_VERSION = "SHOW_ALBUM_VERSION" + REMOVE_REMASTER_FROM_TRACK = "REMOVE_REMASTER_FROM_TRACK" + DO_PERIODIC_SCANS = "DO_PERIODIC_SCANS" + PERIODIC_SCAN_INTERVAL = "PERIODIC_SCAN_INTERVAL" + MERGE_ALBUM_VERSIONS = "MERGE_ALBUM_VERSIONS" def get_flag(flag: ParserFlags) -> bool: diff --git a/app/setup/files.py b/app/setup/files.py index bcdbb9c9..adac14f6 100644 --- a/app/setup/files.py +++ b/app/setup/files.py @@ -63,6 +63,7 @@ def create_config_dir() -> None: thumb_path = os.path.join("images", "thumbnails") small_thumb_path = os.path.join(thumb_path, "small") large_thumb_path = os.path.join(thumb_path, "large") + original_thumb_path = os.path.join(thumb_path, "original") artist_img_path = os.path.join("images", "artists") small_artist_img_path = os.path.join(artist_img_path, "small") @@ -76,6 +77,7 @@ def create_config_dir() -> None: thumb_path, small_thumb_path, large_thumb_path, + original_thumb_path, artist_img_path, small_artist_img_path, large_artist_img_path,