-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic_filenames
executable file
·59 lines (46 loc) · 1.59 KB
/
music_filenames
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
#!/usr/bin/python3
import argparse
import eyed3
import os
parser = argparse.ArgumentParser()
parser.add_argument('--execute', action='store_true',
help='Execute everything,_otherwise it\'s a dry-run.')
parser.add_argument('-t', '--tags', action='store_true', help='Set EXIF tags')
parser.add_argument('file', type=str, help='The help msg')
args = parser.parse_args()
def ask(question: str):
answer = input(f'{question}? ')
yesno = input(f'\'{answer}\' correct? [Y/n] ')
if yesno == 'N' or yesno == 'n':
print('Abort ..')
exit()
return answer
try:
file_content = open(args.file).read().strip().split('\n')
except OSError:
print(f'[!] Error : No file named {args.file}')
exit()
dir_content = [(i+1, title) for i, title in enumerate(file_content)]
for index, title in dir_content:
print(index, title)
yesno = input('Correct? [Y/n] ')
if yesno == 'N' or yesno == 'n':
print('Abort ..')
exit()
artist = ask('Artist')
album = ask('Album')
dir_files = [f for f in os.listdir() if not f == args.file]
for index, (current_file, (index, title)) in \
enumerate(zip(sorted(dir_files), dir_content)):
extension = os.path.splitext(current_file)[1]
new_name = f'{index:02} {artist} - {title}{extension}'
if args.execute:
os.rename(current_file, new_name)
audiofile = eyed3.load(new_name)
audiofile.tag.artist = artist
audiofile.tag.album = album
audiofile.tag.title = title
audiofile.tag.track_num = index
audiofile.tag.save()
else:
print(f'{current_file}\t->\t{new_name}')