-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_tracks.py
38 lines (32 loc) · 926 Bytes
/
tag_tracks.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
import spotify
import re
from os import listdir
import argparse
# parses arguments
parser = argparse.ArgumentParser()
parser.add_argument("path", help="path to playlist directory")
parser.add_argument(
"pattern",
help='put key names in "<>" e.g. "<artist> - <title>.m4a". The "title" key is required.',
)
args = parser.parse_args()
# gets extension of file
ext = lambda path: path.split(".")[-1]
path = args.path
pattern = args.pattern
parent_dir = "/".join(path.split("/")[:-1])
files = listdir(path)
for file in listdir(path):
# checks if the file is just artwork
if ext(file) == "jpg":
continue
# finds info using pattern and filename
query = file.replace("." + ext(file), "")
query = re.sub("[\d-]+", "", query)
try:
track = spotify.search_track(query)
except:
print(query)
continue
track["filepath"] = os.path.join(path, file)
track.tag()