-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunzipmusic
More file actions
executable file
·216 lines (188 loc) · 8.84 KB
/
Copy pathunzipmusic
File metadata and controls
executable file
·216 lines (188 loc) · 8.84 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env python3
import os
import time
import shutil
import zipfile
import argparse
import contextlib
from enum import Enum
#
# USAGE:
# Place all the zips of the music you've downloaded into a folder,
# and from that folder run unzipmusic --source <source>
#
# tidal.squid.wtf source:
# just puts them into album folders, no artist grouping,
# That's manual for the time being.
# monochrome.tf source:
# Puts them into artist folders, then into album folders.
# EXAMPLE:
# before:
# album - artist.zip
# after:
# artist/album/01 - song.flac
#
class musicSource(Enum):
tidalsquidwtf = "tidal.squid.wtf"
monochrometf = "monochrome.tf"
bandcamp = "bandcamp"
def __std__(self):
return self.value
@contextlib.contextmanager
def pushd(new_dir):
previous_dir = os.getcwd()
os.chdir(new_dir)
try:
yield
finally:
os.chdir(previous_dir)
def findzipfiles():
zipfiles = []
for file in os.listdir(os.getcwd()):
if file.endswith(".zip"):
zipfiles.append(file)
print("Found:")
for file in zipfiles:
print(f" - {file}")
return zipfiles
def unzip_monochrometf():
zipfiles = findzipfiles()
# ZIP STRUCTURE:
# Archive: For Lovers - lamp.zip
# Length Method Size Cmpr Date Time CRC-32 Name
# -------- ------ ------- ---- ---------- ----- -------- ----
# 434227 Stored 434227 0% 03-06-2026 21:19 afe8fda7 For Lovers - lamp/cover.jpg
# 658 Stored 658 0% 03-06-2026 21:19 b031bb2d For Lovers - lamp/For Lovers - lamp.m3u
# 4136419 Stored 4136419 0% 03-06-2026 21:19 d194bd51 For Lovers - lamp/01 - lamp - For Lovers.flac
# 32561307 Stored 32561307 0% 03-06-2026 21:19 713b5fd9 For Lovers - lamp/02 - lamp - HIROGARU-NAMIDA.flac
# 35464283 Stored 35464283 0% 03-06-2026 21:19 165e6f02 For Lovers - lamp/03 - lamp - Last Train At 25 O'clock.flac
# 40318155 Stored 40318155 0% 03-06-2026 21:19 3b5ae90a For Lovers - lamp/04 - lamp - Out On Sunny Sunday.flac
# 29010559 Stored 29010559 0% 03-06-2026 21:19 b7689b29 For Lovers - lamp/05 - lamp - Tomorrow Comes I Will.flac
# 39644010 Stored 39644010 0% 03-06-2026 21:19 1d0c170e For Lovers - lamp/06 - lamp - Rainy Tapestry.flac
# 29049954 Stored 29049954 0% 03-06-2026 21:19 8bd486c7 For Lovers - lamp/07 - lamp - Words Of Love.flac
# 32827459 Stored 32827459 0% 03-06-2026 21:20 5c8587be For Lovers - lamp/08 - lamp - Behind The Moon Shadow.flac
# -------- ------- --- -------
# 243447031 243447031 0% 10 files
for file in zipfiles:
album, artist = file.removesuffix(".zip").rsplit(" - ", 1)
print(f"Artist: {artist} // Album: {album}")
# Make sure the artist folder exists
os.makedirs(artist, exist_ok=True)
with zipfile.ZipFile(file) as zip:
zip.extractall(artist)
with pushd(artist):
# Remove artists name from album folder name
os.rename(f"{album} - {artist}", album)
with pushd(album):
for filename in os.listdir():
# If we're an audio file (-m3u)
if filename.endswith((".flac", ".mp3")):
# Remove the artists name from the filename
os.rename(filename, filename.replace(f" - {artist}", ""))
shutil.move(f"{file}", f"{artist}/")
def unzip_tidalsquidwtf():
print("""
WARNING WARNING WARNING
> tidal.squid.wtf is not being updated anymore and has multiple bugs.
> For a more modern and supported alternative, check out: https://monochrome.tf/
WARNING WARNING WARNING
""")
time.sleep(5)
zipfiles = findzipfiles()
# Do actual unzipping
for file in zipfiles:
with zipfile.ZipFile(file) as zip:
subdir = file.replace(".zip", "")
os.mkdir(subdir)
zip.extractall(subdir)
# Clean up filenames
# .
# ├── Clarion - Clarion
# │ ├── Clarion - Clarion - 01-01 Taxidermy.flac
# │ ├── Clarion - Clarion - 01-02 Human Attire.flac
# │ ├── Clarion - Clarion - 01-03 Hello Juliet.flac
# │ ├── Clarion - Clarion - 01-04 Sunhail48.flac
# │ └── Clarion - Clarion - 01-05 Inertia.flac
with pushd(subdir):
for filename in os.listdir():
os.rename(filename, filename.replace(f"{subdir} - ", ""))
def unzip_bandcamp():
zipfiles = findzipfiles()
# Archive: Iron T Hawk - ToT.zip
# Length Method Size Cmpr Date Time CRC-32 Name
# -------- ------ ------- ---- ---------- ----- -------- ----
# 28332588 Stored 28332588 0% 03-07-2026 02:36 a826bf0a Iron T Hawk - ToT - 01 Unfastened.flac
# 48910108 Stored 48910108 0% 03-07-2026 02:36 7df7ad9d Iron T Hawk - ToT - 02 Cessation.flac
# 62887779 Stored 62887779 0% 03-07-2026 02:36 f236be3a Iron T Hawk - ToT - 03 Conclusions.flac
# 35130061 Stored 35130061 0% 03-07-2026 02:36 e189a58b Iron T Hawk - ToT - 04 Exitus Apparatus.flac
# 31199657 Stored 31199657 0% 03-07-2026 02:36 403aa5f3 Iron T Hawk - ToT - 05 Auras.flac
# 43926320 Stored 43926320 0% 03-07-2026 02:36 d9aafa22 Iron T Hawk - ToT - 06 Execute Me In The Sunlight.flac
# 37552062 Stored 37552062 0% 03-07-2026 02:36 032f7365 Iron T Hawk - ToT - 07 Sunbather.flac
# 42297259 Stored 42297259 0% 03-07-2026 02:36 b39b7238 Iron T Hawk - ToT - 08 Illuminant.flac
# 44152926 Stored 44152926 0% 03-07-2026 02:36 c7d87bbd Iron T Hawk - ToT - 09 Numen.flac
# 22172978 Stored 22172978 0% 03-07-2026 02:36 9d953de0 Iron T Hawk - ToT - 10 Sublimity.flac
# 47507517 Stored 47507517 0% 03-07-2026 02:36 3c0b3c0f Iron T Hawk - ToT - 11 End States.flac
# 8736916 Stored 8736916 0% 03-07-2026 02:36 a8596419 Iron T Hawk - ToT - 12 ToT.flac
# 61577164 Stored 61577164 0% 03-07-2026 02:36 cac20bcf Iron T Hawk - ToT - 13 Idolon.flac
# 39493964 Stored 39493964 0% 03-07-2026 02:36 e83d196b Iron T Hawk - ToT - 14 Indebtedness.flac
# 4941836 Stored 4941836 0% 03-07-2026 02:36 0edf5009 cover.png
# -------- ------- --- -------
# 558819135 558819135 0% 15 files
for file in zipfiles:
artist, album = file.removesuffix(".zip").rsplit(" - ", 1)
print(f"Artist: {artist} // Album: {album}")
# Make sure the artist folder exists
fullpath = f"{artist}/{album}"
os.makedirs(fullpath, exist_ok=True)
with zipfile.ZipFile(file) as zip:
zip.extractall(fullpath)
with pushd(fullpath):
for filename in os.listdir():
# If we're an audio file (-m3u)
if filename.endswith((".flac", ".mp3")):
# Remove the artists name from the filename
os.rename(filename, filename.replace(f"{artist} - {album} - ", ""))
shutil.move(f"{file}", f"{artist}/")
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="unzipmusic")
parser.add_argument(
"--source",
help="The Downloader service you used. (tidal.squid.wtf, monochrome.tf)",
type=musicSource,
required=False
)
parser.add_argument(
"--list-sources",
help="Lists all available source choices (use this instead of --help!)",
action="store_true"
)
try:
args = parser.parse_args()
if not args.source or args.list_sources:
if args.list_sources:
print(f"We have {str(len(musicSource))} sources available.")
print("Here they are:")
else:
print("You haven't specified the source for your music!")
print("I can't do anything!")
print("Invoke me as one of the following:")
for source in musicSource:
if source == musicSource.tidalsquidwtf:
print(f" - unzipmusic --source {source.value} | (DEPRECATED! Check out: https://monochrome.tf/)")
else:
print(f" - unzipmusic --source {source.value}")
exit(1)
match args.source:
case musicSource.tidalsquidwtf:
unzip_tidalsquidwtf()
case musicSource.monochrometf:
unzip_monochrometf()
case musicSource.bandcamp:
unzip_bandcamp()
case _:
print(f"Unknown source: {args.source.value}!")
print("Check out: unzipmusic --list-sources")
exit(1)
exit(0)
except KeyboardInterrupt:
exit(1)