Skip to content

Commit

Permalink
feat: new track field - artists
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Oct 7, 2022
1 parent b0665e8 commit 7701d9e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
34 changes: 34 additions & 0 deletions 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")
1 change: 1 addition & 0 deletions docs/fields.rst
Expand Up @@ -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", ""
Expand Down
6 changes: 6 additions & 0 deletions moe/plugins/edit/edit_core.py
Expand Up @@ -3,6 +3,8 @@
import datetime
import logging

import sqlalchemy.ext.associationproxy

from moe.library import LibItem

__all__ = ["EditError", "edit_item"]
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions moe/plugins/write.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tests/library/test_track.py
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/plugins/edit/test_edit_core.py
Expand Up @@ -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."""
Expand Down
3 changes: 3 additions & 0 deletions tests/plugins/test_write.py
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7701d9e

Please sign in to comment.