def process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, result): """ Postprocess mediafiles :param processPath: Path to postprocess in :param videoFiles: Filenames to look for and postprocess :param nzbName: Name of NZB file related :param process_method: auto/manual :param force: Postprocess currently postprocessing file :param is_priority: Boolean, is this a priority download :param result: Previous results """ processor = None for cur_video_file in videoFiles: cur_video_file_path = os.path.join(processPath, cur_video_file) if already_postprocessed(processPath, cur_video_file, force, result): result.output += logHelper( "Already Processed " + cur_video_file_path + " : Skipping", sickrage.srCore.srLogger.DEBUG) continue try: processor = post_processor.PostProcessor(cur_video_file_path, nzbName, process_method, is_priority) result.result = processor.process process_fail_message = "" except EpisodePostProcessingFailedException as e: result.result = False process_fail_message = e.message if processor: result.output += processor.log if result.result: result.output += logHelper("Processing succeeded for " + cur_video_file_path) else: result.output += logHelper( "Processing failed for " + cur_video_file_path + ": " + process_fail_message, sickrage.srCore.srLogger.WARNING) result.missedfiles.append(cur_video_file_path + " : Processing failed: " + process_fail_message) result.aggresult = False
def process_media(self, processPath, videoFiles, nzbName, process_method, force, is_priority): """ Postprocess mediafiles :param processPath: Path to postprocess in :param videoFiles: Filenames to look for and postprocess :param nzbName: Name of NZB file related :param process_method: auto/manual :param force: Postprocess currently postprocessing file :param is_priority: Boolean, is this a priority download """ processor = None for cur_video_file in videoFiles: cur_video_file_path = os.path.join(processPath, cur_video_file) if self.already_postprocessed(processPath, cur_video_file, force): self.log( "Skipping already processed file: {0}".format( cur_video_file), sickrage.app.log.DEBUG) continue try: processor = post_processor.PostProcessor( cur_video_file_path, nzbName, process_method, is_priority) self.result = processor.process() process_fail_message = "" except EpisodePostProcessingFailedException as e: self.result = False process_fail_message = "{}".format(e) if processor: self._output.append(processor.log) if self.result: self.log("Processing succeeded for " + cur_video_file_path) else: self.log( "Processing failed for {0}: {1}".format( cur_video_file_path, process_fail_message), sickrage.app.log.WARNING) self.missed_files.append("{0} : Processing failed: {1}".format( cur_video_file_path, process_fail_message)) self.succeeded = False
def rename(self): """ Renames an episode file and all related files to the location and filename as specified in the naming settings. """ if not os.path.isfile(self.location): sickrage.LOGGER.warning("Can't perform rename on " + self.location + " when it doesn't exist, skipping") return proper_path = self.proper_path() absolute_proper_path = os.path.join(self.show.location, proper_path) absolute_current_path_no_ext, file_ext = os.path.splitext(self.location) absolute_current_path_no_ext_length = len(absolute_current_path_no_ext) related_subs = [] current_path = absolute_current_path_no_ext if absolute_current_path_no_ext.startswith(self.show.location): current_path = absolute_current_path_no_ext[len(self.show.location):] sickrage.LOGGER.debug("Renaming/moving episode from the base path " + self.location + " to " + absolute_proper_path) # if it's already named correctly then don't do anything if proper_path == current_path: sickrage.LOGGER.debug(str(self.indexerid) + ": File " + self.location + " is already named correctly, skipping") return related_files = post_processor.PostProcessor(self.location).list_associated_files( self.location, base_name_only=True, subfolders=True) # This is wrong. Cause of pp not moving subs. if self.show.subtitles and sickrage.SUBTITLES_DIR != '': related_subs = post_processor.PostProcessor(self.location).list_associated_files(sickrage.SUBTITLES_DIR, subtitles_only=True, subfolders=True) absolute_proper_subs_path = os.path.join(sickrage.SUBTITLES_DIR, formatted_filename(self.show, self)) sickrage.LOGGER.debug("Files associated to " + self.location + ": " + str(related_files)) # move the ep file result = rename_ep_file(self.location, absolute_proper_path, absolute_current_path_no_ext_length) # move related files for cur_related_file in related_files: # We need to fix something here because related files can be in subfolders and the original code doesn't handle this (at all) cur_related_dir = os.path.dirname(os.path.abspath(cur_related_file)) subfolder = cur_related_dir.replace(os.path.dirname(os.path.abspath(self.location)), '') # We now have a subfolder. We need to add that to the absolute_proper_path. # First get the absolute proper-path dir proper_related_dir = os.path.dirname(os.path.abspath(absolute_proper_path + file_ext)) proper_related_path = absolute_proper_path.replace(proper_related_dir, proper_related_dir + subfolder) cur_result = rename_ep_file(cur_related_file, proper_related_path, absolute_current_path_no_ext_length + len(subfolder)) if not cur_result: sickrage.LOGGER.error(str(self.indexerid) + ": Unable to rename file " + cur_related_file) for cur_related_sub in related_subs: absolute_proper_subs_path = os.path.join(sickrage.SUBTITLES_DIR, formatted_filename(self.show, self)) cur_result = rename_ep_file(cur_related_sub, absolute_proper_subs_path, absolute_current_path_no_ext_length) if not cur_result: sickrage.LOGGER.error(str(self.indexerid) + ": Unable to rename file " + cur_related_sub) # save the ep with self.lock: if result: self.location = absolute_proper_path + file_ext for relEp in self.relatedEps: relEp.location = absolute_proper_path + file_ext # in case something changed with the metadata just do a quick check for curEp in [self] + self.relatedEps: curEp.checkForMetaFiles() # save any changes to the databas sql_l = [] with self.lock: for relEp in [self] + self.relatedEps: sql_l.append(relEp.get_sql()) if len(sql_l) > 0: main_db.MainDB().mass_action(sql_l)