Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #Frank's Video Processing Magic
- from multiprocessing import Process, Queue, log_to_stderr
- from os import path, popen
- from subprocess import call
- import logging, pyinotify
- config = {
- 'IN_FOLDER': '/home/media/Uploads',
- 'OUT_FOLDER': '/home/media/MoviesToProcess',
- 'HANDBRAKE': 'HandBrakeCLI -i "{input_file}" -o "{output_file}" -ex264 -Ecopy:aac'
- }
- def ConversionEngine(queue):
- log = log_to_stderr()
- log.setLevel(logging.INFO)
- while True:
- event = queue.get()
- input_file = event.pathname
- log.info("Starting processing for %s" % input_file)
- filename = "%s.mp4" % path.splitext(path.basename(input_file))[0]
- output_file = path.join(config['OUT_FOLDER'], filename)
- cli = config['HANDBRAKE'].format(input_file = input_file, output_file=output_file)
- log.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__':
- queue = Queue()
- Process(target = ConversionEngine, args=(queue,)).start()
- handler = NotifyHandler(queue = queue)
- 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
Advertisement