diff --git a/conftest.py b/conftest.py index 4d70f71..571f5d3 100644 --- a/conftest.py +++ b/conftest.py @@ -113,10 +113,10 @@ def seeded_cache(config: Config) -> None: conn.executescript( f"""\ INSERT INTO releases - (id , source_path , cover_image_path , added_at , datafile_mtime, title , releasetype, releasedate, originaldate, compositiondate, catalognumber, edition , disctotal, new , metahash) -VALUES ('r1', '{dirpaths[0]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 1', 'album' , 2023 , null , null , null , null , 1 , false, '1') - , ('r2', '{dirpaths[1]}', '{imagepaths[0]}', '0000-01-01T00:00:00+00:00', '999' , 'Release 2', 'album' , 2021 , 2019 , null , 'DG-001' , 'Deluxe', 1 , false, '2') - , ('r3', '{dirpaths[2]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 3', 'album' , 2021 , null , 1780 , 'DG-002' , null , 1 , true , '3'); + (id , source_path , cover_image_path , added_at , datafile_mtime, title , releasetype, releasedate , originaldate, compositiondate, catalognumber, edition , disctotal, new , metahash) +VALUES ('r1', '{dirpaths[0]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 1', 'album' , '2023' , null , null , null , null , 1 , false, '1') + , ('r2', '{dirpaths[1]}', '{imagepaths[0]}', '0000-01-01T00:00:00+00:00', '999' , 'Release 2', 'album' , '2021' , '2019' , null , 'DG-001' , 'Deluxe', 1 , false, '2') + , ('r3', '{dirpaths[2]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 3', 'album' , '2021-04-20', null , '1780' , 'DG-002' , null , 1 , true , '3'); INSERT INTO releases_genres (release_id, genre , position) diff --git a/rose/audiotags.py b/rose/audiotags.py index 8134949..c177d77 100644 --- a/rose/audiotags.py +++ b/rose/audiotags.py @@ -91,7 +91,7 @@ class RoseDate: def parse(cls, value: str | None) -> RoseDate | None: if not value: return None - if YEAR_REGEX.match(value): + with contextlib.suppress(ValueError): return RoseDate(year=int(value), month=None, day=None) # There may be a time value after the date... allow that and other crap. if m := DATE_REGEX.match(value): diff --git a/rose/cache.py b/rose/cache.py index 569474e..0dba38a 100644 --- a/rose/cache.py +++ b/rose/cache.py @@ -237,9 +237,9 @@ def from_view(cls, c: Config, row: dict[str, Any], aliases: bool = True) -> Cach datafile_mtime=row["datafile_mtime"], releasetitle=row["releasetitle"], releasetype=row["releasetype"], - releasedate=row["releasedate"], - originaldate=row["originaldate"], - compositiondate=row["compositiondate"], + releasedate=RoseDate.parse(row["releasedate"]), + originaldate=RoseDate.parse(row["originaldate"]), + compositiondate=RoseDate.parse(row["compositiondate"]), catalognumber=row["catalognumber"], edition=row["edition"], disctotal=row["disctotal"], @@ -266,9 +266,9 @@ def dump(self) -> dict[str, Any]: "added_at": self.added_at, "releasetitle": self.releasetitle, "releasetype": self.releasetype, - "releasedate": str(self.releasedate), - "originaldate": str(self.originaldate), - "compositiondate": str(self.compositiondate), + "releasedate": str(self.releasedate) if self.releasedate else None, + "originaldate": str(self.originaldate) if self.originaldate else None, + "compositiondate": str(self.compositiondate) if self.compositiondate else None, "catalognumber": self.catalognumber, "edition": self.edition, "new": self.new, @@ -344,9 +344,15 @@ def dump(self, with_release_info: bool = True) -> dict[str, Any]: "releasetitle": self.release.releasetitle, "releasetype": self.release.releasetype, "disctotal": self.release.disctotal, - "releasedate": str(self.release.releasedate), - "originaldate": str(self.release.originaldate), - "compositiondate": str(self.release.compositiondate), + "releasedate": str(self.release.releasedate) + if self.release.releasedate + else None, + "originaldate": str(self.release.originaldate) + if self.release.originaldate + else None, + "compositiondate": str(self.release.compositiondate) + if self.release.compositiondate + else None, "catalognumber": self.release.catalognumber, "edition": self.release.edition, "new": self.release.new, @@ -1034,9 +1040,9 @@ def _update_cache_for_releases_executor( release.datafile_mtime, release.releasetitle, release.releasetype, - release.releasedate, - release.originaldate, - release.compositiondate, + str(release.releasedate) if release.releasedate else None, + str(release.originaldate) if release.originaldate else None, + str(release.compositiondate) if release.compositiondate else None, release.edition, release.catalognumber, release.disctotal, @@ -1507,7 +1513,7 @@ def update_cache_for_collages( for row in cursor: desc_map[row["id"]] = calculate_release_logtext( title=row["releasetitle"], - releasedate=row["releasedate"], + releasedate=RoseDate.parse(row["releasedate"]), artists=_unpack_artists( c, row["releaseartist_names"], row["releaseartist_roles"] ), @@ -1735,7 +1741,7 @@ def update_cache_for_playlists( artists=_unpack_artists( c, row["trackartist_names"], row["trackartist_roles"] ), - releasedate=row["releasedate"], + releasedate=RoseDate.parse(row["releasedate"]), suffix=Path(row["source_path"]).suffix, ) for i, trk in enumerate(tracks): @@ -1903,7 +1909,7 @@ def get_release_logtext(c: Config, release_id: str) -> str | None: return None return calculate_release_logtext( title=row["releasetitle"], - releasedate=row["releasedate"], + releasedate=RoseDate.parse(row["releasedate"]), artists=_unpack_artists(c, row["releaseartist_names"], row["releaseartist_roles"]), ) @@ -2080,7 +2086,7 @@ def get_track_logtext(c: Config, track_id: str) -> str | None: return calculate_track_logtext( title=row["tracktitle"], artists=_unpack_artists(c, row["trackartist_names"], row["trackartist_roles"]), - releasedate=row["releasedate"], + releasedate=RoseDate.parse(row["releasedate"]), suffix=Path(row["source_path"]).suffix, ) diff --git a/rose/cache.sql b/rose/cache.sql index 2d0f999..b5f8b1a 100644 --- a/rose/cache.sql +++ b/rose/cache.sql @@ -14,9 +14,9 @@ CREATE TABLE releases ( datafile_mtime TEXT NOT NULL, title TEXT NOT NULL, releasetype TEXT NOT NULL, - releasedate INTEGER, - originaldate INTEGER, - compositiondate INTEGER, + releasedate TEXT, + originaldate TEXT, + compositiondate TEXT, edition TEXT, catalognumber TEXT, disctotal INTEGER NOT NULL, diff --git a/rose/cache_test.py b/rose/cache_test.py index 2a34860..c5fa1d0 100644 --- a/rose/cache_test.py +++ b/rose/cache_test.py @@ -183,7 +183,7 @@ def test_update_cache_releases(config: Config) -> None: assert row["source_path"] == str(release_dir) assert row["title"] == "I Love Blackpink" assert row["releasetype"] == "album" - assert row["releasedate"] == 1990 + assert row["releasedate"] == "1990-02-05" assert row["compositiondate"] is None assert row["catalognumber"] is None assert row["new"] @@ -317,7 +317,7 @@ def test_update_cache_releases_already_fully_cached(config: Config) -> None: assert row["source_path"] == str(release_dir) assert row["title"] == "I Love Blackpink" assert row["releasetype"] == "album" - assert row["releasedate"] == 1990 + assert row["releasedate"] == "1990-02-05" assert row["new"] @@ -342,7 +342,7 @@ def test_update_cache_releases_disk_update_to_previously_cached(config: Config) assert row["source_path"] == str(release_dir) assert row["title"] == "I Love Blackpink" assert row["releasetype"] == "album" - assert row["releasedate"] == 1990 + assert row["releasedate"] == "1990-02-05" assert row["new"] @@ -402,7 +402,7 @@ def test_update_cache_releases_source_path_renamed(config: Config) -> None: assert row["source_path"] == str(moved_release_dir) assert row["title"] == "I Love Blackpink" assert row["releasetype"] == "album" - assert row["releasedate"] == 1990 + assert row["releasedate"] == "1990-02-05" assert row["new"] @@ -1153,7 +1153,7 @@ def test_list_releases(config: Config) -> None: added_at="0000-01-01T00:00:00+00:00", releasetitle="Release 3", releasetype="album", - releasedate=RoseDate(2021), + releasedate=RoseDate(2021, 4, 20), compositiondate=RoseDate(1780), catalognumber="DG-002", disctotal=1, @@ -1441,7 +1441,7 @@ def test_list_tracks(config: Config) -> None: datafile_mtime="999", releasetitle="Release 3", releasetype="album", - releasedate=RoseDate(2021), + releasedate=RoseDate(2021, 4, 20), compositiondate=RoseDate(1780), catalognumber="DG-002", new=True, diff --git a/rose/collages_test.py b/rose/collages_test.py index 5348ac3..267a290 100644 --- a/rose/collages_test.py +++ b/rose/collages_test.py @@ -132,7 +132,7 @@ def test_dump_collage(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -177,7 +177,7 @@ def test_dump_collage(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, @@ -185,7 +185,7 @@ def test_dump_collage(config: Config) -> None: "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ @@ -222,7 +222,7 @@ def test_dump_collages(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -267,7 +267,7 @@ def test_dump_collages(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, @@ -275,7 +275,7 @@ def test_dump_collages(config: Config) -> None: "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ diff --git a/rose/playlists_test.py b/rose/playlists_test.py index b4c9588..cd18182 100644 --- a/rose/playlists_test.py +++ b/rose/playlists_test.py @@ -157,7 +157,7 @@ def test_dump_playlist(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -216,14 +216,14 @@ def test_dump_playlist(config: Config) -> None: "release_id": "r2", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ @@ -279,7 +279,7 @@ def test_dump_playlists(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -338,14 +338,14 @@ def test_dump_playlists(config: Config) -> None: "release_id": "r2", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ diff --git a/rose/releases.py b/rose/releases.py index 61ce8a5..004cc7e 100644 --- a/rose/releases.py +++ b/rose/releases.py @@ -281,9 +281,9 @@ def serialize(self) -> str: # LOL TOML DOESN'T HAVE A NULL TYPE. Use -9999 as sentinel. If your music is legitimately # released in -9999, you should probably lay off the shrooms. data = asdict(self) - data["releasedate"] = self.releasedate or -9999 - data["originaldate"] = self.originaldate or -9999 - data["compositiondate"] = self.compositiondate or -9999 + data["releasedate"] = str(self.releasedate) if self.releasedate else "" + data["originaldate"] = str(self.originaldate) if self.originaldate else "" + data["compositiondate"] = str(self.compositiondate) if self.compositiondate else "" data["edition"] = self.edition or -9999 data["catalognumber"] = self.catalognumber or "" return tomli_w.dumps(data) @@ -502,7 +502,7 @@ def create_single_release(c: Config, track_path: Path) -> None: dirname = f"{artistsfmt(af.trackartists)} - " if af.releasedate: - dirname += f"{af.releasedate}. " + dirname += f"{af.releasedate.year}. " dirname += title # Handle directory name collisions. collision_no = 2 diff --git a/rose/releases_test.py b/rose/releases_test.py index b1c74eb..b25998d 100644 --- a/rose/releases_test.py +++ b/rose/releases_test.py @@ -455,7 +455,7 @@ def test_dump_release(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -548,7 +548,7 @@ def test_dump_releases(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -636,7 +636,7 @@ def test_dump_releases(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, @@ -644,7 +644,7 @@ def test_dump_releases(config: Config) -> None: "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ @@ -689,8 +689,8 @@ def test_dump_releases(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 3", "releasetype": "album", - "releasedate": 2021, - "compositiondate": 1780, + "releasedate": "2021-04-20", + "compositiondate": "1780", "catalognumber": "DG-002", "new": True, "disctotal": 1, @@ -746,7 +746,7 @@ def test_dump_releases_matcher(config: Config) -> None: "added_at": "0000-01-01T00:00:00+00:00", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, @@ -754,7 +754,7 @@ def test_dump_releases_matcher(config: Config) -> None: "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ diff --git a/rose/templates.py b/rose/templates.py index 39ac466..3e9131d 100644 --- a/rose/templates.py +++ b/rose/templates.py @@ -145,7 +145,7 @@ class PathTemplatePair: DEFAULT_RELEASE_TEMPLATE = PathTemplate( """ {{ releaseartists | artistsfmt }} - -{% if releasedate %}{{ releasedate }}.{% endif %} +{% if releasedate %}{{ releasedate.year }}.{% endif %} {{ releasetitle }} {% if releasetype == "single" %}- {{ releasetype | releasetypefmt }}{% endif %} {% if new %}[NEW]{% endif %} diff --git a/rose/tracks_test.py b/rose/tracks_test.py index 2e76670..b96555b 100644 --- a/rose/tracks_test.py +++ b/rose/tracks_test.py @@ -46,7 +46,7 @@ def test_dump_tracks(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -107,7 +107,7 @@ def test_dump_tracks(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -165,14 +165,14 @@ def test_dump_tracks(config: Config) -> None: "release_id": "r2", "releasetitle": "Release 2", "releasetype": "album", - "releasedate": 2021, + "releasedate": "2021", "compositiondate": None, "catalognumber": "DG-001", "new": False, "genres": ["Classical"], "parent_genres": [], "labels": ["Native State"], - "originaldate": 2019, + "originaldate": "2019", "edition": "Deluxe", "secondary_genres": ["Orchestral"], "parent_secondary_genres": [ @@ -212,8 +212,8 @@ def test_dump_tracks(config: Config) -> None: "release_id": "r3", "releasetitle": "Release 3", "releasetype": "album", - "releasedate": 2021, - "compositiondate": 1780, + "releasedate": "2021-04-20", + "compositiondate": "1780", "catalognumber": "DG-002", "new": True, "genres": [], @@ -266,7 +266,7 @@ def test_dump_tracks_with_matcher(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -327,7 +327,7 @@ def test_dump_tracks_with_matcher(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False, @@ -393,7 +393,7 @@ def test_dump_track(config: Config) -> None: "release_id": "r1", "releasetitle": "Release 1", "releasetype": "album", - "releasedate": 2023, + "releasedate": "2023", "compositiondate": None, "catalognumber": None, "new": False,