This repository has been archived by the owner on Nov 4, 2023. It is now read-only.
/
genre-inferrer.py
executable file
·101 lines (85 loc) · 1.9 KB
/
genre-inferrer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
This is a script to infer and suggest release genres based on artist.
"""
import re
import json
import shlex
import subprocess
from dataclasses import dataclass
BLACKLIST = ["xxxxxxx"]
MATCHES = [
"aespa",
"BLACKPINK",
"NewJeans",
"XG",
"LE SSERAFIM",
"Mamamoo",
"Red Velvet",
"TWICE",
"IVE",
"fromis_9",
"Kep1er",
# TODO: (G)-IDLE
"DLE",
"ITZY",
"ONEUS",
"GFRIEND",
# TODO: G-Dragon
"Dragon",
"Jennie",
"LISA",
# TODO: ROSÉ
"ROS",
"ROSE",
"Jisoo",
"BTS",
"IZ*ONE",
"Huh Yunjin",
"Oh My Girl",
"GFriend",
"EXO",
]
@dataclass
class Album:
albumartist: str
album: str
genre: str
def update_genres() -> list[str]:
kpop_albums: list[Album] = []
for m in MATCHES:
args = [
"beet",
"export",
"--album",
"--include-keys",
"albumartist,album,genre",
"albumartist:" + m,
]
result = subprocess.run(args, capture_output=True)
stdout = result.stdout.decode()
if not stdout.strip():
continue
out = json.loads(stdout)
for album in out:
kpop_albums.append(
Album(
albumartist=album["albumartist"],
album=album["album"],
genre=album["genre"],
)
)
commands: list[str] = []
for album in kpop_albums:
if album.genre == "K-Pop":
continue
albumartist = shlex.quote(f"^{re.escape(album.albumartist)}$")
album = shlex.quote(f"^{re.escape(album.album)}$")
commands.append(
"beet modify --yes --album "
f"albumartist::{albumartist} "
f"album::{album} "
f"genre='K-Pop'"
)
return commands
print("\n".join(update_genres()))