Advertisement
Guest User

Untitled

a guest
Jan 28th, 2012
134
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 = True
  13. build_seektable = True
  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.  
  37. task = System(path=transcoder, db=db)
  38. try:
  39. ##############################################
  40. #### probably need to adjust this one too ####
  41. # output = task('"%s"' % infile,
  42. # '"%s"' % outfile)
  43. output = task('-i "%s"' % infile,
  44. '-o "%s"' % outfile,
  45. '-f m4v',
  46. '--preset="AppleTV 2"',
  47. '>/dev/null 2>&1' )
  48. ##############################################
  49. except MythError, e:
  50. print 'Command failed with output:\n%s' % e.stderr
  51. sys.exit(e.returncode)
  52.  
  53. rec.basename = os.path.basename(outfile)
  54. os.remove(infile)
  55. rec.filesize = os.path.getsize(outfile)
  56. rec.transcoded = 1
  57. rec.seek.clean()
  58.  
  59. if flush_commskip:
  60. for index,mark in reversed(list(enumerate(rec.markup))):
  61. if mark.type in (rec.markup.MARK_COMM_START, rec.markup.MARK_COMM_END):
  62. del rec.markup[index]
  63. rec.bookmark = 0
  64. rec.cutlist = 0
  65. rec.markup.commit()
  66.  
  67. if build_seektable:
  68. task = System(path='mythcommflag')
  69. task.command('--chanid %s' % chanid,
  70. '--starttime %s' % starttime,
  71. '--rebuild')
  72.  
  73. rec.update()
  74.  
  75. if jobid:
  76. job.update({'status':272, 'comment':'Transcode Completed'})
  77.  
  78. def main():
  79. parser = OptionParser(usage="usage: %prog [options] [jobid]")
  80.  
  81. parser.add_option('--chanid', action='store', type='int', dest='chanid',
  82. help='Use chanid for manual operation')
  83. parser.add_option('--starttime', action='store', type='int', dest='starttime',
  84. help='Use starttime for manual operation')
  85. parser.add_option('-v', '--verbose', action='store', type='string', dest='verbose',
  86. help='Verbosity level')
  87.  
  88. opts, args = parser.parse_args()
  89.  
  90. if opts.verbose:
  91. if opts.verbose == 'help':
  92. print MythLog.helptext
  93. sys.exit(0)
  94. MythLog._setlevel(opts.verbose)
  95.  
  96. if len(args) == 1:
  97. runjob(jobid=args[0])
  98. elif opts.chanid and opts.starttime:
  99. runjob(chanid=opts.chanid, starttime=opts.starttime)
  100. else:
  101. print 'Script must be provided jobid, or chanid and starttime.'
  102. sys.exit(1)
  103.  
  104. if __name__ == '__main__':
  105. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement