Skip to content

Commit

Permalink
feat: new album field - media
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Oct 8, 2022
1 parent ddc9272 commit 256a3a6
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions alembic/versions/60608d9d2908_new_field_media.py
@@ -0,0 +1,26 @@
"""new field: media.
Revision ID: 60608d9d2908
Revises: fe0956c93730
Create Date: 2022-10-06 20:26:02.640360
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "60608d9d2908"
down_revision = "fe0956c93730"
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table("album", schema=None) as batch_op:
batch_op.add_column(sa.Column("media", sa.String(), nullable=True))


def downgrade():
with op.batch_alter_table("album", schema=None) as batch_op:
batch_op.drop_column("media")
1 change: 1 addition & 0 deletions docs/fields.rst
Expand Up @@ -36,6 +36,7 @@ Album Fields
"artist", "Album artist", ""
"date", "Album release date", "YYYY-MM-DD format"
"disc_total", "Number of discs in the album", ""
"media", "Album release format (e.g. CD, Digital, etc.)", ""
"path", "Filesystem path of the album", ""
"title", "Album title", ""
"year", "Album release year", ""
Expand Down
3 changes: 3 additions & 0 deletions moe/library/album.py
Expand Up @@ -88,6 +88,7 @@ class Album(LibItem, SABase):
date (datetime.date): Album release date.
disc_total (int): Number of discs in the album.
extras (list[Extra]): Extra non-track files associated with the album.
media (str): Album release format (e.g. CD, Digital, etc.)
path (pathlib.Path): Filesystem path of the album directory.
title (str)
tracks (list[Track]): Album's corresponding tracks.
Expand All @@ -101,6 +102,7 @@ class Album(LibItem, SABase):
artist: str = cast(str, Column(String, nullable=False))
date: datetime.date = cast(datetime.date, Column(Date, nullable=False))
disc_total: int = cast(int, Column(Integer, nullable=False, default=1))
media: str = cast(str, Column(String, nullable=True))
path: Path = cast(Path, Column(PathType, nullable=False, unique=True))
title: str = cast(str, Column(String, nullable=False))
_custom_fields: dict[str, Any] = cast(
Expand Down Expand Up @@ -207,6 +209,7 @@ def fields(self) -> set[str]:
"date",
"disc_total",
"extras",
"media",
"path",
"title",
"tracks",
Expand Down
1 change: 1 addition & 0 deletions moe/library/track.py
Expand Up @@ -113,6 +113,7 @@ def read_custom_tags(
album_fields["artist"] = audio_file.albumartist or audio_file.artist
album_fields["date"] = audio_file.date
album_fields["disc_total"] = audio_file.disctotal
album_fields["media"] = audio_file.media
album_fields["path"] = track_path.parent
album_fields["title"] = audio_file.album

Expand Down
1 change: 1 addition & 0 deletions moe/plugins/musicbrainz/mb_core.py
Expand Up @@ -400,6 +400,7 @@ def _create_album(release: dict) -> Album:
date=datetime.date(year, month, day),
disc_total=int(release["medium-count"]),
mb_album_id=release["id"],
media=release["medium-list"][0]["format"],
title=release["title"],
path=None, # type: ignore # this will get set in `add_prompt`
)
Expand Down
1 change: 1 addition & 0 deletions moe/plugins/write.py
Expand Up @@ -81,6 +81,7 @@ def write_custom_tags(track: Track):
audio_file.disc = track.disc
audio_file.disctotal = track.album_obj.disc_total
audio_file.genres = track.genres
audio_file.media = track.album_obj.media
audio_file.title = track.title
audio_file.track = track.track_num

Expand Down
2 changes: 2 additions & 0 deletions tests/library/test_track.py
Expand Up @@ -128,6 +128,7 @@ def test_read_tags(self, tmp_config):

album.date = datetime.date(2020, 1, 12)
album.disc_total = 2
album.media = "CD"
write_tags(track)

new_track = Track.from_file(track.path)
Expand All @@ -144,6 +145,7 @@ def test_read_tags(self, tmp_config):

assert new_album.disc_total == album.disc_total
assert new_album.date == album.date
assert new_album.media == album.media

def test_non_track_file(self):
"""Raise `TrackError` if the given path does not correspond to a track file."""
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/musicbrainz/resources/full_release.py
Expand Up @@ -1681,6 +1681,7 @@ def album() -> Album:
artist="Kanye West",
title="My Beautiful Dark Twisted Fantasy",
date=datetime.date(2010, 11, 22),
media="CD",
path=None, # type: ignore
mb_album_id="2fcfcaaa-6594-4291-b79f-2d354139e108",
)
Expand Down
3 changes: 3 additions & 0 deletions tests/plugins/test_write.py
Expand Up @@ -70,6 +70,7 @@ def test_write_tags(self, tmp_config):
disc = 2
disc_total = 2
genres = {"alternative", "rock"}
media = "CD"
title = "What's Up"
track_num = 3

Expand All @@ -81,6 +82,7 @@ def test_write_tags(self, tmp_config):
track.disc = disc
track.album_obj.disc_total = disc_total
track.genres = genres
track.album_obj.media = media
track.title = title
track.track_num = track_num

Expand All @@ -100,6 +102,7 @@ def test_write_tags(self, tmp_config):

assert new_album.date == date
assert new_album.disc_total == disc_total
assert new_album.media == media


@pytest.mark.usefixtures("_tmp_write_config")
Expand Down

0 comments on commit 256a3a6

Please sign in to comment.