Skip to content

Commit 1c40318

Browse files
committed
Try to match tag ordering, version, etc. of known-good files
- Remove extraneous tags - Set TLEN, TENC - Order of sub-frames - The actual important thing: use ID3v2 2.3, not 2.4 (mutagen default)
1 parent 51825f1 commit 1c40318

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

chapterize.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import shutil
44
from glob import glob
55
import mutagen
6-
from mutagen.id3 import ID3, CHAP, CTOC, APIC, TIT2, PictureType, CTOCFlags
6+
from mutagen.id3 import (ID3, CHAP, CTOC, APIC, TIT2, TLEN, TENC,
7+
PictureType, CTOCFlags)
78

89

910
def _get_frames(f_id: str):
@@ -28,7 +29,7 @@ def _get_chapters(frames, length_ms):
2829
element_id=f'chp{i}',
2930
start_time=timestamp,
3031
end_time=end_time,
31-
sub_frames=[apic, tit2]
32+
sub_frames=[tit2, apic]
3233
)
3334

3435

@@ -38,7 +39,7 @@ def chapterize(mp3_path, frames_path, outfile):
3839
infile = mutagen.File(mp3_path)
3940
length_ms = int(infile.info.length * 1000)
4041

41-
tag = ID3(mp3_path)
42+
tag = ID3(mp3_path, v2_version=3)
4243

4344
frames = sorted(_get_frames(frames_path))
4445

@@ -58,7 +59,13 @@ def chapterize(mp3_path, frames_path, outfile):
5859
for ch in chapters:
5960
tag.add(ch)
6061

61-
tag.save(outfile)
62+
tag.add(TLEN(text=str(length_ms)))
63+
tag.add(TENC(text='chapterize.py'))
64+
65+
tag.delall('TXXX')
66+
tag.delall('TSSE')
67+
68+
tag.save(outfile, v2_version=3)
6269

6370

6471
def main():

0 commit comments

Comments
 (0)