Created
November 11, 2018 19:16
-
-
Save ryanmr/8ee6f4785f7fffb00c720e0d68cb60f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from mutagen.id3 import ID3, CTOC, CHAP, TIT2, CTOCFlags | |
from mutagen import File | |
def main(): | |
print "hi" | |
# target_file = "ns61-ian.mp3" | |
target_file = "pk43.mp3" | |
print_tags(target_file) | |
audio = ID3(target_file) | |
audio.add( | |
CTOC(element_id=u"toc", flags=CTOCFlags.TOP_LEVEL | CTOCFlags.ORDERED, | |
child_element_ids=[u"chp1", "chp2"], | |
sub_frames=[ | |
TIT2(text=[u"I'm a TOC"]), | |
])) | |
audio.add( | |
CHAP(element_id=u"chp1", start_time=0, end_time=42000, | |
sub_frames=[ | |
TIT2(text=[u"I'm the first chapter"]), | |
])) | |
audio.add( | |
CHAP(element_id=u"chp2", start_time=42000, end_time=84000, | |
sub_frames=[ | |
TIT2(text=[u"I'm the second chapter"]), | |
])) | |
audio.save() | |
print_tags(target_file) | |
pass | |
def print_tags(file): | |
id3_tags = File(file) | |
id3_keys = id3_tags.keys() | |
for key in id3_keys: | |
print key, id3_tags[key] | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment