Skip to content

Commit

Permalink
Use List & Dict types for Python 3.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kernitus committed Oct 29, 2023
1 parent c8db4e2 commit 1bc575d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'

Expand Down
28 changes: 14 additions & 14 deletions beetsplug/oldestdate.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]:
Expand All @@ -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:
Expand All @@ -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 = []

Expand All @@ -71,15 +71,15 @@ 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


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__()
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1bc575d

Please sign in to comment.