Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #Frank's Video Processing Magic
- config = {}
- config['IN_FOLDER'] = '/home/media/Uploads'
- config['OUT_FOLDER'] = '/home/media/MoviesToProcess'
- config['HANDBRAKE'] = 'HandBrakeCLI -i "{input_file}" -o "{output_file}" -ex264 -Ecopy:aac'
- from multiprocessing import Process, Queue, log_to_stderr
- from os import path, popen
- from subprocess import call
- import logging, pyinotify
- def ConversionEngine(q):
- l = log_to_stderr()
- l.setLevel(logging.INFO)
- while True:
- event = q.get()
- file = event.pathname
- l.info("Starting processing for %s" % file)
- filename = "%s.mp4" % path.basename(file)[:path.basename(file).rfind('.')]
- output_file = path.join(config['OUT_FOLDER'], filename)
- cli = config['HANDBRAKE'].format(input_file = file, output_file=output_file)
- l.info(cli)
- call(cli, shell=True)
- class NotifyHandler(pyinotify.ProcessEvent):
- def my_init(self, queue):
- self.queue = queue
- self.log = log_to_stderr()
- self.log.setLevel(logging.INFO)
- def process_IN_CLOSE_WRITE(self, event):
- self.log.info("Got file: %s" % event.pathname)
- self.queue.put(event)
- if __name__ == '__main__':
- q = Queue()
- Process(target = ConversionEngine, args=(q,)).start()
- handler = NotifyHandler(queue = q)
- wm = pyinotify.WatchManager()
- notifier = pyinotify.Notifier(wm, handler)
- wm.add_watch(config['IN_FOLDER'], pyinotify.IN_CLOSE_WRITE)
- notifier.loop()
Advertisement
Add Comment
Please, Sign In to add comment