Advertisement
Guest User

Untitled

a guest
Feb 20th, 2013
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #Frank's Video Processing Magic
  3. from multiprocessing import Process, Queue, log_to_stderr
  4. from os import path, popen
  5. from subprocess import call
  6. import logging, pyinotify
  7.  
  8. config = {
  9.     'IN_FOLDER':    '/home/media/Uploads',
  10.     'OUT_FOLDER':   '/home/media/MoviesToProcess',
  11.     'HANDBRAKE':    'HandBrakeCLI -i "{input_file}" -o "{output_file}" -ex264 -Ecopy:aac'
  12. }
  13.  
  14. def ConversionEngine(queue):
  15.     log = log_to_stderr()
  16.     log.setLevel(logging.INFO)
  17.     while True:
  18.         event = queue.get()
  19.         input_file = event.pathname
  20.         log.info("Starting processing for %s" % input_file)
  21.         filename = "%s.mp4" % path.splitext(path.basename(input_file))[0]
  22.         output_file = path.join(config['OUT_FOLDER'], filename)
  23.         cli = config['HANDBRAKE'].format(input_file = input_file, output_file=output_file)
  24.         log.info(cli)
  25.         call(cli, shell=True)
  26.  
  27. class NotifyHandler(pyinotify.ProcessEvent):
  28.     def my_init(self, queue):
  29.         self.queue = queue
  30.         self.log = log_to_stderr()
  31.         self.log.setLevel(logging.INFO)
  32.     def process_IN_CLOSE_WRITE(self, event):
  33.         self.log.info("Got file: %s" % event.pathname)
  34.         self.queue.put(event)
  35.  
  36. if __name__ == '__main__':
  37.     queue = Queue()
  38.     Process(target = ConversionEngine, args=(queue,)).start()
  39.     handler = NotifyHandler(queue = queue)
  40.     wm = pyinotify.WatchManager()
  41.     notifier = pyinotify.Notifier(wm, handler)
  42.     wm.add_watch(config['IN_FOLDER'], pyinotify.IN_CLOSE_WRITE)
  43.     notifier.loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement