this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 37 lines 1.2 kB view raw
1#!/usr/bin/env python3 2from pathlib import Path 3from mutagen.easyid3 import EasyID3 4 5here = Path(__file__).parent 6library_file = here / "library.tsv" 7library = [ 8 t.replace("/", "").split(" ", 2) 9 for t in library_file.read_text("UTF-8").splitlines() 10] 11 12def tag_track(title: str, artists: set[str], file: Path) -> bool: 13 """ 14 Returns True if the tag was applied, False if it was already applied 15 """ 16 track = EasyID3(str(file)) 17 if set(track.get("artist", [])) == artists and track.get("title", [])[0] == title: 18 # print(f"Checked {track.get('artist', [])!r} against {artists!r}") 19 # print(f"Checked {track.get('title', [''])[0]!r} against {title!r}") 20 # print("⤷ Skipped") 21 return False 22 track["title"] = title 23 track["artist"] = "\0".join(artists) 24 track.save() 25 print(f"Tagged {file.name!r} as {', '.join(artists)}{title}") 26 return True 27 28if __name__ == "__main__": 29 for artists_str, title in library: 30 artists = set(artists_str.split(", ")) 31 for file in library_file.parent.iterdir(): 32 if file.name.startswith(f"{artists_str} {title}") and file.name.endswith(".mp3"): 33 tag_track(title, artists, file) 34 35 36 37