diff --git a/alembic/versions/fe0956c93730_new_field_artists.py b/alembic/versions/fe0956c93730_new_field_artists.py new file mode 100644 index 00000000..77fdeb56 --- /dev/null +++ b/alembic/versions/fe0956c93730_new_field_artists.py @@ -0,0 +1,34 @@ +"""new field: artists. + +Revision ID: fe0956c93730 +Revises: 6d4e785df5cb +Create Date: 2022-10-06 18:26:11.939381 + +""" +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "fe0956c93730" +down_revision = "6d4e785df5cb" +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table( + "artist", + sa.Column("_id", sa.Integer(), nullable=False), + sa.Column("_track_id", sa.Integer(), nullable=True), + sa.Column("name", sa.String(), nullable=False), + sa.ForeignKeyConstraint( + ["_track_id"], + ["track._id"], + ), + sa.PrimaryKeyConstraint("_id"), + ) + + +def downgrade(): + op.drop_table("artist") diff --git a/docs/fields.rst b/docs/fields.rst index d66914b1..f06c9b61 100644 --- a/docs/fields.rst +++ b/docs/fields.rst @@ -18,6 +18,7 @@ Track Fields "album", "Album title", "" "albumartist", "Album artist", "" "artist", "Track artist", "" + "artists", "Set of track artists.", "Supports multiple values" "date", "Album release date", "YYYY-MM-DD format" "disc", "Disc number", "" "disc_total", "Number of discs in the album", "" diff --git a/moe/plugins/edit/edit_core.py b/moe/plugins/edit/edit_core.py index c1a1b5ba..b6923485 100644 --- a/moe/plugins/edit/edit_core.py +++ b/moe/plugins/edit/edit_core.py @@ -3,6 +3,8 @@ import datetime import logging +import sqlalchemy.ext.associationproxy + from moe.library import LibItem __all__ = ["EditError", "edit_item"] @@ -40,6 +42,10 @@ def edit_item(item: LibItem, field: str, value: str): setattr(item, field, value) elif isinstance(attr, int): setattr(item, field, int(value)) + elif isinstance(attr, set) or isinstance( + attr, sqlalchemy.ext.associationproxy._AssociationSet + ): + setattr(item, field, {value.strip() for value in value.split(";")}) elif isinstance(attr, datetime.date): try: setattr(item, field, datetime.date.fromisoformat(value)) diff --git a/moe/plugins/write.py b/moe/plugins/write.py index 45db2c88..0e0e8bd8 100644 --- a/moe/plugins/write.py +++ b/moe/plugins/write.py @@ -76,6 +76,7 @@ def write_custom_tags(track: Track): audio_file.album = track.album audio_file.albumartist = track.albumartist audio_file.artist = track.artist + audio_file.artists = track.artists audio_file.date = track.date audio_file.disc = track.disc audio_file.disctotal = track.disc_total diff --git a/pyproject.toml b/pyproject.toml index b6786d41..037653bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ moe = 'moe.cli:main' python = ">=3.9, <3.11" alembic = "^1.4.2" dynaconf = "^3.1.4" -mediafile = "^0.6.0" +mediafile = "^0.9.0" musicbrainzngs = "^0.7.1" pluggy = "^0.13.1" pyyaml = "^5.3.1" diff --git a/tests/library/test_track.py b/tests/library/test_track.py index 4ed8accf..1b62fc07 100644 --- a/tests/library/test_track.py +++ b/tests/library/test_track.py @@ -118,6 +118,7 @@ def test_read_tags(self, tmp_config): track.album = "The Lost Album" track.albumartist = "Wu-Tang Clan" track.artist = "Wu-Tang Clan" + track.artists = {"Wu-Tang Clan", "Me"} track.date = datetime.date(2020, 1, 12) track.disc = 1 track.disc_total = 2 @@ -131,6 +132,7 @@ def test_read_tags(self, tmp_config): assert new_track.album == track.album assert new_track.albumartist == track.albumartist assert new_track.artist == track.artist + assert new_track.artists == track.artists assert new_track.date == track.date assert new_track.disc == track.disc assert new_track.disc_total == track.disc_total diff --git a/tests/plugins/edit/test_edit_core.py b/tests/plugins/edit/test_edit_core.py index 2f2dbd1e..7a21e3f1 100644 --- a/tests/plugins/edit/test_edit_core.py +++ b/tests/plugins/edit/test_edit_core.py @@ -44,12 +44,12 @@ def test_invalid_date_field(self): with pytest.raises(edit.EditError): edit.edit_item(track_factory(), "date", "2020") - def test_list_field(self): - """We can edit list fields.""" + def test_set_field(self): + """We can edit set fields.""" track = track_factory() - edit.edit_item(track, "genre", "a; b") + edit.edit_item(track, "artists", "a; b") - assert set(track.genres) == {"a", "b"} + assert track.artists == {"a", "b"} def test_non_editable_fields(self): """Editing paths is not currently supported.""" diff --git a/tests/plugins/test_write.py b/tests/plugins/test_write.py index 53c6de2c..11d19577 100644 --- a/tests/plugins/test_write.py +++ b/tests/plugins/test_write.py @@ -65,6 +65,7 @@ def test_write_tags(self, tmp_config): album = "Bigger, Better, Faster, More!" albumartist = "4 Non Blondes" artist = "4 Non Blondes" + artists = {"4 Non Blondes", "Me"} date = datetime.date(1996, 10, 13) disc = 2 disc_total = 2 @@ -75,6 +76,7 @@ def test_write_tags(self, tmp_config): track.album = album track.albumartist = albumartist track.artist = artist + track.artists = artists track.date = date track.disc = disc track.disc_total = disc_total @@ -88,6 +90,7 @@ def test_write_tags(self, tmp_config): assert new_track.album == album assert new_track.albumartist == albumartist assert new_track.artist == artist + assert new_track.artists == artists assert new_track.date == date assert new_track.disc == disc assert new_track.disc_total == disc_total