From 79f7bf4006ce49bff1b6c1933f96ceb6dc9ef61a Mon Sep 17 00:00:00 2001 From: blissful Date: Mon, 3 Jun 2024 07:40:44 -0400 Subject: [PATCH] remove year and file ext from playlist description_meta --- rose-py/rose/cache.py | 11 +++-------- rose-py/rose/cache_test.py | 8 ++++---- rose-py/rose/playlists.py | 19 +++++++++++++++---- rose-py/rose/playlists_test.py | 2 +- rose-vfs/rose_vfs/virtualfs_test.py | 4 ++-- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/rose-py/rose/cache.py b/rose-py/rose/cache.py index a31de66..8c5c995 100644 --- a/rose-py/rose/cache.py +++ b/rose-py/rose/cache.py @@ -1674,14 +1674,9 @@ def update_cache_for_playlists( track_ids, ) for row in cursor: - desc_map[row["id"]] = make_track_logtext( - title=row["tracktitle"], - artists=_unpack_artists( - c, row["trackartist_names"], row["trackartist_roles"] - ), - releasedate=RoseDate.parse(row["releasedate"]), - suffix=Path(row["source_path"]).suffix, - ) + title = row["tracktitle"] + artists = _unpack_artists(c, row["trackartist_names"], row["trackartist_roles"]) + desc_map[row["id"]] = f"{artistsfmt(artists)} - {title}" for trk in tracks: with contextlib.suppress(KeyError): trk["description_meta"] = desc_map[trk["uuid"]] diff --git a/rose-py/rose/cache_test.py b/rose-py/rose/cache_test.py index 4c7bd1f..c9c34d6 100644 --- a/rose-py/rose/cache_test.py +++ b/rose-py/rose/cache_test.py @@ -1041,8 +1041,8 @@ def test_update_tracks_updates_playlists_description_meta( fp.read() == """\ tracks = [ - { uuid = "iloveloona", description_meta = "Carly Rae Jepsen - Track 1 [1990].m4a" }, - { uuid = "ilovetwice", description_meta = "Carly Rae Jepsen - Track 2 [1990].m4a" }, + { uuid = "iloveloona", description_meta = "Carly Rae Jepsen - Track 1" }, + { uuid = "ilovetwice", description_meta = "Carly Rae Jepsen - Track 2" }, ] """ ) @@ -1069,8 +1069,8 @@ def test_update_tracks_updates_playlists_description_meta( fp.read() == """\ tracks = [ - { uuid = "iloveloona", description_meta = "Carly Rae Jepsen - Track 1 [1990].m4a" }, - { uuid = "ilovetwice", description_meta = "Carly Rae Jepsen - Track 2 [1990].m4a" }, + { uuid = "iloveloona", description_meta = "Carly Rae Jepsen - Track 1" }, + { uuid = "ilovetwice", description_meta = "Carly Rae Jepsen - Track 2" }, ] """ ) diff --git a/rose-py/rose/playlists.py b/rose-py/rose/playlists.py index cc3ce22..3ecceb1 100644 --- a/rose-py/rose/playlists.py +++ b/rose-py/rose/playlists.py @@ -14,8 +14,10 @@ from send2trash import send2trash from rose.cache import ( + get_track, get_track_logtext, lock, + make_track_logtext, playlist_lock_name, update_cache_evict_nonexistent_playlists, update_cache_for_playlists, @@ -24,6 +26,7 @@ from rose.common import RoseExpectedError from rose.config import Config from rose.releases import InvalidCoverArtFileError +from rose.templates import artistsfmt from rose.tracks import TrackDoesNotExistError logger = logging.getLogger(__name__) @@ -116,8 +119,8 @@ def add_track_to_playlist( playlist_name: str, track_id: str, ) -> None: - track_logtext = get_track_logtext(c, track_id) - if not track_logtext: + track = get_track(c, track_id) + if not track: raise TrackDoesNotExistError(f"Track {track_id} does not exist") path = playlist_path(c, playlist_name) if not path.exists(): @@ -130,11 +133,19 @@ def add_track_to_playlist( # duplicate playlist entries. for r in data["tracks"]: if r["uuid"] == track_id: - logger.info(f"No-Op: Track {track_logtext} already in playlist {playlist_name}") + logger.info(f"No-Op: Track {track} already in playlist {playlist_name}") return - data["tracks"].append({"uuid": track_id, "description_meta": track_logtext}) + + desc = f"{artistsfmt(track.trackartists)} - {track.tracktitle}" + data["tracks"].append({"uuid": track_id, "description_meta": desc}) with path.open("wb") as fp: tomli_w.dump(data, fp) + track_logtext = make_track_logtext( + title=track.tracktitle, + artists=track.trackartists, + releasedate=track.release.releasedate, + suffix=track.source_path.suffix, + ) logger.info(f"Added track {track_logtext} to playlist {playlist_name}") update_cache_for_playlists(c, [playlist_name], force=True) diff --git a/rose-py/rose/playlists_test.py b/rose-py/rose/playlists_test.py index ae887b6..3fa25b1 100644 --- a/rose-py/rose/playlists_test.py +++ b/rose-py/rose/playlists_test.py @@ -171,7 +171,7 @@ def editfn(x: str) -> str: monkeypatch.setattr("rose.playlists.click.edit", editfn) edit_playlist_in_editor(config, "You & Me") - assert seen == "\n".join([f"BLACKPINK - Track 1 [1990].m4a [{tid}]" for tid in track_ids]) + assert seen == "\n".join([f"BLACKPINK - Track 1 [{tid}]" for tid in track_ids]) with (config.music_source_dir / "!playlists" / "You & Me.toml").open("rb") as fp: data = tomllib.load(fp) diff --git a/rose-vfs/rose_vfs/virtualfs_test.py b/rose-vfs/rose_vfs/virtualfs_test.py index b04d4de..74499ed 100644 --- a/rose-vfs/rose_vfs/virtualfs_test.py +++ b/rose-vfs/rose_vfs/virtualfs_test.py @@ -299,12 +299,12 @@ def test_virtual_filesystem_playlist_actions( assert (root / "7. Playlists" / "New Jeans" / filename).is_file() assert (root / "7. Playlists" / "New Jeans" / "1. BLACKPINK - Track 1.m4a").is_file() with (src / "!playlists" / "New Jeans.toml").open("r") as fp: - assert "BLACKPINK - Track 1 [1990].m4a" in fp.read() + assert "BLACKPINK - Track 1" in fp.read() # Delete track from playlist. (root / "7. Playlists" / "New Jeans" / "1. BLACKPINK - Track 1.m4a").unlink() assert not (root / "7. Playlists" / "New Jeans" / "1. BLACKPINK - Track 1.m4a").exists() with (src / "!playlists" / "New Jeans.toml").open("r") as fp: - assert "BLACKPINK - Track 1 [1990].m4a" not in fp.read() + assert "BLACKPINK - Track 1" not in fp.read() # Delete playlist. (root / "7. Playlists" / "New Jeans").rmdir() assert not (src / "!playlists" / "New Jeans.toml").exists()