diff --git a/README.md b/README.md index 4197c8a..1753e93 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,11 @@ - Fast `Redis` cache - A user-friendly interface for selecting the desired artist and then the desired album - Working on Linux/MacOS + - Suported formats: `.flac`, `.dsf` ## QuickStart + ### Installation + ```bash git clone https://github.com/Olezhich/AudioTagLoader.git @@ -25,4 +28,23 @@ echo DISCOGS_TOKEN="YOUR_DISCOGS_TOKEN" > .secrets # run docker redis container docker-compose -f cache/docker-compose.yml up -d + ``` + +You also may add `autag` script into `$PATH`. + + ### Uisng + + ```bash +# First step: go to taget directory where your tracks exists + +cd YOUR_DIR + +# Second step: load tags into tags.txt file + +# Load tags by artist name: +autag fba "The Artist Name" . + +# Final step: set tags into tracks + +autag set ``` \ No newline at end of file diff --git a/audiotagloader/app.py b/audiotagloader/app.py index edb83cc..fdf2f79 100644 --- a/audiotagloader/app.py +++ b/audiotagloader/app.py @@ -37,14 +37,14 @@ def _get_albums_by_artist(self, artist: Artist) -> list[Album]: pattern = re.compile(rf"^({artist.aliases})\*?\s*\S+\s*(.+)$") - target_albums = [] + target_albums = set() for i in range(releases.pages): for master in releases.page(i): title_match = pattern.match(master.title) if title_match: try: - target_albums.append( + target_albums.add( Album( id=master.id, title=title_match.group(2), @@ -58,7 +58,7 @@ def _get_albums_by_artist(self, artist: Artist) -> list[Album]: except Exception: pass - return target_albums + return sorted([i for i in target_albums], key=lambda x: x.year) @cache def _get_cover_image(self, album_id: int) -> Image: @@ -108,7 +108,7 @@ def get_track_tags_by_artist( albums = self._get_albums_by_artist(current_artist) for i in range(len(albums)): - print(f"[{i:02d}] {albums[i].year} - {albums[i].title}") + print(f"[{i:02d}] {albums[i].year} - {albums[i].title} {albums[i].id}") current_album = albums[ max(0, min(len(albums) - 1, int(input("select album: ")))) diff --git a/audiotagloader/models.py b/audiotagloader/models.py index 89cb04e..91e611b 100644 --- a/audiotagloader/models.py +++ b/audiotagloader/models.py @@ -26,7 +26,7 @@ def aliases(self) -> str: return "|".join([re.escape(alias) for alias in lst]) -class Album(BaseModel): +class Album(BaseModel, frozen=True): id: int title: str = Field(default="") year: int = Field(default=0) @@ -43,6 +43,14 @@ def normlize_list(cls, value: list[str] | None) -> list[str]: return res return value + def __hash__(self): + return hash(self.id) + + def __eq__(self, other): + if not isinstance(other, Album): + return False + return self.id == other.id + class Image(BaseModel): url: str = Field(default="")