Skip to content

Commit

Permalink
feat: new album field - barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpavlock committed Oct 11, 2022
1 parent d0507fe commit 72d07d3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions alembic/versions/eb8c7e20a080_new_field_barcode.py
@@ -0,0 +1,26 @@
"""new field barcode.
Revision ID: eb8c7e20a080
Revises: db3a470892c6
Create Date: 2022-10-11 14:51:44.788096
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "eb8c7e20a080"
down_revision = "db3a470892c6"
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("barcode", sa.String(), nullable=True))


def downgrade():
with op.batch_alter_table("album", schema=None) as batch_op:
batch_op.drop_column("barcode")
1 change: 1 addition & 0 deletions docs/fields.rst
Expand Up @@ -34,6 +34,7 @@ Album Fields
:width: 100%

"artist", "Album artist", ""
"barcode", "UPC barcode", ""
"country", "Country the album was released in (two character identifier)", ""
"date", "Album release date", "2"
"disc_total", "Number of discs in the album", ""
Expand Down
3 changes: 3 additions & 0 deletions moe/library/album.py
Expand Up @@ -85,6 +85,7 @@ class Album(LibItem, SABase):
Attributes:
artist (str): AKA albumartist.
barcode (str): UPC barcode.
country (str): Country the album was released in (two character identifier).
date (datetime.date): Album release date.
disc_total (int): Number of discs in the album.
Expand All @@ -103,6 +104,7 @@ class Album(LibItem, SABase):

_id: int = cast(int, Column(Integer, primary_key=True))
artist: str = cast(str, Column(String, nullable=False))
barcode: str = cast(str, Column(String, nullable=True))
country: str = cast(str, Column(String, nullable=True))
date: datetime.date = cast(datetime.date, Column(Date, nullable=False))
disc_total: int = cast(int, Column(Integer, nullable=False, default=1))
Expand Down Expand Up @@ -215,6 +217,7 @@ def fields(self) -> set[str]:
"""Returns any editable album fields."""
return {
"artist",
"barcode",
"country",
"date",
"disc_total",
Expand Down
1 change: 1 addition & 0 deletions moe/library/track.py
Expand Up @@ -111,6 +111,7 @@ def read_custom_tags(
audio_file = mediafile.MediaFile(track_path)

album_fields["artist"] = audio_file.albumartist or audio_file.artist
album_fields["barcode"] = audio_file.barcode
album_fields["country"] = audio_file.country
album_fields["date"] = audio_file.date
album_fields["disc_total"] = audio_file.disctotal
Expand Down
1 change: 1 addition & 0 deletions moe/plugins/musicbrainz/mb_core.py
Expand Up @@ -397,6 +397,7 @@ def _create_album(release: dict) -> Album:

album = Album(
artist=_flatten_artist_credit(release["artist-credit"]),
barcode=release.get("barcode"),
country=release.get("country"),
date=_parse_date(release["date"]),
disc_total=int(release["medium-count"]),
Expand Down
1 change: 1 addition & 0 deletions moe/plugins/write.py
Expand Up @@ -77,6 +77,7 @@ def write_custom_tags(track: Track):
audio_file.albumartist = track.albumartist
audio_file.artist = track.artist
audio_file.artists = track.artists
audio_file.barcode = track.album_obj.barcode
audio_file.country = track.album_obj.country
audio_file.date = track.album_obj.date
audio_file.disc = track.disc
Expand Down
1 change: 1 addition & 0 deletions moe/util/core/match.py
Expand Up @@ -17,6 +17,7 @@

MATCH_ALBUM_FIELD_WEIGHTS = {
"artist": 0.8,
"barcode": 1.0,
"country": 0.3,
"date": 0.2,
"disc_total": 0.8,
Expand Down
2 changes: 2 additions & 0 deletions tests/library/test_track.py
Expand Up @@ -126,6 +126,7 @@ def test_read_tags(self, tmp_config):
track.title = "Full"
track.track_num = 1

album.barcode = "1234"
album.country = "US"
album.date = datetime.date(2020, 1, 12)
album.disc_total = 2
Expand All @@ -146,6 +147,7 @@ def test_read_tags(self, tmp_config):
assert new_track.title == track.title
assert new_track.track_num == track.track_num

assert new_album.barcode == album.barcode
assert new_album.country == album.country
assert new_album.disc_total == album.disc_total
assert new_album.date == album.date
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/musicbrainz/resources/full_release.py
Expand Up @@ -1681,6 +1681,7 @@ def album() -> Album:
return Album(
artist="Kanye West",
title="My Beautiful Dark Twisted Fantasy",
barcode="602527474465",
country="US",
date=datetime.date(2010, 11, 22),
label="Roc‐A‐Fella Records",
Expand Down
3 changes: 3 additions & 0 deletions tests/plugins/test_write.py
Expand Up @@ -66,6 +66,7 @@ def test_write_tags(self, tmp_config):
albumartist = "4 Non Blondes"
artist = "4 Non Blondes"
artists = {"4 Non Blondes", "Me"}
barcode = "1234"
country = "US"
date = datetime.date(1996, 10, 13)
disc = 2
Expand All @@ -81,6 +82,7 @@ def test_write_tags(self, tmp_config):
track.albumartist = albumartist
track.artist = artist
track.artists = artists
track.album_obj.barcode = barcode
track.album_obj.country = country
track.album_obj.date = date
track.album_obj.original_date = original_date
Expand All @@ -106,6 +108,7 @@ def test_write_tags(self, tmp_config):
assert new_track.title == title
assert new_track.track_num == track_num

assert new_album.barcode == barcode
assert new_album.country == country
assert new_album.date == date
assert new_album.disc_total == disc_total
Expand Down

0 comments on commit 72d07d3

Please sign in to comment.