Skip to content

Instantly share code, notes, and snippets.

@neta1
Created September 29, 2019 20:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neta1/44902ea8b01764116bb0b42ba4750dea to your computer and use it in GitHub Desktop.
Save neta1/44902ea8b01764116bb0b42ba4750dea to your computer and use it in GitHub Desktop.
avsファイルのTrim指定からブックマークをインポートするAvsPmod用マクロ (主にAmatsukazeが一時出力するtrim0.avs向け)
import re
filename = avsp.GetFilename(_('Select a file'), filefilter=
_('.trim.avs files') + ' (*.avs)|*.avs|'+
_('All files') + ' (*.*)|*.*')
if not filename:
return
lines = avsp.GetWindow().GetTextFromFile(filename)[0]
bookmarkDict = {}
# parsing .trim.avs files
if not bookmarkDict:
timeList = re.findall(r'Trim\(\s*(\d+)\s*,\s*(\d+)\s*\)', lines)
if timeList:
for inFrame, outFrame in timeList:
bookmarkDict[int(inFrame)] = 'IN'
bookmarkDict[int(outFrame)] = 'OUT'
if bookmarkDict:
bookmarkList = bookmarkDict.items()
# Don't delete current bookmarks, update its title if supplied
oldBookmarks = avsp.GetBookmarkList()
for bookmark, title in bookmarkDict.items():
if bookmark in oldBookmarks:
if title:
bookmarkList.append((bookmark, title))
else:
bookmarkList.remove((bookmark, title))
avsp.SetBookmark(bookmarkList)
else:
avsp.MsgBox(_('Bookmark file unrecognized!'), _('Error'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment