Skip to content

Commit

Permalink
Add ability to use mp4chap
Browse files Browse the repository at this point in the history
  • Loading branch information
n1m3 committed Apr 30, 2011
1 parent 9fb9920 commit 6285d4d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions prittag.py
Expand Up @@ -25,6 +25,7 @@
import string import string
import re import re
import traceback import traceback
import subprocess
from xml.etree import ElementTree from xml.etree import ElementTree


from mutagen.mp3 import MP3 from mutagen.mp3 import MP3
Expand Down Expand Up @@ -214,13 +215,36 @@ def write_tags_to_mp4(path, tags):
if 'cover' in tags: if 'cover' in tags:
audio['covr'] = [get_mp4_coverart(tags['cover'])] audio['covr'] = [get_mp4_coverart(tags['cover'])]
audio.save() audio.save()
if 'chapters' in tags:
write_mp4_chapters(path, tags['chapters'])


def get_mp4_coverart(path): def get_mp4_coverart(path):
with open(path, 'rb') as f: with open(path, 'rb') as f:
data = f.read() data = f.read()
cover = MP4Cover(data) cover = MP4Cover(data)
return cover return cover


def write_mp4_chapters(path, chapters):
chapter_path = os.path.splitext(path)[0] + '.chapters.txt'
data = ""
for chapter in chapters:
line = u"%s %s\n" % (chapter['time'], chapter['title'])
line = line.encode('utf-8')
data = ''.join((data, line))
if data:
try:
with open(chapter_path, 'w') as f:
f.write(data)
except:
print "couldn't write to %s" % chapter_path
else:
call_mp4_chaps(path)
os.remove(chapter_path)

def call_mp4_chaps(path):
popen = subprocess.Popen('mp4chaps -i %s' % path, shell = True)
popen.wait()

if __name__ == "__main__": if __name__ == "__main__":
print '''prittag Copyright (C) 2011 Nils Mehrtens print '''prittag Copyright (C) 2011 Nils Mehrtens
This program comes with ABSOLUTELY NO WARRANTY. This program comes with ABSOLUTELY NO WARRANTY.
Expand Down

0 comments on commit 6285d4d

Please sign in to comment.