add migration to remove the small thumbs path

+ misc
This commit is contained in:
mungai-njoroge 2023-08-12 18:23:28 +03:00
parent 0a703dcc0f
commit 27c4924327
9 changed files with 42 additions and 31 deletions

View File

@ -10,7 +10,6 @@ enjoy your music library in a web browser.
### For more screenshots, see the [screenshots page on the website](https://swingmusic.vercel.app/screenshots.html).
> This project is in the early stages of development. Many features are missing but will be added with time.
### Setup

View File

@ -96,7 +96,7 @@ def get_album_tracks(albumhash: str):
Returns all the tracks in the given album, sorted by disc and track number.
"""
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
sort_by_track_no(tracks)
tracks = sort_by_track_no(tracks)
return {"tracks": tracks}

View File

@ -142,7 +142,7 @@ def get_album_trackhashes(albumhash: str):
"""
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
tracks = sort_by_track_no(tracks)
return [t["trackhash"] for t in tracks]
@ -299,7 +299,7 @@ def remove_playlist_image(playlistid: str):
if playlist is None:
return {"error": "Playlist not found"}, 404
PL.remove_image(pid)
PL.remove_banner(pid)
playlist.image = None
playlist.thumb = None
@ -412,18 +412,22 @@ def save_item_as_playlist():
trackhashes = get_album_trackhashes(itemhash)
elif itemtype == "artist":
trackhashes = get_artist_trackhashes(itemhash)
elif itemtype == "queue":
trackhashes = itemhash.split(",")
else:
trackhashes = []
if len(trackhashes) == 0:
return {"error": "No tracks founds"}, 404
playlist = insert_playlist(playlist_name, image=itemhash + ".webp")
image = itemhash + ".webp" if itemtype != "folder" and itemtype != "queue" else None
playlist = insert_playlist(playlist_name, image)
if playlist is None:
return {"error": "Playlist could not be created"}, 500
if itemtype != "folder":
if itemtype != "folder" and itemtype != "queue":
filename = itemhash + ".webp"
base_path = (

View File

@ -8,8 +8,7 @@ from tqdm import tqdm
from app import settings
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
from app.db.sqlite.lastfm.similar_artists import \
SQLiteLastFMSimilarArtists as lastfmdb
from app.db.sqlite.lastfm.similar_artists import SQLiteLastFMSimilarArtists as lastfmdb
from app.db.sqlite.settings import SettingsSQLMethods as sdb
from app.db.sqlite.tracks import SQLiteTrackMethods
from app.lib.albumslib import validate_albums
@ -111,6 +110,8 @@ class Populate:
if Ping()():
FetchSimilarArtistsLastFM()
ArtistStore.load_artists()
@staticmethod
def remove_modified(tracks: Generator[Track, None, None]):
"""

View File

@ -19,6 +19,7 @@ from app.migrations.base import Migration
migrations: list[list[Migration]] = [
[
# v1.3.0
v1_3_0.RemoveSmallThumbnailFolder,
v1_3_0.RemovePlaylistArtistHashes,
v1_3_0.AddSettingsToPlaylistTable,
v1_3_0.AddLastUpdatedToTrackTable,
@ -39,12 +40,11 @@ def apply_migrations():
# run migrations after the previous migration version
for migration in migrations[(version - 1) :]:
for m in migration:
log.info("Running new migration: %s", m.name)
try:
m.migrate()
log.info("Applied migration: %s", m.__name__)
except:
log.error("Failed to run migration: %s", m.name)
log.error("Failed to run migration: %s", m.__name__)
# bump migration version
MigrationManager.set_version(len(migrations))

View File

@ -3,14 +3,9 @@ class Migration:
Base migration class.
"""
name: str
"""
Name of the migration.
"""
@staticmethod
def migrate():
"""
Code to run when migrating
Code to run when migrating, override this method.
"""
pass

View File

@ -1,11 +1,14 @@
import json
from sqlite3 import OperationalError
import os
import shutil
import time
from collections import OrderedDict
from sqlite3 import OperationalError
from typing import Generator
from app.db.sqlite.utils import SQLiteManager
from app.migrations.base import Migration
from app.settings import Paths
from app.utils.decorators import coroutine
from app.utils.hashing import create_hash
@ -20,13 +23,30 @@ from app.utils.hashing import create_hash
# 6: trackhashes
class RemoveSmallThumbnailFolder(Migration):
"""
Removes the small thumbnail folder.
Because we are added a new folder "original" in the same directory, and the small thumbs folder is used to check if an album's thumbnail is already extracted.
So we need to remove it, to force the app to extract thumbnails for all albums.
"""
@staticmethod
def migrate():
path = Paths.get_sm_thumb_path()
if os.path.exists(path):
shutil.rmtree(path)
os.mkdir(path)
class RemovePlaylistArtistHashes(Migration):
"""
removes the artisthashes column from the playlists table.
"""
name = "RemovePlaylistArtistHashes"
@staticmethod
def migrate():
# remove artisthashes column
@ -47,8 +67,6 @@ class AddSettingsToPlaylistTable(Migration):
to the playlists table.
"""
name = "AddSettingsToPlaylistTable"
@staticmethod
def migrate():
# existing_playlists = []
@ -126,8 +144,6 @@ class AddLastUpdatedToTrackTable(Migration):
adds the last modified column to the tracks table.
"""
name = "AddLastUpdatedToTrackTable"
@staticmethod
def migrate():
# add last_mod column and default to current timestamp
@ -148,8 +164,6 @@ class MovePlaylistsAndFavoritesTo10BitHashes(Migration):
moves the playlists and favorites to 10 bit hashes.
"""
name = "MovePlaylistsAndFavoritesTo10BitHashes"
@staticmethod
def migrate():
def get_track_data_by_hash(trackhash: str, tracks: list[tuple]) -> tuple:
@ -257,8 +271,6 @@ class RemoveAllTracks(Migration):
removes all tracks from the tracks table.
"""
name = "RemoveAllTracks"
@staticmethod
def migrate():
sql = "DELETE FROM tracks"

View File

@ -148,7 +148,7 @@ class Album:
"""
Checks if the album is a live album.
"""
keywords = ["live from", "live at", "live in"]
keywords = ["live from", "live at", "live in", "live on", "mtv unplugged"]
for keyword in keywords:
if keyword in self.title.lower():
return True

View File

@ -23,8 +23,8 @@ class ArtistStore:
# db_artists: list[tuple] = list(ardb.get_all_artists())
for art in tqdm(ardb.get_all_artists(), desc="Loading artists"):
cls.map_artist_color(art)
for artist in tqdm(ardb.get_all_artists(), desc="Loading artists"):
cls.map_artist_color(artist)
@classmethod
def map_artist_color(cls, artist_tuple: tuple):