Advertisement
Guest User

Untitled

a guest
Mar 4th, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from MythTV import Job, Recorded, System, MythDB, findfile, MythError, MythLog
  4.  
  5. from optparse import OptionParser
  6. import sys
  7. import os
  8.  
  9. ################################
  10. #### adjust these as needed ####
  11. transcoder = '/usr/bin/HandBrakeCLI'
  12. flush_commskip = False
  13. build_seektable = False
  14. ################################
  15.  
  16. def runjob(jobid=None, chanid=None, starttime=None):
  17. db = MythDB()
  18. if jobid:
  19. job = Job(jobid, db=db)
  20. chanid = job.chanid
  21. starttime = job.starttime
  22. rec = Recorded((chanid, starttime), db=db)
  23.  
  24. sg = findfile(rec.basename, rec.storagegroup, db=db)
  25. if sg is None:
  26. print 'Local access to recording not found.'
  27. sys.exit(1)
  28.  
  29. infile = os.path.join(sg.dirname, rec.basename)
  30. # outfile = '%s.mkv' % infile.rsplit('.',1)[0]
  31. outfile = '%s.m4v' % infile.rsplit('.',1)[0]
  32. #### list of segments to be cut
  33. # rec.markup.gencutlist()
  34. #### list of segments to keep
  35. # rec.markup.genuncutlist()
  36. task = System(path=transcoder, db=db)
  37. try:
  38. ##############################################
  39. #### probably need to adjust this one too ####
  40. # output = task('"%s"' % infile,
  41. # '"%s"' % outfile)
  42. output = task('-i "%s"' % infile,
  43. '-o "%s"' % outfile,
  44. '-f m4v',
  45. '--preset="AppleTV"',
  46. '>/dev/null 2>&1' )
  47. ##############################################
  48. except MythError, e:
  49. print 'Command failed with output:\n%s' % e.stderr
  50. sys.exit(e.returncode)
  51.  
  52. rec.basename = os.path.basename(outfile)
  53. os.remove(infile)
  54. rec.filesize = os.path.getsize(outfile)
  55. rec.transcoded = 1
  56. rec.seek.clean()
  57. if flush_commskip:
  58. for index,mark in reversed(list(enumerate(rec.markup))):
  59. if mark.type in (rec.markup.MARK_COMM_START, rec.markup.MARK_COMM_END):
  60. del rec.markup[index]
  61. rec.bookmark = 0
  62. rec.cutlist = 0
  63. rec.markup.commit()
  64.  
  65. if build_seektable:
  66. task = System(path='mythcommflag')
  67. task.command('--chanid %s' % chanid,
  68. '--starttime %s' % starttime,
  69. '--rebuild')
  70.  
  71. rec.update()
  72.  
  73. if jobid:
  74. job.update({'status':272, 'comment':'Transcode Completed'})
  75.  
  76. def main():
  77. parser = OptionParser(usage="usage: %prog [options] [jobid]")
  78.  
  79. parser.add_option('--chanid', action='store', type='int', dest='chanid',
  80. help='Use chanid for manual operation')
  81. parser.add_option('--starttime', action='store', type='int', dest='starttime',
  82. help='Use starttime for manual operation')
  83. parser.add_option('-v', '--verbose', action='store', type='string', dest='verbose',
  84. help='Verbosity level')
  85.  
  86. opts, args = parser.parse_args()
  87.  
  88. if opts.verbose:
  89. if opts.verbose == 'help':
  90. print MythLog.helptext
  91. sys.exit(0)
  92. MythLog._setlevel(opts.verbose)
  93.  
  94. if len(args) == 1:
  95. runjob(jobid=args[0])
  96. elif opts.chanid and opts.starttime:
  97. runjob(chanid=opts.chanid, starttime=opts.starttime)
  98. else:
  99. print 'Script must be provided jobid, or chanid and starttime.'
  100. sys.exit(1)
  101.  
  102. if __name__ == '__main__':
  103. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement