Skip to content

Commit

Permalink
remove year and file ext from playlist description_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Jun 3, 2024
1 parent d1485a9 commit 79f7bf4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
11 changes: 3 additions & 8 deletions rose-py/rose/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
8 changes: 4 additions & 4 deletions rose-py/rose/cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
]
"""
)
Expand All @@ -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" },
]
"""
)
Expand Down
19 changes: 15 additions & 4 deletions rose-py/rose/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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__)
Expand Down Expand Up @@ -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():
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion rose-py/rose/playlists_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rose-vfs/rose_vfs/virtualfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 79f7bf4

Please sign in to comment.