Skip to content

Commit

Permalink
Drop support for beets<1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Sep 20, 2024
1 parent b5cd331 commit 9455f8c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
fail-fast: false
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
beets: ["1.4.9", "1.5.0", "1.6.0"]
beets: ["1.5.0", "1.6.0"]
steps:
- uses: actions/checkout@v4

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [0.20.0] 2024-06-25

### Removed

- Drop support for `beets<1.5`.

### Fixed

- `album`:
Expand Down
24 changes: 13 additions & 11 deletions beetsplug/bandcamp/metaguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from .tracks import Tracks

BEETS_VERSION = Version(beets_version)
EXTENDED_FIELDS_SUPPORT = BEETS_VERSION >= Version("1.5.0")
ALBUMTYPES_LIST_SUPPORT = BEETS_VERSION >= Version("1.6.0")

JSONDict = Dict[str, Any]
Expand Down Expand Up @@ -426,11 +425,18 @@ def get_fields(self, fields: Iterable[str], src: object = None) -> JSONDict:
@property
def _common_album(self) -> JSONDict:
common_data: JSONDict = {"album": self.album_name}
fields = ["label", "catalognum", "albumtype", "country"]
if EXTENDED_FIELDS_SUPPORT:
fields.extend(["genre", "style", "comments", "albumtypes"])
fields = [
"albumtype",
"albumtypes",
"catalognum",
"comments",
"country",
"genre",
"label",
"style",
]
common_data.update(self.get_fields(fields))
if EXTENDED_FIELDS_SUPPORT and not ALBUMTYPES_LIST_SUPPORT:
if not ALBUMTYPES_LIST_SUPPORT:
common_data["albumtypes"] = "; ".join(common_data["albumtypes"])
reldate = self.release_date
if reldate:
Expand All @@ -447,9 +453,6 @@ def _trackinfo(self, track: Track, **kwargs: Any) -> TrackInfo:
data.pop("catalognum", None)
if not data["lyrics"]:
data.pop("lyrics", None)
if not EXTENDED_FIELDS_SUPPORT:
data.pop("catalognum", None)
data.pop("lyrics", None)
for field in set(data.keys()) & self.excluded_fields:
data.pop(field)

Expand All @@ -460,9 +463,8 @@ def singleton(self) -> TrackInfo:
self._singleton = True
self.media = self.media_formats[0]
track = self._trackinfo(self.tracks.first)
if EXTENDED_FIELDS_SUPPORT:
track.update(self._common_album)
track.pop("album", None)
track.update(self._common_album)
track.pop("album", None)
track.track_id = track.data_url
return track

Expand Down
22 changes: 13 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Changelog = "https://github.com/snejus/beetcamp/blob/master/CHANGELOG.md"
python = ">=3.8, <4"

pycountry = ">=20.7.3"
beets = ">=1.4,<=2"
beets = ">=1.5,<=2"
httpx = ">=0.27.0"
ordered-set = ">=4.0"
packaging = ">=24.0"
Expand Down
25 changes: 1 addition & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from rich_tables.utils import make_console, pretty_diff

from beetsplug.bandcamp import DEFAULT_CONFIG
from beetsplug.bandcamp.metaguru import ALBUMTYPES_LIST_SUPPORT, EXTENDED_FIELDS_SUPPORT
from beetsplug.bandcamp.metaguru import ALBUMTYPES_LIST_SUPPORT

if TYPE_CHECKING:
from _pytest.config import Config
Expand Down Expand Up @@ -178,26 +178,6 @@ def bandcamp_html(bandcamp_data_path: Path) -> str:
JSONDictOrList = Union[Dict[str, Any], List[Dict[str, Any]]]


def remove_extra_fields(data: JSONDictOrList) -> JSONDictOrList:
"""Remove extra fields from the JSON data."""
t_fields = set(TrackInfo(None, None).__dict__)
a_fields = set(AlbumInfo(None, None, None, None, None).__dict__)

def keep_fields(data: JSONDict, fields: set[str]) -> JSONDict:
return {k: v for k, v in data.items() if k in fields}

def album(album_data: JSONDict) -> JSONDict:
return {
**keep_fields(album_data, a_fields),
"tracks": [keep_fields(t, t_fields) for t in album_data["tracks"]],
}

if isinstance(data, dict):
return keep_fields(data, t_fields)

return [album(a) for a in data]


@pytest.fixture
def expected_release(bandcamp_data_path: Path) -> list[AlbumInfo] | TrackInfo | None:
"""Return corresponding expected release JSON data.
Expand All @@ -213,9 +193,6 @@ def expected_release(bandcamp_data_path: Path) -> list[AlbumInfo] | TrackInfo |

release_data = json.loads(release_datastr)

if not EXTENDED_FIELDS_SUPPORT:
release_data = remove_extra_fields(release_data)

if isinstance(release_data, dict):
if ALBUMTYPES_LIST_SUPPORT:
release_data["albumtypes"] = release_data["albumtypes"].split("; ")
Expand Down

0 comments on commit 9455f8c

Please sign in to comment.