def move(self, destination_directory, deleteSourceDirectory=False): jvr_helper.log('move') jvr_helper.log(deleteSourceDirectory) jvr_helper.ensure_path(destination_directory) destination = self.get_destination(destination_directory) jvr_helper.log('destination: ' + destination) jvr_helper.log('now try to move') jvr_helper.log('self.source: ' + self.source) shutil.move(self.source, destination) if deleteSourceDirectory: shutil.rmtree(self.get_directory()) self.source = destination
def get_command(self, new_video): command = ['/usr/local/bin/ffmpeg', '-i', new_video.source] if new_video.get_format() == 'mkv': command.extend(['-y', '-f', 'mp4', '-vcodec', 'copy', '-ac', '2', '-c:a', 'libfaac']) elif new_video.get_format() == 'avi': command.extend(['-vcodec', 'libx264']) else: jvr_helper.log('unrecognized format: ' + new_video.get_format()) raise 'unrecognized format' jvr_helper.log(new_video.get_destination(self.converted_folder)) #command.append(new_video.get_destination(self.converted_folder)) command.append(new_video.get_converted_file_path(self.converted_folder)) return command
def main(): jvr_helper.log("start jvr") completed_downloads_folder_handler = completed_folder_handler.CompletedFolderHandler( queue_folder=QUEUE_FOLDER, watch_folder=WATCH_FOLDER ) completed_downloads_folder_handler.move_to_queue() queue = queue_handler.QueueHandler( queue_folder=QUEUE_FOLDER, processing_folder=PROCESSING_FOLDER, reject_folder=REJECT_FOLDER, converted_folder=CONVERTED_FOLDER, ) queue.process_all_conversions()
def process_all_conversions(self): videos = self.get_videos_from_folder(self.queue_folder) jvr_helper.log(videos) for new_video in videos: self.process_video_conversion(new_video)
def process_video_conversion(self, new_video): jvr_helper.log("process_video") jvr_helper.log(new_video.source) if (new_video == None) or (new_video.source == ".DS_Store"): return jvr_helper.log("move new_video") new_video.move(self.processing_folder, False) jvr_helper.log("finish move") jvr_helper.log(new_video.source) if self.converter.convert(new_video, self.converted_folder): jvr_helper.log("success, now remove") self.remove_video(new_video) else: jvr_helper.log("failure") new_video.move(self.reject_folder, False)
def convert(self, new_video, destination_directory): jvr_helper.log('------------') new_video.move(self.processing_folder) jvr_helper.log('self.processing_folder') jvr_helper.log(os.listdir(self.processing_folder)) jvr_helper.log(self.get_command(new_video)) jvr_helper.log(' '.join(self.get_command(new_video))) jvr_helper.log('new video.source: ' + new_video.source) jvr_helper.log('original copy exists: ' + str(new_video.exists())) conversion = subprocess.Popen(self.get_command(new_video), stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate() jvr_helper.log('conversion ended') jvr_helper.log(conversion) jvr_helper.log('------------') return True