-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.py
executable file
·56 lines (46 loc) · 1.61 KB
/
delete.py
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
#!/usr/bin/python3
import os
import argparse
import pathlib
def fix_wd():
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
if __name__ == "__main__":
print("music-lib Deleter version 1.0.1")
fix_wd()
parser = argparse.ArgumentParser(description="Delete music from music-lib")
parser.add_argument("--dry", action="store_true", help="Don't make any actual changes")
args = parser.parse_args()
dry_run = args.dry
if dry_run:
print("Dry run mode enabled. No changes will be made.")
ids = []
with open("./music/archive.txt", "r", encoding="utf8") as archive:
archive_data = archive.read()
ids = archive_data.split("\n")
ids = [id.removeprefix("youtube ") for id in ids] # Remove the "youtube " (note the space)
# prefix from IDs
ids = list(filter(None, ids)) # Remove any empty strings from IDs
music_files = []
music_dir = pathlib.Path("./music")
for song_id in ids:
pattern = f"*{song_id}*"
# TODO wtf
file = ""
for file in music_dir.glob(pattern):
file = f"./music/{file.name}"
break
if not file:
print(f"(No music file found for id {song_id})")
continue
music_files.append(file)
print(f"Found music files: {music_files}")
print("Deleting files")
for file in music_files:
print(f"Deleting: {file}")
if not dry_run:
os.remove(file)
print("Deleting archive")
if not dry_run:
os.remove("./music/archive.txt")