forked from vdcrim/AvsP-macros
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bookmarks to Chapter.py
37 lines (36 loc) · 1.09 KB
/
Bookmarks to Chapter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import codecs
import os.path
# run in thread
try:
bookmarks = avsp.GetBookmarkList(title=True)
except TypeError:
bookmarks = avsp.GetBookmarkList()
bookmarks.sort()
filename = avsp.GetSaveFilename(
title=_('Save chapter file as...'),
default=os.path.splitext(
avsp.GetScriptFilename(propose='general', only='base'))[0],
filefilter = '|'.join((_('Text files') + ' (*.txt)|*.txt',
_('All files') + ' (*.*)|*.*')))
if not filename:
return
fps = avsp.GetVideoFramerate()
text = []
chapter = 1
for item in bookmarks:
if type(item) is int:
bookmark = item
title = ''
else:
bookmark, title = item
m, s = divmod(bookmark/fps, 60)
h, m = divmod(m, 60)
timecode = 'CHAPTER%02d=%02d:%02d:%06.3f\n' % (chapter, h ,m, s)
if not title:
title = 'Chapter %02d' % chapter
title = 'CHAPTER%02dNAME=%s\n' % (chapter, title)
text += [timecode, title]
chapter +=1
f = codecs.open(filename, 'w', 'utf-8')
f.writelines(text)
f.close()