-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
130 lines (120 loc) · 3.2 KB
/
main.py
File metadata and controls
130 lines (120 loc) · 3.2 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# auto_tag/main.py
import argparse
import asyncio
import os
from auto_tag.audio_recognize import find_and_recognize_audio_files
from auto_tag.gui import launch_gui
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
if v.lower() in ("no", "false", "f", "n", "0"):
return False
raise argparse.ArgumentTypeError("Boolean value expected.")
async def main():
parser = argparse.ArgumentParser(
description="Process audio files with Shazam recognition and optional renaming and tagging."
)
parser.add_argument(
"-di",
"--directory",
help="Directory to process (default: current folder)",
default=os.getcwd(),
)
parser.add_argument(
"-m",
"--modify",
type=str2bool,
nargs="?",
const=True,
default=True,
help="Apply modifications to tags and filenames (default: true)",
)
parser.add_argument(
"-de",
"--delay",
type=int,
default=10,
help="Delay in seconds before retrying Shazam (default: 10)",
)
parser.add_argument(
"-n",
"--nbrRetry",
type=int,
default=3,
help="Number of retries if Shazam fails (default: 3)",
)
parser.add_argument(
"-tr",
"--trace",
type=str2bool,
nargs="?",
const=True,
default=False,
help="Enable tracing/debug output (default: false)",
)
parser.add_argument(
"-g",
"--gui",
type=str2bool,
nargs="?",
const=True,
default=True,
help="Launch the GUI instead of CLI (default: true)",
)
parser.add_argument(
"-e",
"--extensions",
type=str,
default="mp3,ogg",
help="Comma-separated list of extensions to process (default: mp3,ogg)",
)
parser.add_argument(
"-o",
"--output",
type=str,
default=None,
help="Base output directory for moved files (default: same folder)",
)
parser.add_argument(
"-p",
"--plex",
action="store_true",
help="Organize output into Plex structure Artist/Album/Title.ext",
)
parser.add_argument(
"-c",
"--copy",
type=str,
default=None,
help="Copy files to this directory instead of moving them",
)
parser.add_argument(
"-to",
"--tag_only",
type=str2bool,
nargs="?",
const=True,
default=False,
help="Only update tags/cover art (no rename/move)",
)
args = parser.parse_args()
if args.gui:
launch_gui()
else:
exts = [x.strip().lower() for x in args.extensions.split(",")]
await find_and_recognize_audio_files(
folder_path=args.directory,
modify=args.modify,
delay=args.delay,
nbr_retry=args.nbrRetry,
trace=args.trace,
extensions=exts,
output_dir=args.output,
plex_structure=args.plex,
copy_to=args.copy,
tag_only=args.tag_only,
)
if __name__ == "__main__":
asyncio.run(main())