Guest User

Untitled

a guest
Feb 19th, 2013
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #Frank's Video Processing Magic
  3.  
  4. config = {}
  5. config['IN_FOLDER'] = '/home/media/Uploads'
  6. config['OUT_FOLDER'] = '/home/media/MoviesToProcess'
  7. config['HANDBRAKE'] = 'HandBrakeCLI -i "{input_file}" -o "{output_file}" -ex264 -Ecopy:aac'
  8.  
  9. from multiprocessing import Process, Queue, log_to_stderr
  10. from os import path, popen
  11. from subprocess import call
  12. import logging, pyinotify
  13.  
  14. def ConversionEngine(q):
  15.     l = log_to_stderr()
  16.     l.setLevel(logging.INFO)
  17.     while True:
  18.         event = q.get()
  19.         file = event.pathname
  20.         l.info("Starting processing for %s" % file)
  21.         filename = "%s.mp4" % path.basename(file)[:path.basename(file).rfind('.')]
  22.         output_file = path.join(config['OUT_FOLDER'], filename)
  23.         cli = config['HANDBRAKE'].format(input_file = file, output_file=output_file)
  24.         l.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.     q = Queue()
  38.     Process(target = ConversionEngine, args=(q,)).start()
  39.     handler = NotifyHandler(queue = q)
  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