Skip to content
Browse files

Add ability to use mp4chap

  • Loading branch information...
1 parent 9fb9920 commit 6285d4d8ca7b752e7a88b92c07622bd138d061a6 @n1m3 n1m3 committed Apr 30, 2011
Showing with 24 additions and 0 deletions.
  1. +24 −0 prittag.py
View
24 prittag.py
@@ -25,6 +25,7 @@
import string
import re
import traceback
+import subprocess
from xml.etree import ElementTree
from mutagen.mp3 import MP3
@@ -214,13 +215,36 @@ def write_tags_to_mp4(path, tags):
if 'cover' in tags:
audio['covr'] = [get_mp4_coverart(tags['cover'])]
audio.save()
+ if 'chapters' in tags:
+ write_mp4_chapters(path, tags['chapters'])
def get_mp4_coverart(path):
with open(path, 'rb') as f:
data = f.read()
cover = MP4Cover(data)
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__":
print '''prittag Copyright (C) 2011 Nils Mehrtens
This program comes with ABSOLUTELY NO WARRANTY.

0 comments on commit 6285d4d

Please sign in to comment.
Something went wrong with that request. Please try again.