Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2.  
  3. fps = avsp.GetVideoFramerate(index=None)
  4. filename = avsp.GetFilename(title='Open OGG Chapters',filefilter='Chapter Files (*.txt)|*.txt')
  5. #avsp.MsgBox("fps: %s\nfilename: %s" % (fps,filename), title='debug')
  6.  
  7. def parseOgg(file):
  8.     chapre = re.compile("CHAPTER\d+=(\S+)",re.I)
  9.     timeStrings = []
  10.    
  11.     chapFile = open(file)
  12.     for line in chapFile:
  13.         timeString = chapre.match(line)
  14.         if timeString != None:
  15.             timeStrings.append(timeString.group(1))
  16.     chapFile.close()
  17.    
  18.     return timeStrings
  19.  
  20. def time2ms(ts):
  21.    
  22.     t = ts.split(':')
  23.     h = int(t[0]) * 3600000
  24.     m = h + int(t[1]) * 60000
  25.     ms = round(m + float(t[2]) * 1000)
  26.    
  27.     return ms
  28.  
  29. # def ms2frame(ms,fps):
  30.     # rat = re.compile('(\d+)(?:/|:)(\d+)')
  31.     # s = ms / 1000
  32.     # fps = rat.search(fps).groups() if rat.search(fps) else \
  33.         # [re.search('(\d+)',fps).group(0),'1']
  34.     # frame = round((int(fps[0])/int(fps[1])) * s)
  35.    
  36.     # return frame
  37. def ms2frame(ms,fps):
  38.     s = ms /1000
  39.     frame = int(round(fps * s))
  40.     return frame
  41.  
  42. if filename != '':
  43.     timeStrings=parseOgg(filename)
  44.     #avsp.MsgBox("timeStrings: %s" % ';'.join(timeStrings), title='debug')
  45.     timeCodes = [time2ms(timeString) for timeString in timeStrings]
  46.     #avsp.MsgBox("timeCodes: %s" % ';'.join([str(i) for i in timeCodes]), title='debug')
  47.     frameNumbers = [ms2frame(timeCode,fps) for timeCode in timeCodes]
  48.     for frame in frameNumbers:
  49.         avsp.SetBookmark(frame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement