Skip to content

Commit

Permalink
codegen a subgenre dict from rym metadata and return parent_genres
Browse files Browse the repository at this point in the history
…from releases/tracks (#95)
  • Loading branch information
azuline authored Apr 20, 2024
1 parent 030d1c4 commit 33ee799
Show file tree
Hide file tree
Showing 13 changed files with 22,623 additions and 6 deletions.
17 changes: 16 additions & 1 deletion rose/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
uniq,
)
from rose.config import Config
from rose.genre_hierarchy import PARENT_GENRES
from rose.templates import artistsfmt, eval_release_template, eval_track_template

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -214,12 +215,14 @@ class CachedRelease:
new: bool
disctotal: int
genres: list[str]
parent_genres: list[str]
labels: list[str]
releaseartists: ArtistMapping
metahash: str

@classmethod
def from_view(cls, c: Config, row: dict[str, Any], aliases: bool = True) -> CachedRelease:
genres = _split(row["genres"]) if row["genres"] else []
return CachedRelease(
id=row["id"],
source_path=Path(row["source_path"]),
Expand All @@ -233,7 +236,8 @@ def from_view(cls, c: Config, row: dict[str, Any], aliases: bool = True) -> Cach
catalognumber=row["catalognumber"],
disctotal=row["disctotal"],
new=bool(row["new"]),
genres=_split(row["genres"]) if row["genres"] else [],
genres=genres,
parent_genres=_get_parent_genres(genres),
labels=_split(row["labels"]) if row["labels"] else [],
releaseartists=_unpack_artists(
c, row["releaseartist_names"], row["releaseartist_roles"], aliases=aliases
Expand All @@ -257,6 +261,7 @@ def dump(self) -> dict[str, Any]:
"new": self.new,
"disctotal": self.disctotal,
"genres": self.genres,
"parent_genres": self.parent_genres,
"labels": self.labels,
"releaseartists": self.releaseartists.dump(),
}
Expand Down Expand Up @@ -328,6 +333,7 @@ def dump(self, with_release_info: bool = True) -> dict[str, Any]:
"catalognumber": self.release.catalognumber,
"new": self.release.new,
"genres": self.release.genres,
"parent_genres": self.release.parent_genres,
"labels": self.release.labels,
"releaseartists": self.release.releaseartists.dump(),
}
Expand Down Expand Up @@ -626,6 +632,7 @@ def _update_cache_for_releases_executor(
new=True,
disctotal=0,
genres=[],
parent_genres=[],
labels=[],
releaseartists=ArtistMapping(),
metahash="",
Expand Down Expand Up @@ -1702,6 +1709,7 @@ def list_releases_delete_this(
"""
args.extend(sanitized_artists)
if sanitized_genre_filter:
# TODO(NOW): Umm.. sanitized to not sanitized?
query += """
AND EXISTS (
SELECT * FROM releases_genres
Expand Down Expand Up @@ -2172,6 +2180,13 @@ def _unpack_artists(
return mapping


def _get_parent_genres(genres: list[str]) -> list[str]:
rval: set[str] = set()
for g in genres:
rval.update(PARENT_GENRES.get(g, []))
return sorted(rval)


def _flatten(xxs: list[list[T]]) -> list[T]:
xs: list[T] = []
for group in xxs:
Expand Down
48 changes: 48 additions & 0 deletions rose/cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,12 @@ def test_list_releases(config: Config) -> None:
disctotal=1,
new=False,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand All @@ -1068,6 +1074,7 @@ def test_list_releases(config: Config) -> None:
disctotal=1,
new=False,
genres=["Classical"],
parent_genres=[],
labels=["Native State"],
releaseartists=ArtistMapping(
main=[Artist("Violin Woman")], guest=[Artist("Conductor Woman")]
Expand All @@ -1088,6 +1095,7 @@ def test_list_releases(config: Config) -> None:
disctotal=1,
new=True,
genres=[],
parent_genres=[],
labels=[],
releaseartists=ArtistMapping(),
metahash="3",
Expand Down Expand Up @@ -1116,6 +1124,12 @@ def test_get_release_and_associated_tracks(config: Config) -> None:
disctotal=1,
new=False,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand Down Expand Up @@ -1206,6 +1220,12 @@ def test_list_tracks(config: Config) -> None:
disctotal=1,
new=False,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand Down Expand Up @@ -1236,6 +1256,12 @@ def test_list_tracks(config: Config) -> None:
disctotal=1,
new=False,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand Down Expand Up @@ -1268,6 +1294,7 @@ def test_list_tracks(config: Config) -> None:
new=False,
disctotal=1,
genres=["Classical"],
parent_genres=[],
labels=["Native State"],
releaseartists=ArtistMapping(
main=[Artist("Violin Woman")], guest=[Artist("Conductor Woman")]
Expand Down Expand Up @@ -1300,6 +1327,7 @@ def test_list_tracks(config: Config) -> None:
new=True,
disctotal=1,
genres=[],
parent_genres=[],
labels=[],
releaseartists=ArtistMapping(),
metahash="3",
Expand Down Expand Up @@ -1338,6 +1366,12 @@ def test_get_track(config: Config) -> None:
disctotal=1,
new=False,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand Down Expand Up @@ -1430,6 +1464,12 @@ def test_get_collage(config: Config) -> None:
new=False,
disctotal=1,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand All @@ -1448,6 +1488,7 @@ def test_get_collage(config: Config) -> None:
new=False,
disctotal=1,
genres=["Classical"],
parent_genres=[],
labels=["Native State"],
releaseartists=ArtistMapping(
main=[Artist("Violin Woman")], guest=[Artist("Conductor Woman")]
Expand Down Expand Up @@ -1516,6 +1557,12 @@ def test_get_playlist(config: Config) -> None:
disctotal=1,
new=False,
genres=["Techno", "Deep House"],
parent_genres=[
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
labels=["Silk Music"],
releaseartists=ArtistMapping(main=[Artist("Techno Man"), Artist("Bass Man")]),
metahash="1",
Expand Down Expand Up @@ -1548,6 +1595,7 @@ def test_get_playlist(config: Config) -> None:
new=False,
disctotal=1,
genres=["Classical"],
parent_genres=[],
labels=["Native State"],
releaseartists=ArtistMapping(
main=[Artist("Violin Woman")], guest=[Artist("Conductor Woman")]
Expand Down
14 changes: 14 additions & 0 deletions rose/collages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def test_dump_collage(config: Config) -> None:
"new": False,
"disctotal": 1,
"genres": ["Techno", "Deep House"],
"parent_genres": [
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
"labels": ["Silk Music"],
"releaseartists": {
"main": [
Expand Down Expand Up @@ -166,6 +172,7 @@ def test_dump_collage(config: Config) -> None:
"new": False,
"disctotal": 1,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"releaseartists": {
"main": [{"name": "Violin Woman", "alias": False}],
Expand Down Expand Up @@ -202,6 +209,12 @@ def test_dump_collages(config: Config) -> None:
"new": False,
"disctotal": 1,
"genres": ["Techno", "Deep House"],
"parent_genres": [
"Dance",
"Electronic",
"Electronic Dance Music",
"House",
],
"labels": ["Silk Music"],
"releaseartists": {
"main": [
Expand Down Expand Up @@ -230,6 +243,7 @@ def test_dump_collages(config: Config) -> None:
"new": False,
"disctotal": 1,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"releaseartists": {
"main": [{"name": "Violin Woman", "alias": False}],
Expand Down
Loading

0 comments on commit 33ee799

Please sign in to comment.