Guest User

Untitled

a guest
Jul 17th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. diff --git a/vfr.py b/vfr.py
  2. index cc4867e..f2246c4 100755
  3. --- a/vfr.py
  4. +++ b/vfr.py
  5. @@ -40,6 +40,7 @@ def main():
  6. p.add_option('--ofps', action="store", help='Output frames per second', dest="ofps")
  7. p.add_option('--timecodes', '-t', action="store", help='Timecodes file from the vfr video', dest="timecodes")
  8. p.add_option('--chapters', '-c', action="store", help='Chapters file [.%s/.txt]' % "/.".join(exts.keys()), dest="chapters")
  9. + p.add_option('--chnames', '-n', action="store", help='Path to template file for chapter names', dest="chnames")
  10. p.add_option('--qpfile', '-q', action="store", help='QPFile for x264 (frame-accurate only if used with final framecount)', dest="qpfile")
  11. p.add_option('--verbose', '-v', action="store_true", help='Verbose', dest="verbose")
  12. p.add_option('--merge', '-m', action="store_true", help='Merge cut files', dest="merge")
  13. @@ -260,16 +261,27 @@ def main():
  14.  
  15. </Tag>""".format(EditionUID,"Default","eng")
  16.  
  17. + chapNames = []
  18. +
  19. + if o.chnames:
  20. + with open(o.chnames, "r") as f:
  21. + [chapNames.append(line.strip()) for line in f.readlines()]
  22. +
  23. + if not o.chnames or len(chapNames) != len(Trims2ts):
  24. + # The if statement is for clarity; it doesn't actually do anything useful
  25. + for i in range(len(chapNames),len(Trims2ts)):
  26. + chapNames.append("Chapter {:02d}".format(i+1))
  27. +
  28. if not o.test:
  29. with open(o.chapters, "w") as output:
  30. if chapType == 'MKV':
  31. output.write(matroskaXmlHeader)
  32. output.write(matroskaXmlEditionHeader)
  33. - [output.write(generateChap(formatTime(Trims2ts[i][0]), formatTime(Trims2ts[i][1]),i+1,chapType)) for i in range(len(Trims2ts))]
  34. + [output.write(generateChap(formatTime(Trims2ts[i][0]), formatTime(Trims2ts[i][1]),i+1,chapNames[i],chapType)) for i in range(len(Trims2ts))]
  35. output.write(matroskaXmlEditionFooter)
  36. output.write(matroskaXmlFooter)
  37. else:
  38. - [output.write(generateChap(formatTime(Trims2ts[i][0],1), formatTime(Trims2ts[i][1],1),i+1,chapType)) for i in range(len(Trims2ts))]
  39. + [output.write(generateChap(formatTime(Trims2ts[i][0],1), formatTime(Trims2ts[i][1],1),i+1,chapNames[i],chapType)) for i in range(len(Trims2ts))]
  40. if o.verbose:
  41. print("Writing {} Chapters to {}".format(chapType,o.chapters))
  42.  
  43. @@ -365,7 +377,7 @@ def unTs(fn,old,new):
  44. new=new if math.floor(new) == math.floor(abs(new-0.2)) else new-0.2
  45. return int(math.floor(new))
  46.  
  47. -def generateChap(start, end, chapter, type):
  48. +def generateChap(start, end, chapter, chaptername, type):
  49. """Generates chapters"""
  50. # Matroska
  51. if type == 'MKV':
  52. @@ -374,17 +386,17 @@ def generateChap(start, end, chapter, type):
  53. <ChapterTimeStart>{}</ChapterTimeStart>
  54. <ChapterTimeEnd>{}</ChapterTimeEnd>
  55. <ChapterDisplay>
  56. - <ChapterString>Chapter {:02d}</ChapterString>
  57. + <ChapterString>{}</ChapterString>
  58. <ChapterLanguage>{}</ChapterLanguage>
  59. </ChapterDisplay>
  60. </ChapterAtom>
  61. -"""[1:].format(start,end,chapter,"eng")
  62. +"""[1:].format(start,end,chaptername,"eng")
  63. # OGM
  64. elif type == 'OGM':
  65. - return 'CHAPTER{0:02d}={1}\nCHAPTER{0:02d}NAME=Chapter {0:02d}\n'.format(chapter,start)
  66. + return 'CHAPTER{0:02d}={1}\nCHAPTER{0:02d}NAME={2}\n'.format(chapter,start,chaptername)
  67. # X264
  68. elif type == 'X264':
  69. - return '{0} Chapter {1:02d}\n'.format(start,chapter)
  70. + return '{0} {1}\n'.format(start,chaptername)
  71.  
  72. if __name__ == '__main__':
  73. main()
Add Comment
Please, Sign In to add comment