From 1bc575d92d5869aa42c8e693b6f5dc75b46b7574 Mon Sep 17 00:00:00 2001 From: kernitus <2789734+kernitus@users.noreply.github.com> Date: Sun, 29 Oct 2023 21:33:53 +0000 Subject: [PATCH] Use List & Dict types for Python 3.7 compatibility --- README.md | 4 +++- beetsplug/oldestdate.py | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ba6fd91..9da4ba3 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ necessary. The plugin is intended to be used in singleton mode. Undefined behavi # Configuration - Key | Default Value | Description + | Key | Default Value | Description :----------------------:|:-------------:| :-----: auto | True | Run oldestdate during the import phase ignore_track_id | False | During import, ignore existing track_id. Needed if using plugin on a library already tagged by MusicBrainz @@ -40,6 +40,8 @@ necessary. The plugin is intended to be used in singleton mode. Undefined behavi prompt_missing_work_id: yes force: yes overwrite_date: yes + overwrite_month: yes + overwrite_day: yes filter_recordings: yes approach: 'releases' diff --git a/beetsplug/oldestdate.py b/beetsplug/oldestdate.py index 995d960..8b27f54 100644 --- a/beetsplug/oldestdate.py +++ b/beetsplug/oldestdate.py @@ -1,4 +1,4 @@ -from typing import Optional, Any +from typing import Optional, Any, List, Dict import mediafile import musicbrainzngs from beets import ui, config @@ -16,8 +16,8 @@ ) # Type alias -Recording = dict[str, Any] -Work = dict[str, Any] +Recording = Dict[str, Any] +Work = Dict[str, Any] def _get_work_id_from_recording(recording: Recording) -> Optional[str]: @@ -35,7 +35,7 @@ def _get_work_id_from_recording(recording: Recording) -> Optional[str]: return work_id -def _contains_artist(recording: Recording, artist_ids: list[str]) -> bool: +def _contains_artist(recording: Recording, artist_ids: List[str]) -> bool: """Returns whether this recording contains at least one of the specified artists""" artist_found = False if 'artist-credit' in recording: @@ -48,7 +48,7 @@ def _contains_artist(recording: Recording, artist_ids: list[str]) -> bool: return artist_found -def _get_artist_ids_from_recording(recording: Recording) -> list[str]: +def _get_artist_ids_from_recording(recording: Recording) -> List[str]: """Extract artist ids from a recording""" ids = [] @@ -71,7 +71,7 @@ def _is_cover(recording: Recording) -> bool: return False -def _fetch_work(work_id: str) -> dict[str, Any]: +def _fetch_work(work_id: str) -> Dict[str, Any]: """Fetch work, including recording relations""" work: Work = musicbrainzngs.get_work_by_id(work_id, ['recording-rels'])['work'] return work @@ -79,7 +79,7 @@ def _fetch_work(work_id: str) -> dict[str, Any]: class OldestDatePlugin(BeetsPlugin): # type: ignore _importing: bool = False - _recordings_cache: dict[str, Recording] = dict() + _recordings_cache: Dict[str, Recording] = dict() def __init__(self) -> None: super(OldestDatePlugin, self).__init__() @@ -124,7 +124,7 @@ def __init__(self) -> None: mediafile.StorageStyle(recording_field)) self.add_media_field(recording_field, field) - def commands(self) -> list[ui.Subcommand]: + def commands(self) -> List[ui.Subcommand]: recording_date_command = ui.Subcommand( 'oldestdate', help="Retrieve the date of the oldest known recording or release of a track.", @@ -186,7 +186,7 @@ def _has_work_id(self, recording_id: str) -> bool: work_id = _get_work_id_from_recording(recording) return work_id is not None - def _command_func(self, lib: Library, _: ImportSession, args: list[str]) -> None: + def _command_func(self, lib: Library, _: ImportSession, args: List[str]) -> None: """This queries the local database, not the files.""" for item in lib.items(args): self._process_file(item) @@ -251,7 +251,7 @@ def _get_recording(self, recording_id: str) -> Recording: return self._recordings_cache[ recording_id] if recording_id in self._recordings_cache else self._fetch_recording(recording_id) - def _extract_oldest_recording_date(self, recordings: list[Recording], starting_date: DateWrapper, + def _extract_oldest_recording_date(self, recordings: List[Recording], starting_date: DateWrapper, is_cover: bool, approach: str) -> DateWrapper: """Get oldest date from a recording""" oldest_date = starting_date @@ -286,8 +286,8 @@ def _extract_oldest_recording_date(self, recordings: list[Recording], starting_d return oldest_date - def _extract_oldest_release_date(self, recordings: list[Recording], starting_date: DateWrapper, - is_cover: bool, artist_ids: list[str]) -> DateWrapper: + def _extract_oldest_release_date(self, recordings: List[Recording], starting_date: DateWrapper, + is_cover: bool, artist_ids: List[str]) -> DateWrapper: """Get oldest date from a release""" oldest_date = starting_date release_types = self.config['release_types'].get() @@ -336,8 +336,8 @@ def _extract_oldest_release_date(self, recordings: list[Recording], starting_dat return oldest_date - def _iterate_dates(self, recordings: list[Recording], starting_date: DateWrapper, - is_cover: bool, artist_ids: list[str]) -> Optional[DateWrapper]: + def _iterate_dates(self, recordings: List[Recording], starting_date: DateWrapper, + is_cover: bool, artist_ids: List[str]) -> Optional[DateWrapper]: """Iterates through a list of recordings and returns oldest date""" approach = self.config['approach'].get() oldest_date = starting_date