mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
prevent running migrations if is_fresh_install
+ fix: sqlite3.ProgrammingError: Cannot operate on a closed cursor on ProcessAlbumColors() + move processing artist images from periodic_scans to Populate + bump hash string limit from 7 to 10 + add last_mod property to database + fix: TypeError: '<' not supported between instances of 'int' and 'str' on album page
This commit is contained in:
@@ -79,7 +79,7 @@ class CheckArtistImages:
|
||||
tqdm(
|
||||
pool.map(self.download_image, artist_store.ArtistStore.artists),
|
||||
total=len(artist_store.ArtistStore.artists),
|
||||
desc="Downloading artist images",
|
||||
desc="Downloading missing artist images",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
+9
-1
@@ -34,7 +34,11 @@ def get_image_colors(image: str, count=1) -> list[str]:
|
||||
|
||||
|
||||
def process_color(item_hash: str, is_album=True):
|
||||
path = settings.Paths.get_sm_thumb_path() if is_album else settings.Paths.get_artist_img_sm_path()
|
||||
path = (
|
||||
settings.Paths.get_sm_thumb_path()
|
||||
if is_album
|
||||
else settings.Paths.get_artist_img_sm_path()
|
||||
)
|
||||
path = Path(path) / (item_hash + ".webp")
|
||||
|
||||
if not path.exists():
|
||||
@@ -69,6 +73,8 @@ class ProcessAlbumColors:
|
||||
color_str = json.dumps(colors)
|
||||
db.insert_one_album(cur, album.albumhash, color_str)
|
||||
|
||||
cur.close()
|
||||
|
||||
|
||||
class ProcessArtistColors:
|
||||
"""
|
||||
@@ -95,3 +101,5 @@ class ProcessArtistColors:
|
||||
|
||||
artist.set_colors(colors)
|
||||
adb.insert_one_artist(cur, artist.artisthash, colors)
|
||||
|
||||
cur.close()
|
||||
|
||||
+41
-8
@@ -1,10 +1,14 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from requests import ConnectionError as RequestConnectionError
|
||||
from requests import ReadTimeout
|
||||
|
||||
from app import settings
|
||||
from app.db.sqlite.tracks import SQLiteTrackMethods
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as favdb
|
||||
from app.lib.artistlib import CheckArtistImages
|
||||
from app.lib.colorlib import ProcessAlbumColors, ProcessArtistColors
|
||||
|
||||
from app.lib.taglib import extract_thumb, get_tags
|
||||
@@ -16,9 +20,11 @@ from app.utils.filesystem import run_fast_scandir
|
||||
from app.store.albums import AlbumStore
|
||||
from app.store.tracks import TrackStore
|
||||
from app.store.artists import ArtistStore
|
||||
from app.utils.network import Ping
|
||||
|
||||
get_all_tracks = SQLiteTrackMethods.get_all_tracks
|
||||
insert_many_tracks = SQLiteTrackMethods.insert_many_tracks
|
||||
remove_tracks_by_filepaths = SQLiteTrackMethods.remove_tracks_by_filepaths
|
||||
|
||||
POPULATE_KEY = ""
|
||||
|
||||
@@ -48,8 +54,8 @@ class Populate:
|
||||
if len(dirs_to_scan) == 0:
|
||||
log.warning(
|
||||
(
|
||||
"The root directory is not configured. "
|
||||
+ "Open the app in your webbrowser to configure."
|
||||
"The root directory is not configured. "
|
||||
+ "Open the app in your webbrowser to configure."
|
||||
)
|
||||
)
|
||||
return
|
||||
@@ -65,18 +71,44 @@ class Populate:
|
||||
for _dir in dirs_to_scan:
|
||||
files.extend(run_fast_scandir(_dir, full=True)[1])
|
||||
|
||||
self.remove_modified(tracks)
|
||||
untagged = self.filter_untagged(tracks, files)
|
||||
|
||||
if len(untagged) == 0:
|
||||
log.info("All clear, no unread files.")
|
||||
return
|
||||
|
||||
self.tag_untagged(untagged, key)
|
||||
if len(untagged) != 0:
|
||||
self.tag_untagged(untagged, key)
|
||||
|
||||
ProcessTrackThumbnails()
|
||||
ProcessAlbumColors()
|
||||
ProcessArtistColors()
|
||||
|
||||
tried_to_download_new_images = False
|
||||
|
||||
if Ping()():
|
||||
tried_to_download_new_images = True
|
||||
try:
|
||||
CheckArtistImages()
|
||||
except (RequestConnectionError, ReadTimeout):
|
||||
log.error(
|
||||
"Internet connection lost. Downloading artist images stopped."
|
||||
)
|
||||
else:
|
||||
log.warning(
|
||||
f"No internet connection. Downloading artist images halted for {settings.get_scan_sleep_time()} seconds."
|
||||
)
|
||||
|
||||
# Re-process the new artist images.
|
||||
if tried_to_download_new_images:
|
||||
ProcessArtistColors()
|
||||
|
||||
@staticmethod
|
||||
def remove_modified(tracks: list[Track]):
|
||||
modified = [
|
||||
t.filepath for t in tracks if t.last_mod != os.path.getmtime(t.filepath)
|
||||
]
|
||||
|
||||
TrackStore.remove_tracks_by_filepaths(modified)
|
||||
remove_tracks_by_filepaths(modified)
|
||||
|
||||
@staticmethod
|
||||
def filter_untagged(tracks: list[Track], files: list[str]):
|
||||
tagged_files = [t.filepath for t in tracks]
|
||||
@@ -120,6 +152,7 @@ class Populate:
|
||||
log.warning("Could not read file: %s", file)
|
||||
|
||||
if len(tagged_tracks) > 0:
|
||||
log.info("Adding %s tracks to database", len(tagged_tracks))
|
||||
insert_many_tracks(tagged_tracks)
|
||||
|
||||
log.info("Added %s/%s tracks", tagged_count, len(untagged))
|
||||
|
||||
+6
-4
@@ -64,17 +64,18 @@ def extract_thumb(filepath: str, webp_path: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def extract_date(date_str: str | None, filepath: str) -> int:
|
||||
def extract_date(date_str: str | None, timestamp: float) -> int:
|
||||
try:
|
||||
return int(date_str.split("-")[0])
|
||||
except: # pylint: disable=bare-except
|
||||
# TODO: USE FILEPATH LAST-MOD DATE instead of current date
|
||||
return datetime.date.today().today().year
|
||||
print(datetime.datetime.fromtimestamp(timestamp).year)
|
||||
return datetime.datetime.fromtimestamp(timestamp).year
|
||||
|
||||
|
||||
def get_tags(filepath: str):
|
||||
filetype = filepath.split(".")[-1]
|
||||
filename = (filepath.split("/")[-1]).replace(f".{filetype}", "")
|
||||
last_mod = os.path.getmtime(filepath)
|
||||
|
||||
try:
|
||||
tags = TinyTag.get(filepath)
|
||||
@@ -141,9 +142,10 @@ def get_tags(filepath: str):
|
||||
tags.image = f"{tags.albumhash}.webp"
|
||||
tags.folder = win_replace_slash(os.path.dirname(filepath))
|
||||
|
||||
tags.date = extract_date(tags.year, filepath)
|
||||
tags.date = extract_date(tags.year, last_mod)
|
||||
tags.filepath = win_replace_slash(filepath)
|
||||
tags.filetype = filetype
|
||||
tags.last_mod = last_mod
|
||||
|
||||
tags = tags.__dict__
|
||||
|
||||
|
||||
@@ -16,4 +16,4 @@ def validate_tracks() -> None:
|
||||
for track in tqdm(TrackStore.tracks, desc="Checking for deleted tracks"):
|
||||
if not os.path.exists(track.filepath):
|
||||
TrackStore.tracks.remove(track)
|
||||
tdb.remove_track_by_filepath(track.filepath)
|
||||
tdb.remove_tracks_by_filepaths(track.filepath)
|
||||
|
||||
+7
-10
@@ -8,18 +8,16 @@ import time
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
from watchdog.observers import Observer
|
||||
|
||||
from app.logger import log
|
||||
from app.lib.taglib import get_tags
|
||||
from app.models import Artist, Track
|
||||
from app import settings
|
||||
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||
from app.db.sqlite.tracks import SQLiteManager
|
||||
from app.db.sqlite.tracks import SQLiteTrackMethods as db
|
||||
from app.db.sqlite.settings import SettingsSQLMethods as sdb
|
||||
|
||||
from app.store.tracks import TrackStore
|
||||
from app.lib.taglib import get_tags
|
||||
from app.logger import log
|
||||
from app.models import Artist, Track
|
||||
from app.store.albums import AlbumStore
|
||||
from app.store.artists import ArtistStore
|
||||
from app.store.tracks import TrackStore
|
||||
|
||||
|
||||
class Watcher:
|
||||
@@ -133,7 +131,7 @@ def add_track(filepath: str) -> None:
|
||||
"""
|
||||
# remove the track if it already exists
|
||||
TrackStore.remove_track_by_filepath(filepath)
|
||||
db.remove_track_by_filepath(filepath)
|
||||
db.remove_tracks_by_filepaths(filepath)
|
||||
|
||||
# add the track to the database and store.
|
||||
tags = get_tags(filepath)
|
||||
@@ -142,7 +140,6 @@ def add_track(filepath: str) -> None:
|
||||
return
|
||||
|
||||
with SQLiteManager() as cur:
|
||||
db.remove_track_by_filepath(tags["filepath"])
|
||||
db.insert_one_track(tags, cur)
|
||||
|
||||
track = Track(**tags)
|
||||
@@ -168,7 +165,7 @@ def remove_track(filepath: str) -> None:
|
||||
except IndexError:
|
||||
return
|
||||
|
||||
db.remove_track_by_filepath(filepath)
|
||||
db.remove_tracks_by_filepaths(filepath)
|
||||
TrackStore.remove_track_by_filepath(filepath)
|
||||
|
||||
empty_album = TrackStore.count_tracks_by_hash(track.albumhash) > 0
|
||||
|
||||
Reference in New Issue
Block a user