-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathyaml2folders.py
More file actions
44 lines (37 loc) · 1.32 KB
/
yaml2folders.py
File metadata and controls
44 lines (37 loc) · 1.32 KB
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
from tinytag import TinyTag
import os
import sys
import yaml
from shutil import copy2
os.chdir(os.path.dirname(__file__))
arg = ""
if len(sys.argv) > 1:
arg = sys.argv[1]
musiclist = None
if arg != "":
with open(arg, 'r', encoding='utf-8') as music:
musiclist = yaml.load(music)
songs = list(filter(lambda x: os.path.isfile(x) and x.lower().endswith(('.mp3', '.ogg')), os.listdir(os.getcwd())))
Log = open("music_log.txt", "w", encoding='utf-8')
if musiclist:
musics = []
for item in musiclist:
if 'category' not in item:
continue
cat = item['category'].strip('=')
Dir = os.path.join(os.getcwd(), cat)
if not os.path.exists(Dir):
os.makedirs(Dir)
for song in item['songs']:
try:
song['name'] = song['name'][song['name'].find('/')+1:]
F = os.path.join(os.getcwd(), song['name'])
copy2(F, '{}/'.format(Dir))
print('{}/{}'.format(cat, song['name']))
Log.write('{}/{}\n'.format(cat, song['name']))
except:
Log.write('Song {} missing!\n'.format(song['name']))
print("Song {} missing!".format(song['name']))
input("Done!")
else:
input("Usage: drag and drop music.yaml on this program to copy all songs to categories.")