-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_album_in_folder.py
More file actions
65 lines (57 loc) · 1.77 KB
/
create_album_in_folder.py
File metadata and controls
65 lines (57 loc) · 1.77 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# pip install eyeD3
# pip install python-magic-bin
# to download a youtube video as mp3:
# download https://github.com/yt-dlp/yt-dlp
# install or configure ffmpeg in the PATH
# yt-dlp.exe --extract-audio --audio-format mp3 "link to video or playlist"
import eyed3
import typing as t
from os import listdir
from os.path import join, splitext
import argparse
def remove_quotes(string: str):
return "".join(filter(lambda x: x not in ['"', "'"], string))
def main(parsed_args: argparse.Namespace, print_help: t.Callable):
author = parsed_args.author
album = parsed_args.album
base_dir = remove_quotes(parsed_args.dir)
if not all((author, album, base_dir)):
print_help()
return
songs_names = list(filter(lambda x: ".mp3" in x, listdir(base_dir)))
for number, song_name in enumerate(songs_names):
audiofile = eyed3.load(join(base_dir, song_name))
if audiofile is None:
print(f"can't load file {song_name}")
continue
audiofile.tag.artist = author
audiofile.tag.album = album
title, _ = splitext(song_name)
audiofile.tag.title = title
audiofile.tag.track_num = number + 1
audiofile.tag.save()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Create an album from a directory of songs"
)
parser.add_argument(
"--author",
"-A",
type=str,
help="add album author",
)
parser.add_argument(
"--album",
"-a",
type=str,
help="add album name",
)
parser.add_argument(
"--dir",
"-d",
type=str,
default=".",
help="add album directory location",
)
parsed_args = parser.parse_args()
main(parsed_args, parser.print_help)