Skip to content

Commit 6431668

Browse files
committed
fix: missing support for OGG cover and atom corruption
1 parent 4b28236 commit 6431668

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
demucs @ git+https://github.com/facebookresearch/demucs.git@583db9df0213ba5f5b3491eca5c993e7629f1949#egg=demucs
2-
tagpy @ git+https://github.com/acolombier/tagpy.git@c5de51fe9636b312bfe95dee8b051ab640976d43#egg=tagpy
2+
tagpy @ git+https://github.com/acolombier/tagpy.git@7be8801d1079cfb3c3d84839959e954781722eb0#egg=tagpy
33
setuptools>=61.0
44
ffmpeg-python==0.2.0
55
torch>=2.1.2

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
URL = "https://github.com/acolombier/stemgen"
1414
EMAIL = "stemgen@acolombier.dev"
1515
AUTHOR = "Antoine Colombier"
16-
REQUIRES_PYTHON = ">=3.11.0"
16+
REQUIRES_PYTHON = ">=3.10.0"
1717

1818
# Get version without explicitly loading the module.
1919
for line in open("stemgen/__init__.py"):

stemgen/__main__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def main(
197197
overlap=overlap,
198198
jobs=jobs,
199199
)
200+
has_failure = False
200201
for file in files:
201202
file = str(Path(file).resolve())
202203
filename = ".".join(os.path.basename(file).split(".")[:-1])
@@ -209,7 +210,8 @@ def main(
209210
fg="red",
210211
err=True,
211212
)
212-
exit(1)
213+
has_failure |= True
214+
continue
213215
click.echo(f"Processing {filename}...")
214216

215217
src = Track(file)
@@ -230,6 +232,8 @@ def main(
230232
stem_4_color=vocal_stem_color,
231233
)
232234
click.secho(f"Stem generated in {os.path.basename(dst)}", bold=True, fg="green")
235+
if has_failure:
236+
exit(1)
233237

234238

235239
if __name__ == "__main__":

stemgen/nistemfile.py

+31-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import tagpy
44
import tagpy.id3v2
5+
import tagpy.ogg.flac
56
from torchaudio.io import StreamWriter, CodecConfig
67
import stembox
78
import torch
@@ -27,29 +28,34 @@ def _extract_cover(f):
2728
covers = []
2829
if hasattr(tag, "covers"):
2930
covers = tag.covers
31+
elif hasattr(tag, "pictureList"):
32+
covers = tag.pictureList()
3033
elif hasattr(f, "ID3v2Tag"):
3134
covers = [
3235
a
3336
for a in f.ID3v2Tag().frameList()
3437
if isinstance(a, tagpy.id3v2.AttachedPictureFrame)
3538
]
36-
3739
if covers:
3840
cover = covers[0]
3941
fmt = tagpy.mp4.CoverArtFormats.Unknown
4042
if isinstance(cover, tagpy.mp4.CoverArt):
4143
return cover
44+
data = None
45+
if isinstance(cover, tagpy.ogg.flac.Picture):
46+
data = cover.data()
4247
else:
43-
mime = cover.mimeType().lower().strip()
44-
if "image/jpeg":
45-
fmt = tagpy.mp4.CoverArtFormats.JPEG
46-
elif "image/png":
47-
fmt = tagpy.mp4.CoverArtFormats.PNG
48-
elif "image/bmp":
49-
fmt = tagpy.mp4.CoverArtFormats.BMP
50-
elif "image/gif":
51-
fmt = tagpy.mp4.CoverArtFormats.GIF
52-
return tagpy.mp4.CoverArt(fmt, cover.picture())
48+
data = cover.picture()
49+
mime = cover.mimeType().lower().strip()
50+
if "image/jpeg":
51+
fmt = tagpy.mp4.CoverArtFormats.JPEG
52+
elif "image/png":
53+
fmt = tagpy.mp4.CoverArtFormats.PNG
54+
elif "image/bmp":
55+
fmt = tagpy.mp4.CoverArtFormats.BMP
56+
elif "image/gif":
57+
fmt = tagpy.mp4.CoverArtFormats.GIF
58+
return tagpy.mp4.CoverArt(fmt, data)
5359

5460

5561
class NIStemFile:
@@ -118,6 +124,20 @@ def write(self, original, stems):
118124
progress.finish()
119125

120126
def update_metadata(self, src, **stem_metadata):
127+
# FIXME generating metadata atom after the file tags
128+
with stembox.Stem(self.__path) as f:
129+
f.stems = [
130+
dict(
131+
color=stem_metadata.get(
132+
f"stem_{i+1}_color",
133+
)
134+
or self.STEM_DEFAULT_COLOR[i],
135+
name=stem_metadata.get(f"stem_{i+1}_label")
136+
or self.STEM_DEFAULT_LABEL[i].title(),
137+
)
138+
for i in range(4)
139+
]
140+
121141
src = tagpy.FileRef(src)
122142
dst = tagpy.FileRef(self.__path)
123143

@@ -132,16 +152,3 @@ def update_metadata(self, src, **stem_metadata):
132152
c.append(cover)
133153
dst_tag.covers = c
134154
dst.save()
135-
136-
with stembox.Stem(self.__path) as f:
137-
f.stems = [
138-
dict(
139-
color=stem_metadata.get(
140-
f"stem_{i+1}_color",
141-
)
142-
or self.STEM_DEFAULT_COLOR[i],
143-
name=stem_metadata.get(f"stem_{i+1}_label")
144-
or self.STEM_DEFAULT_LABEL[i].title(),
145-
)
146-
for i in range(4)
147-
]

0 commit comments

Comments
 (0)