-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_media_tagedit
executable file
·98 lines (69 loc) · 2.41 KB
/
s_media_tagedit
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
#!/usr/bin/env python3
# Bin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bin. If not, see <https://www.gnu.org/licenses/>.
from pathlib import Path
import argparse
import taglib
class SongMeta:
"""Edit tune attributes."""
def __init__(self, song: str):
self.song = taglib.File(song)
def album(self, name: str) -> None:
self.song.tags["ALBUM"] = name
def artist(self, name: str) -> None:
self.song.tags["ARTIST"] = name
def title(self, name: str) -> None:
self.song.tags["TITLE"] = name
def date(self, name: str) -> None:
self.song.tags["DATE"] = name
def save(self):
self.song.save()
# ACTIONS -----------------------------------------------------
def single(file: str) -> None:
"""Edit single file metadata."""
song_meta = SongMeta(str(file))
if args.song:
song_meta.title(args.song)
if args.artist:
song_meta.artist(args.artist)
if args.album:
song_meta.album(args.album)
if args.date:
song_meta.date(args.date)
song_meta.save()
def multiple(dir: str) -> None:
"""Edit all files metadata in directory."""
for item in dir.iterdir():
if Path(item).is_file:
single(item)
# CLI -----------------------------------------------------
parser = argparse.ArgumentParser(
prog="tagedit",
description="Edit tag of file or directory files.",
epilog="Praise the sun!",
)
parser.add_argument("-t", "--target", help="file/directory to edit")
parser.add_argument("-a", "--artist", help="artist name")
parser.add_argument("-s", "--song", help="song title")
parser.add_argument("-A", "--album", help="album title")
parser.add_argument("-d", "--date", help="album/song date of release")
args = parser.parse_args()
if not args.target:
parser.print_help()
exit(1)
target = Path(args.target)
if target.is_dir():
multiple(target)
exit()
single(target)
exit()