-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorter.py
34 lines (30 loc) · 1004 Bytes
/
sorter.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
import audio_metadata, os
files=[]
folders=[]
path="INSERT FOLDER HERE"
# ['path', 'album', 'title']
for filename in os.listdir(path):
f = os.path.join(path,filename)
if os.path.isfile(f):
metadata = audio_metadata.load(f) # Loads the metadata from the song
album = metadata.tags['album'] # Isolates album name
files.append((f,album[0],filename))
for directory in os.listdir(path):
f = os.path.join(path,directory)
if os.path.isdir(f):
folders.append(f)
for file in files:
if file[1] not in folders:
toCreate = os.path.join(path, file[1])
destinationFile = os.path.join(toCreate, file[2])
try:
os.mkdir(toCreate)
except:
pass
folders.append(toCreate)
os.rename(file[0], destinationFile)
print(destinationFile)
else:
destinationFile = os.path.join(path, file[1], file[2])
os.rename(file[0], destinationFile)
print(destinationFile)