From a0b9459e6ff83b96f0ffbec027f3b7ff8632b8b3 Mon Sep 17 00:00:00 2001 From: blissful Date: Sun, 5 May 2024 21:43:16 -0400 Subject: [PATCH] remove Cached prefix from cache objects --- rose/__init__.py | 20 ++++++----- rose/cache.py | 82 +++++++++++++++++++++--------------------- rose/cache_test.py | 58 +++++++++++++++--------------- rose/releases.py | 6 ++-- rose/releases_test.py | 16 ++++----- rose/rules.py | 12 +++---- rose/templates.py | 28 +++++++-------- rose/templates_test.py | 6 ++-- rose_vfs/virtualfs.py | 12 +++---- 9 files changed, 122 insertions(+), 118 deletions(-) diff --git a/rose/__init__.py b/rose/__init__.py index eb84224..c078611 100644 --- a/rose/__init__.py +++ b/rose/__init__.py @@ -5,13 +5,13 @@ ) from rose.cache import ( STORED_DATA_FILE_REGEX, - CachedCollage, - CachedPlaylist, - CachedRelease, - CachedTrack, + Collage, DescriptorEntry, GenreEntry, LabelEntry, + Playlist, + Release, + Track, artist_exists, calculate_release_logtext, calculate_track_logtext, @@ -54,6 +54,8 @@ ) from rose.common import ( VERSION, + Artist, + ArtistMapping, RoseError, RoseExpectedError, initialize_logging, @@ -138,7 +140,7 @@ "eval_track_template", # TODO: Rename. "preview_path_templates", # Releases - "CachedRelease", + "Release", "create_single_release", "delete_release", "delete_release_cover_art", @@ -149,12 +151,14 @@ "set_release_cover_art", "toggle_release_new", # Tracks - "CachedTrack", + "Track", "dump_all_tracks", "dump_track", "get_track", "get_tracks_associated_with_release", # TODO: Rename: `get_tracks_of_release` / `dump_release(with_tracks=tracks)` # Artists + "Artist", + "ArtistMapping", "artist_exists", "list_artists", # Genres @@ -170,7 +174,7 @@ "list_labels", "label_exists", # Collages - "CachedCollage", + "Collage", "add_release_to_collage", "collage_exists", "create_collage", @@ -183,7 +187,7 @@ "remove_release_from_collage", "rename_collage", # Playlists - "CachedPlaylist", + "Playlist", "add_track_to_playlist", "list_playlists", "playlist_exists", diff --git a/rose/cache.py b/rose/cache.py index 70447ec..f688267 100644 --- a/rose/cache.py +++ b/rose/cache.py @@ -201,7 +201,7 @@ def playlist_lock_name(playlist_name: str) -> str: @dataclass(slots=True) -class CachedRelease: +class Release: id: str source_path: Path cover_image_path: Path | None @@ -252,10 +252,10 @@ def dump(self) -> dict[str, Any]: } -def cached_release_from_view(c: Config, row: dict[str, Any], aliases: bool = True) -> CachedRelease: +def cached_release_from_view(c: Config, row: dict[str, Any], aliases: bool = True) -> Release: secondary_genres = _split(row["secondary_genres"]) if row["secondary_genres"] else [] genres = _split(row["genres"]) if row["genres"] else [] - return CachedRelease( + return Release( id=row["id"], source_path=Path(row["source_path"]), cover_image_path=Path(row["cover_image_path"]) if row["cover_image_path"] else None, @@ -284,7 +284,7 @@ def cached_release_from_view(c: Config, row: dict[str, Any], aliases: bool = Tru @dataclass(slots=True) -class CachedTrack: +class Track: id: str source_path: Path source_mtime: str @@ -296,7 +296,7 @@ class CachedTrack: trackartists: ArtistMapping metahash: str - release: CachedRelease + release: Release def dump(self, with_release_info: bool = True) -> dict[str, Any]: r = { @@ -344,10 +344,10 @@ def dump(self, with_release_info: bool = True) -> dict[str, Any]: def cached_track_from_view( c: Config, row: dict[str, Any], - release: CachedRelease, + release: Release, aliases: bool = True, -) -> CachedTrack: - return CachedTrack( +) -> Track: + return Track( id=row["id"], source_path=Path(row["source_path"]), source_mtime=row["source_mtime"], @@ -368,14 +368,14 @@ def cached_track_from_view( @dataclass(slots=True) -class CachedCollage: +class Collage: name: str source_mtime: str release_ids: list[str] @dataclass(slots=True) -class CachedPlaylist: +class Playlist: name: str source_mtime: str cover_path: Path | None @@ -564,7 +564,7 @@ def _update_cache_for_releases_executor( # 1. Fetch all releases. # 2. Fetch all tracks in a single query, and then associates each track with a release. # The tracks are stored as a dict of source_path -> Track. - cached_releases: dict[str, tuple[CachedRelease, dict[str, CachedTrack]]] = {} + cached_releases: dict[str, tuple[Release, dict[str, Track]]] = {} with connect(c) as conn: cursor = conn.execute( rf""" @@ -646,7 +646,7 @@ def _update_cache_for_releases_executor( f"First-time unidentified release found at release {source_path}, writing UUID and new" ) release_dirty = True - release = CachedRelease( + release = Release( id=preexisting_release_id or "", source_path=source_path, datafile_mtime="", @@ -766,7 +766,7 @@ def _update_cache_for_releases_executor( # Now we'll switch over to processing some of the tracks. We need track metadata in # order to calculate some fields of the release, so we'll first compute the valid set of - # CachedTracks, and then we will finalize the release and execute any required database + # Tracks, and then we will finalize the release and execute any required database # operations for the release and tracks. # We want to know which cached tracks are no longer on disk. By the end of the following @@ -777,7 +777,7 @@ def _update_cache_for_releases_executor( # leverage mtimes and such to avoid unnecessary recomputations. If a release has changed # and should be updated in the database, we add its ID to track_ids_to_insert, which # will be used in the database execution step. - tracks: list[CachedTrack] = [] + tracks: list[Track] = [] track_ids_to_insert: set[str] = set() # This value is set to true if we read an AudioTags and used it to confirm the release # tags. @@ -915,7 +915,7 @@ def _update_cache_for_releases_executor( continue # And now create the cached track. - track = CachedTrack( + track = Track( id=track_id, source_path=Path(f), source_mtime=track_mtime, @@ -1423,7 +1423,7 @@ def update_cache_for_collages( files.append((path.resolve(), path.stem, f)) logger.debug(f"Refreshing the read cache for {len(files)} collages") - cached_collages: dict[str, CachedCollage] = {} + cached_collages: dict[str, Collage] = {} with connect(c) as conn: cursor = conn.execute( """ @@ -1437,7 +1437,7 @@ def update_cache_for_collages( """, ) for row in cursor: - cached_collages[row["name"]] = CachedCollage( + cached_collages[row["name"]] = Collage( name=row["name"], source_mtime=row["source_mtime"], release_ids=_split(row["release_ids"]) if row["release_ids"] else [], @@ -1455,7 +1455,7 @@ def update_cache_for_collages( cached_collage = cached_collages[name] except KeyError: logger.debug(f"First-time unidentified collage found at {source_path}") - cached_collage = CachedCollage( + cached_collage = Collage( name=name, source_mtime="", release_ids=[], @@ -1618,7 +1618,7 @@ def update_cache_for_playlists( files.append((path.resolve(), path.stem, f)) logger.debug(f"Refreshing the read cache for {len(files)} playlists") - cached_playlists: dict[str, CachedPlaylist] = {} + cached_playlists: dict[str, Playlist] = {} with connect(c) as conn: cursor = conn.execute( """ @@ -1633,7 +1633,7 @@ def update_cache_for_playlists( """, ) for row in cursor: - cached_playlists[row["name"]] = CachedPlaylist( + cached_playlists[row["name"]] = Playlist( name=row["name"], source_mtime=row["source_mtime"], cover_path=Path(row["cover_path"]) if row["cover_path"] else None, @@ -1652,7 +1652,7 @@ def update_cache_for_playlists( cached_playlist = cached_playlists[name] except KeyError: logger.debug(f"First-time unidentified playlist found at {source_path}") - cached_playlist = CachedPlaylist( + cached_playlist = Playlist( name=name, source_mtime="", cover_path=None, @@ -1822,7 +1822,7 @@ def list_releases_delete_this( descriptor_filter: str | None = None, label_filter: str | None = None, new: bool | None = None, -) -> list[CachedRelease]: +) -> list[Release]: with connect(c) as conn: query = "SELECT * FROM releases_view WHERE 1=1" args: list[str | bool] = [] @@ -1876,13 +1876,13 @@ def list_releases_delete_this( query += " ORDER BY source_path" cursor = conn.execute(query, args) - releases: list[CachedRelease] = [] + releases: list[Release] = [] for row in cursor: releases.append(cached_release_from_view(c, row)) return releases -def list_releases(c: Config, release_ids: list[str] | None = None) -> list[CachedRelease]: +def list_releases(c: Config, release_ids: list[str] | None = None) -> list[Release]: """Fetch data associated with given release IDs. Pass None to fetch all.""" query = "SELECT * FROM releases_view" args = [] @@ -1892,13 +1892,13 @@ def list_releases(c: Config, release_ids: list[str] | None = None) -> list[Cache query += " ORDER BY source_path" with connect(c) as conn: cursor = conn.execute(query, args) - releases: list[CachedRelease] = [] + releases: list[Release] = [] for row in cursor: releases.append(cached_release_from_view(c, row)) return releases -def get_release(c: Config, release_id: str) -> CachedRelease | None: +def get_release(c: Config, release_id: str) -> Release | None: with connect(c) as conn: cursor = conn.execute( "SELECT * FROM releases_view WHERE id = ?", @@ -1939,7 +1939,7 @@ def calculate_release_logtext( return logtext -def list_tracks(c: Config, track_ids: list[str] | None = None) -> list[CachedTrack]: +def list_tracks(c: Config, track_ids: list[str] | None = None) -> list[Track]: """Fetch data associated with given track IDs. Pass None to fetch all.""" query = "SELECT * FROM tracks_view" args = [] @@ -1960,7 +1960,7 @@ def list_tracks(c: Config, track_ids: list[str] | None = None) -> list[CachedTra """, release_ids, ) - releases_map: dict[str, CachedRelease] = {} + releases_map: dict[str, Release] = {} for row in cursor: releases_map[row["id"]] = cached_release_from_view(c, row) @@ -1970,7 +1970,7 @@ def list_tracks(c: Config, track_ids: list[str] | None = None) -> list[CachedTra return rval -def get_track(c: Config, uuid: str) -> CachedTrack | None: +def get_track(c: Config, uuid: str) -> Track | None: with connect(c) as conn: cursor = conn.execute("SELECT * FROM tracks_view WHERE id = ?", (uuid,)) trackrow = cursor.fetchone() @@ -1983,8 +1983,8 @@ def get_track(c: Config, uuid: str) -> CachedTrack | None: def get_tracks_associated_with_release( c: Config, - release: CachedRelease, -) -> list[CachedTrack]: + release: Release, +) -> list[Track]: with connect(c) as conn: cursor = conn.execute( """ @@ -2003,10 +2003,10 @@ def get_tracks_associated_with_release( def get_tracks_associated_with_releases( c: Config, - releases: list[CachedRelease], -) -> list[tuple[CachedRelease, list[CachedTrack]]]: + releases: list[Release], +) -> list[tuple[Release, list[Track]]]: releases_map = {r.id: r for r in releases} - tracks_map: dict[str, list[CachedTrack]] = defaultdict(list) + tracks_map: dict[str, list[Track]] = defaultdict(list) with connect(c) as conn: cursor = conn.execute( f""" @@ -2123,7 +2123,7 @@ def list_playlists(c: Config) -> list[str]: return [r["name"] for r in cursor] -def get_playlist(c: Config, playlist_name: str) -> tuple[CachedPlaylist, list[CachedTrack]] | None: +def get_playlist(c: Config, playlist_name: str) -> tuple[Playlist, list[Track]] | None: with connect(c) as conn: cursor = conn.execute( """ @@ -2139,7 +2139,7 @@ def get_playlist(c: Config, playlist_name: str) -> tuple[CachedPlaylist, list[Ca row = cursor.fetchone() if not row: return None - playlist = CachedPlaylist( + playlist = Playlist( name=row["name"], source_mtime=row["source_mtime"], cover_path=Path(row["cover_path"]) if row["cover_path"] else None, @@ -2168,11 +2168,11 @@ def get_playlist(c: Config, playlist_name: str) -> tuple[CachedPlaylist, list[Ca """, release_ids, ) - releases_map: dict[str, CachedRelease] = {} + releases_map: dict[str, Release] = {} for row in cursor: releases_map[row["id"]] = cached_release_from_view(c, row) - tracks: list[CachedTrack] = [] + tracks: list[Track] = [] for row in trackrows: playlist.track_ids.append(row["id"]) tracks.append(cached_track_from_view(c, row, releases_map[row["release_id"]])) @@ -2207,7 +2207,7 @@ def list_collages(c: Config) -> list[str]: return [r["name"] for r in cursor] -def get_collage(c: Config, collage_name: str) -> tuple[CachedCollage, list[CachedRelease]] | None: +def get_collage(c: Config, collage_name: str) -> tuple[Collage, list[Release]] | None: with connect(c) as conn: cursor = conn.execute( "SELECT name, source_mtime FROM collages WHERE name = ?", @@ -2216,7 +2216,7 @@ def get_collage(c: Config, collage_name: str) -> tuple[CachedCollage, list[Cache row = cursor.fetchone() if not row: return None - collage = CachedCollage( + collage = Collage( name=row["name"], source_mtime=row["source_mtime"], # Accumulated below when we query the releases. @@ -2232,7 +2232,7 @@ def get_collage(c: Config, collage_name: str) -> tuple[CachedCollage, list[Cache """, (collage_name,), ) - releases: list[CachedRelease] = [] + releases: list[Release] = [] for row in cursor: collage.release_ids.append(row["id"]) releases.append(cached_release_from_view(c, row)) diff --git a/rose/cache_test.py b/rose/cache_test.py index 1a54ad0..8d65efa 100644 --- a/rose/cache_test.py +++ b/rose/cache_test.py @@ -12,13 +12,13 @@ from rose.cache import ( CACHE_SCHEMA_PATH, STORED_DATA_FILE_REGEX, - CachedCollage, - CachedPlaylist, - CachedRelease, - CachedTrack, + Collage, DescriptorEntry, GenreEntry, LabelEntry, + Playlist, + Release, + Track, _unpack, artist_exists, collage_exists, @@ -1107,7 +1107,7 @@ def test_update_cache_playlists_on_release_rename(config: Config) -> None: @pytest.mark.usefixtures("seeded_cache") def test_list_releases(config: Config) -> None: expected = [ - CachedRelease( + Release( datafile_mtime="999", id="r1", source_path=Path(config.music_source_dir / "r1"), @@ -1142,7 +1142,7 @@ def test_list_releases(config: Config) -> None: releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]), metahash="1", ), - CachedRelease( + Release( datafile_mtime="999", id="r2", source_path=Path(config.music_source_dir / "r2"), @@ -1171,7 +1171,7 @@ def test_list_releases(config: Config) -> None: ), metahash="2", ), - CachedRelease( + Release( datafile_mtime="999", id="r3", source_path=Path(config.music_source_dir / "r3"), @@ -1205,7 +1205,7 @@ def test_list_releases(config: Config) -> None: def test_get_release_and_associated_tracks(config: Config) -> None: release = get_release(config, "r1") assert release is not None - assert release == CachedRelease( + assert release == Release( datafile_mtime="999", id="r1", source_path=Path(config.music_source_dir / "r1"), @@ -1242,7 +1242,7 @@ def test_get_release_and_associated_tracks(config: Config) -> None: ) expected_tracks = [ - CachedTrack( + Track( id="t1", source_path=config.music_source_dir / "r1" / "01.m4a", source_mtime="999", @@ -1255,7 +1255,7 @@ def test_get_release_and_associated_tracks(config: Config) -> None: metahash="1", release=release, ), - CachedTrack( + Track( id="t2", source_path=config.music_source_dir / "r1" / "02.m4a", source_mtime="999", @@ -1311,7 +1311,7 @@ def test_get_release_logtext(config: Config) -> None: @pytest.mark.usefixtures("seeded_cache") def test_list_tracks(config: Config) -> None: expected = [ - CachedTrack( + Track( id="t1", source_path=config.music_source_dir / "r1" / "01.m4a", source_mtime="999", @@ -1322,7 +1322,7 @@ def test_list_tracks(config: Config) -> None: duration_seconds=120, trackartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]), metahash="1", - release=CachedRelease( + release=Release( datafile_mtime="999", id="r1", source_path=Path(config.music_source_dir / "r1"), @@ -1358,7 +1358,7 @@ def test_list_tracks(config: Config) -> None: metahash="1", ), ), - CachedTrack( + Track( id="t2", source_path=config.music_source_dir / "r1" / "02.m4a", source_mtime="999", @@ -1369,7 +1369,7 @@ def test_list_tracks(config: Config) -> None: duration_seconds=240, trackartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]), metahash="2", - release=CachedRelease( + release=Release( datafile_mtime="999", id="r1", source_path=Path(config.music_source_dir / "r1"), @@ -1405,7 +1405,7 @@ def test_list_tracks(config: Config) -> None: metahash="1", ), ), - CachedTrack( + Track( id="t3", source_path=config.music_source_dir / "r2" / "01.m4a", source_mtime="999", @@ -1418,7 +1418,7 @@ def test_list_tracks(config: Config) -> None: main=[Artist("Violin Woman")], guest=[Artist("Conductor Woman")] ), metahash="3", - release=CachedRelease( + release=Release( id="r2", source_path=config.music_source_dir / "r2", cover_image_path=config.music_source_dir / "r2" / "cover.jpg", @@ -1448,7 +1448,7 @@ def test_list_tracks(config: Config) -> None: metahash="2", ), ), - CachedTrack( + Track( id="t4", source_path=config.music_source_dir / "r3" / "01.m4a", source_mtime="999", @@ -1459,7 +1459,7 @@ def test_list_tracks(config: Config) -> None: duration_seconds=120, trackartists=ArtistMapping(), metahash="4", - release=CachedRelease( + release=Release( id="r3", source_path=config.music_source_dir / "r3", cover_image_path=None, @@ -1492,7 +1492,7 @@ def test_list_tracks(config: Config) -> None: @pytest.mark.usefixtures("seeded_cache") def test_get_track(config: Config) -> None: - assert get_track(config, "t1") == CachedTrack( + assert get_track(config, "t1") == Track( id="t1", source_path=config.music_source_dir / "r1" / "01.m4a", source_mtime="999", @@ -1503,7 +1503,7 @@ def test_get_track(config: Config) -> None: duration_seconds=120, trackartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]), metahash="1", - release=CachedRelease( + release=Release( datafile_mtime="999", id="r1", source_path=Path(config.music_source_dir / "r1"), @@ -1630,13 +1630,13 @@ def test_get_collage(config: Config) -> None: cdata = get_collage(config, "Rose Gold") assert cdata is not None collage, releases = cdata - assert collage == CachedCollage( + assert collage == Collage( name="Rose Gold", source_mtime="999", release_ids=["r1", "r2"], ) assert releases == [ - CachedRelease( + Release( id="r1", source_path=config.music_source_dir / "r1", cover_image_path=None, @@ -1671,7 +1671,7 @@ def test_get_collage(config: Config) -> None: releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]), metahash="1", ), - CachedRelease( + Release( id="r2", source_path=config.music_source_dir / "r2", cover_image_path=config.music_source_dir / "r2" / "cover.jpg", @@ -1705,7 +1705,7 @@ def test_get_collage(config: Config) -> None: cdata = get_collage(config, "Ruby Red") assert cdata is not None collage, releases = cdata - assert collage == CachedCollage( + assert collage == Collage( name="Ruby Red", source_mtime="999", release_ids=[], @@ -1730,14 +1730,14 @@ def test_get_playlist(config: Config) -> None: pdata = get_playlist(config, "Lala Lisa") assert pdata is not None playlist, tracks = pdata - assert playlist == CachedPlaylist( + assert playlist == Playlist( name="Lala Lisa", source_mtime="999", cover_path=config.music_source_dir / "!playlists" / "Lala Lisa.jpg", track_ids=["t1", "t3"], ) assert tracks == [ - CachedTrack( + Track( id="t1", source_path=config.music_source_dir / "r1" / "01.m4a", source_mtime="999", @@ -1748,7 +1748,7 @@ def test_get_playlist(config: Config) -> None: duration_seconds=120, trackartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]), metahash="1", - release=CachedRelease( + release=Release( datafile_mtime="999", id="r1", source_path=Path(config.music_source_dir / "r1"), @@ -1784,7 +1784,7 @@ def test_get_playlist(config: Config) -> None: metahash="1", ), ), - CachedTrack( + Track( id="t3", source_path=config.music_source_dir / "r2" / "01.m4a", source_mtime="999", @@ -1797,7 +1797,7 @@ def test_get_playlist(config: Config) -> None: main=[Artist("Violin Woman")], guest=[Artist("Conductor Woman")] ), metahash="3", - release=CachedRelease( + release=Release( id="r2", source_path=config.music_source_dir / "r2", cover_image_path=config.music_source_dir / "r2" / "cover.jpg", diff --git a/rose/releases.py b/rose/releases.py index fa2c9a6..fccb8f3 100644 --- a/rose/releases.py +++ b/rose/releases.py @@ -21,8 +21,8 @@ from rose.audiotags import AudioTags, RoseDate from rose.cache import ( STORED_DATA_FILE_REGEX, - CachedRelease, - CachedTrack, + Release, + Track, calculate_release_logtext, get_release, get_tracks_associated_with_release, @@ -253,7 +253,7 @@ class MetadataRelease: tracks: dict[str, MetadataTrack] @classmethod - def from_cache(cls, release: CachedRelease, tracks: list[CachedTrack]) -> MetadataRelease: + def from_cache(cls, release: Release, tracks: list[Track]) -> MetadataRelease: return MetadataRelease( title=release.releasetitle, new=release.new, diff --git a/rose/releases_test.py b/rose/releases_test.py index 7c2c390..046cc82 100644 --- a/rose/releases_test.py +++ b/rose/releases_test.py @@ -10,8 +10,8 @@ from conftest import TEST_RELEASE_1 from rose.audiotags import AudioTags, RoseDate from rose.cache import ( - CachedRelease, - CachedTrack, + Release, + Track, connect, get_release, get_tracks_associated_with_release, @@ -181,7 +181,7 @@ def test_edit_release(monkeypatch: Any, config: Config, source_dir: Path) -> Non edit_release(config, release_id) release = get_release(config, release_id) assert release is not None - assert release == CachedRelease( + assert release == Release( id=release_id, source_path=release_path, cover_image_path=None, @@ -212,7 +212,7 @@ def test_edit_release(monkeypatch: Any, config: Config, source_dir: Path) -> Non ) tracks = get_tracks_associated_with_release(config, release) assert tracks == [ - CachedTrack( + Track( id=track_ids[0], source_path=release_path / "01.m4a", source_mtime=tracks[0].source_mtime, @@ -225,7 +225,7 @@ def test_edit_release(monkeypatch: Any, config: Config, source_dir: Path) -> Non metahash=tracks[0].metahash, release=release, ), - CachedTrack( + Track( id=track_ids[1], source_path=release_path / "02.m4a", source_mtime=tracks[1].source_mtime, @@ -355,7 +355,7 @@ def editfn(text: str, **_: Any) -> str: release = get_release(config, release_id) assert release is not None - assert release == CachedRelease( + assert release == Release( id=release_id, source_path=release_path, cover_image_path=None, @@ -381,7 +381,7 @@ def editfn(text: str, **_: Any) -> str: ) tracks = get_tracks_associated_with_release(config, release) assert tracks == [ - CachedTrack( + Track( id=track_ids[0], source_path=release_path / "01.m4a", source_mtime=tracks[0].source_mtime, @@ -394,7 +394,7 @@ def editfn(text: str, **_: Any) -> str: metahash=tracks[0].metahash, release=release, ), - CachedTrack( + Track( id=track_ids[1], source_path=release_path / "02.m4a", source_mtime=tracks[1].source_mtime, diff --git a/rose/rules.py b/rose/rules.py index d2401be..d905bd6 100644 --- a/rose/rules.py +++ b/rose/rules.py @@ -24,8 +24,8 @@ from rose.audiotags import AudioTags, RoseDate from rose.cache import ( - CachedRelease, - CachedTrack, + Release, + Track, connect, list_releases, list_tracks, @@ -679,8 +679,8 @@ def fast_search_for_matching_releases( def filter_track_false_positives_using_read_cache( matcher: MetadataMatcher, - tracks: list[CachedTrack], -) -> list[CachedTrack]: + tracks: list[Track], +) -> list[Track]: time_start = time.time() rval = [] for t in tracks: @@ -729,8 +729,8 @@ def filter_track_false_positives_using_read_cache( def filter_release_false_positives_using_read_cache( matcher: MetadataMatcher, - releases: list[CachedRelease], -) -> list[CachedRelease]: + releases: list[Release], +) -> list[Release]: time_start = time.time() rval = [] for r in releases: diff --git a/rose/templates.py b/rose/templates.py index e4a6930..80439a6 100644 --- a/rose/templates.py +++ b/rose/templates.py @@ -21,7 +21,7 @@ from rose.common import Artist, ArtistMapping, RoseExpectedError if typing.TYPE_CHECKING: - from rose.cache import CachedRelease, CachedTrack + from rose.cache import Release, Track from rose.config import Config RELEASE_TYPE_FORMATTER = { @@ -283,7 +283,7 @@ class PathContext: def eval_release_template( template: PathTemplate, - release: CachedRelease, + release: Release, context: PathContext | None = None, position: str | None = None, ) -> str: @@ -294,7 +294,7 @@ def eval_release_template( def eval_track_template( template: PathTemplate, - track: CachedTrack, + track: Track, context: PathContext | None = None, position: str | None = None, ) -> str: @@ -306,7 +306,7 @@ def eval_track_template( ) -def _calc_release_variables(release: CachedRelease, position: str | None) -> dict[str, Any]: +def _calc_release_variables(release: Release, position: str | None) -> dict[str, Any]: return { "added_at": release.added_at, "releasetitle": release.releasetitle, @@ -329,7 +329,7 @@ def _calc_release_variables(release: CachedRelease, position: str | None) -> dic } -def _calc_track_variables(track: CachedTrack, position: str | None) -> dict[str, Any]: +def _calc_track_variables(track: Track, position: str | None) -> dict[str, Any]: return { "added_at": track.release.added_at, "tracktitle": track.tracktitle, @@ -402,10 +402,10 @@ def preview_path_templates(c: Config) -> None: # fmt: on -def _get_preview_releases(c: Config) -> tuple[CachedRelease, CachedRelease, CachedRelease]: - from rose.cache import CachedRelease +def _get_preview_releases(c: Config) -> tuple[Release, Release, Release]: + from rose.cache import Release - kimlip = CachedRelease( + kimlip = Release( id="018b268e-ff1e-7a0c-9ac8-7bbb282761f2", source_path=c.music_source_dir / "LOONA - 2017. Kim Lip", cover_image_path=None, @@ -443,7 +443,7 @@ def _get_preview_releases(c: Config) -> tuple[CachedRelease, CachedRelease, Cach metahash="0", ) - youngforever = CachedRelease( + youngforever = Release( id="018b6021-f1e5-7d4b-b796-440fbbea3b13", source_path=c.music_source_dir / "BTS - 2016. Young Forever (花樣年華)", cover_image_path=None, @@ -484,7 +484,7 @@ def _get_preview_releases(c: Config) -> tuple[CachedRelease, CachedRelease, Cach metahash="0", ) - debussy = CachedRelease( + debussy = Release( id="018b268e-de0c-7cb2-8ffa-bcc2083c94e6", source_path=c.music_source_dir / "Debussy - 1907. Images performed by Cleveland Orchestra under Pierre Boulez (1992)", @@ -531,14 +531,14 @@ def _preview_release_template(c: Config, label: str, template: PathTemplate) -> def _preview_track_template(c: Config, label: str, template: PathTemplate) -> None: # Import cycle trick :) - from rose.cache import CachedTrack + from rose.cache import Track kimlip, youngforever, debussy = _get_preview_releases(c) click.secho(f"{label}:", dim=True, underline=True) click.secho(" Sample 1: ", dim=True, nl=False) - track = CachedTrack( + track = Track( id="018b268e-ff1e-7a0c-9ac8-7bbb282761f1", source_path=c.music_source_dir / "LOONA - 2017. Kim Lip" / "01. Eclipse.opus", source_mtime="999", @@ -554,7 +554,7 @@ def _preview_track_template(c: Config, label: str, template: PathTemplate) -> No click.secho(eval_track_template(template, track, position="1")) click.secho(" Sample 2: ", dim=True, nl=False) - track = CachedTrack( + track = Track( id="018b6021-f1e5-7d4b-b796-440fbbea3b15", source_path=c.music_source_dir / "BTS - 2016. Young Forever (花樣年華)" @@ -572,7 +572,7 @@ def _preview_track_template(c: Config, label: str, template: PathTemplate) -> No click.secho(eval_track_template(template, track, position="2")) click.secho(" Sample 3: ", dim=True, nl=False) - track = CachedTrack( + track = Track( id="018b6514-6e65-78cc-94a5-fdb17418f090", source_path=c.music_source_dir / "Debussy - 1907. Images performed by Cleveland Orchestra under Pierre Boulez (1992)" diff --git a/rose/templates_test.py b/rose/templates_test.py index cd6fe0e..f716c06 100644 --- a/rose/templates_test.py +++ b/rose/templates_test.py @@ -5,7 +5,7 @@ from click.testing import CliRunner from rose.audiotags import RoseDate -from rose.cache import CachedRelease, CachedTrack +from rose.cache import Release, Track from rose.common import Artist, ArtistMapping from rose.config import Config from rose.templates import ( @@ -17,7 +17,7 @@ preview_path_templates, ) -EMPTY_CACHED_RELEASE = CachedRelease( +EMPTY_CACHED_RELEASE = Release( id="", source_path=Path(), cover_image_path=None, @@ -42,7 +42,7 @@ metahash="0", ) -EMPTY_CACHED_TRACK = CachedTrack( +EMPTY_CACHED_TRACK = Track( id="", source_path=Path("hi.m4a"), source_mtime="", diff --git a/rose_vfs/virtualfs.py b/rose_vfs/virtualfs.py index eb0ded9..8e701cf 100644 --- a/rose_vfs/virtualfs.py +++ b/rose_vfs/virtualfs.py @@ -58,12 +58,12 @@ STORED_DATA_FILE_REGEX, SUPPORTED_AUDIO_EXTENSIONS, AudioTags, - CachedRelease, - CachedTrack, Config, PathContext, PathTemplate, + Release, RoseError, + Track, add_release_to_collage, add_track_to_playlist, artist_exists, @@ -409,8 +409,8 @@ def __init__(self, config: Config, sanitizer: Sanitizer): def list_release_paths( self, release_parent: VirtualPath, - releases: list[CachedRelease], - ) -> Iterator[tuple[CachedRelease, str]]: + releases: list[Release], + ) -> Iterator[tuple[Release, str]]: """ Given a parent directory and a list of releases, calculates the virtual directory names for those releases, and returns a zipped iterator of the releases and their virtual @@ -521,8 +521,8 @@ def list_release_paths( def list_track_paths( self, track_parent: VirtualPath, - tracks: list[CachedTrack], - ) -> Iterator[tuple[CachedTrack, str]]: + tracks: list[Track], + ) -> Iterator[tuple[Track, str]]: """ Given a parent directory and a list of tracks, calculates the virtual filenames for those tracks, and returns a zipped iterator of the tracks and their virtual filenames.