mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-06 19:25:34 +00:00
add migration to remove the small thumbs path
+ misc
This commit is contained in:
parent
0a703dcc0f
commit
27c4924327
@ -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).
|
### 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
|
### Setup
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ def get_album_tracks(albumhash: str):
|
|||||||
Returns all the tracks in the given album, sorted by disc and track number.
|
Returns all the tracks in the given album, sorted by disc and track number.
|
||||||
"""
|
"""
|
||||||
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
|
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
|
||||||
sort_by_track_no(tracks)
|
tracks = sort_by_track_no(tracks)
|
||||||
|
|
||||||
return {"tracks": tracks}
|
return {"tracks": tracks}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ def get_album_trackhashes(albumhash: str):
|
|||||||
"""
|
"""
|
||||||
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
|
tracks = TrackStore.get_tracks_by_albumhash(albumhash)
|
||||||
tracks = sort_by_track_no(tracks)
|
tracks = sort_by_track_no(tracks)
|
||||||
|
|
||||||
return [t["trackhash"] for t in tracks]
|
return [t["trackhash"] for t in tracks]
|
||||||
|
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ def remove_playlist_image(playlistid: str):
|
|||||||
if playlist is None:
|
if playlist is None:
|
||||||
return {"error": "Playlist not found"}, 404
|
return {"error": "Playlist not found"}, 404
|
||||||
|
|
||||||
PL.remove_image(pid)
|
PL.remove_banner(pid)
|
||||||
|
|
||||||
playlist.image = None
|
playlist.image = None
|
||||||
playlist.thumb = None
|
playlist.thumb = None
|
||||||
@ -412,18 +412,22 @@ def save_item_as_playlist():
|
|||||||
trackhashes = get_album_trackhashes(itemhash)
|
trackhashes = get_album_trackhashes(itemhash)
|
||||||
elif itemtype == "artist":
|
elif itemtype == "artist":
|
||||||
trackhashes = get_artist_trackhashes(itemhash)
|
trackhashes = get_artist_trackhashes(itemhash)
|
||||||
|
elif itemtype == "queue":
|
||||||
|
trackhashes = itemhash.split(",")
|
||||||
else:
|
else:
|
||||||
trackhashes = []
|
trackhashes = []
|
||||||
|
|
||||||
if len(trackhashes) == 0:
|
if len(trackhashes) == 0:
|
||||||
return {"error": "No tracks founds"}, 404
|
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:
|
if playlist is None:
|
||||||
return {"error": "Playlist could not be created"}, 500
|
return {"error": "Playlist could not be created"}, 500
|
||||||
|
|
||||||
if itemtype != "folder":
|
if itemtype != "folder" and itemtype != "queue":
|
||||||
filename = itemhash + ".webp"
|
filename = itemhash + ".webp"
|
||||||
|
|
||||||
base_path = (
|
base_path = (
|
||||||
|
@ -8,8 +8,7 @@ from tqdm import tqdm
|
|||||||
|
|
||||||
from app import settings
|
from app import settings
|
||||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||||
from app.db.sqlite.lastfm.similar_artists import \
|
from app.db.sqlite.lastfm.similar_artists import SQLiteLastFMSimilarArtists as lastfmdb
|
||||||
SQLiteLastFMSimilarArtists as lastfmdb
|
|
||||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||||
from app.db.sqlite.tracks import SQLiteTrackMethods
|
from app.db.sqlite.tracks import SQLiteTrackMethods
|
||||||
from app.lib.albumslib import validate_albums
|
from app.lib.albumslib import validate_albums
|
||||||
@ -111,6 +110,8 @@ class Populate:
|
|||||||
if Ping()():
|
if Ping()():
|
||||||
FetchSimilarArtistsLastFM()
|
FetchSimilarArtistsLastFM()
|
||||||
|
|
||||||
|
ArtistStore.load_artists()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_modified(tracks: Generator[Track, None, None]):
|
def remove_modified(tracks: Generator[Track, None, None]):
|
||||||
"""
|
"""
|
||||||
|
@ -19,6 +19,7 @@ from app.migrations.base import Migration
|
|||||||
migrations: list[list[Migration]] = [
|
migrations: list[list[Migration]] = [
|
||||||
[
|
[
|
||||||
# v1.3.0
|
# v1.3.0
|
||||||
|
v1_3_0.RemoveSmallThumbnailFolder,
|
||||||
v1_3_0.RemovePlaylistArtistHashes,
|
v1_3_0.RemovePlaylistArtistHashes,
|
||||||
v1_3_0.AddSettingsToPlaylistTable,
|
v1_3_0.AddSettingsToPlaylistTable,
|
||||||
v1_3_0.AddLastUpdatedToTrackTable,
|
v1_3_0.AddLastUpdatedToTrackTable,
|
||||||
@ -39,12 +40,11 @@ def apply_migrations():
|
|||||||
# run migrations after the previous migration version
|
# run migrations after the previous migration version
|
||||||
for migration in migrations[(version - 1) :]:
|
for migration in migrations[(version - 1) :]:
|
||||||
for m in migration:
|
for m in migration:
|
||||||
log.info("Running new migration: %s", m.name)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
m.migrate()
|
m.migrate()
|
||||||
|
log.info("Applied migration: %s", m.__name__)
|
||||||
except:
|
except:
|
||||||
log.error("Failed to run migration: %s", m.name)
|
log.error("Failed to run migration: %s", m.__name__)
|
||||||
|
|
||||||
# bump migration version
|
# bump migration version
|
||||||
MigrationManager.set_version(len(migrations))
|
MigrationManager.set_version(len(migrations))
|
||||||
|
@ -3,14 +3,9 @@ class Migration:
|
|||||||
Base migration class.
|
Base migration class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name: str
|
|
||||||
"""
|
|
||||||
Name of the migration.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
"""
|
"""
|
||||||
Code to run when migrating
|
Code to run when migrating, override this method.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import json
|
import json
|
||||||
from sqlite3 import OperationalError
|
import os
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from sqlite3 import OperationalError
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
from app.db.sqlite.utils import SQLiteManager
|
from app.db.sqlite.utils import SQLiteManager
|
||||||
from app.migrations.base import Migration
|
from app.migrations.base import Migration
|
||||||
|
from app.settings import Paths
|
||||||
from app.utils.decorators import coroutine
|
from app.utils.decorators import coroutine
|
||||||
from app.utils.hashing import create_hash
|
from app.utils.hashing import create_hash
|
||||||
|
|
||||||
@ -20,13 +23,30 @@ from app.utils.hashing import create_hash
|
|||||||
# 6: trackhashes
|
# 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):
|
class RemovePlaylistArtistHashes(Migration):
|
||||||
"""
|
"""
|
||||||
removes the artisthashes column from the playlists table.
|
removes the artisthashes column from the playlists table.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "RemovePlaylistArtistHashes"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
# remove artisthashes column
|
# remove artisthashes column
|
||||||
@ -47,8 +67,6 @@ class AddSettingsToPlaylistTable(Migration):
|
|||||||
to the playlists table.
|
to the playlists table.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "AddSettingsToPlaylistTable"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
# existing_playlists = []
|
# existing_playlists = []
|
||||||
@ -126,8 +144,6 @@ class AddLastUpdatedToTrackTable(Migration):
|
|||||||
adds the last modified column to the tracks table.
|
adds the last modified column to the tracks table.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "AddLastUpdatedToTrackTable"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
# add last_mod column and default to current timestamp
|
# 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.
|
moves the playlists and favorites to 10 bit hashes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "MovePlaylistsAndFavoritesTo10BitHashes"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
def get_track_data_by_hash(trackhash: str, tracks: list[tuple]) -> tuple:
|
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.
|
removes all tracks from the tracks table.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "RemoveAllTracks"
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
sql = "DELETE FROM tracks"
|
sql = "DELETE FROM tracks"
|
||||||
|
@ -148,7 +148,7 @@ class Album:
|
|||||||
"""
|
"""
|
||||||
Checks if the album is a live 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:
|
for keyword in keywords:
|
||||||
if keyword in self.title.lower():
|
if keyword in self.title.lower():
|
||||||
return True
|
return True
|
||||||
|
@ -23,8 +23,8 @@ class ArtistStore:
|
|||||||
|
|
||||||
# db_artists: list[tuple] = list(ardb.get_all_artists())
|
# db_artists: list[tuple] = list(ardb.get_all_artists())
|
||||||
|
|
||||||
for art in tqdm(ardb.get_all_artists(), desc="Loading artists"):
|
for artist in tqdm(ardb.get_all_artists(), desc="Loading artists"):
|
||||||
cls.map_artist_color(art)
|
cls.map_artist_color(artist)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def map_artist_color(cls, artist_tuple: tuple):
|
def map_artist_color(cls, artist_tuple: tuple):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user