def validateDir(path, dirName, nzbNameOriginal, failed, result): """ Check if directory is valid for processing :param path: Path to use :param dirName: Directory to check :param nzbNameOriginal: Original NZB name :param failed: Previously failed objects :param result: Previous results :return: True if dir is valid for processing, False if not """ IGNORED_FOLDERS = ['.AppleDouble', '.@__thumb', '@eaDir'] folder_name = os.path.basename(dirName) if folder_name in IGNORED_FOLDERS: return False result.output += logHelper("Processing folder " + dirName, sickrage.srCore.srLogger.DEBUG) if folder_name.startswith('_FAILED_'): result.output += logHelper("The directory name indicates it failed to extract.", sickrage.srCore.srLogger.DEBUG) failed = True elif folder_name.startswith('_UNDERSIZED_'): result.output += logHelper("The directory name indicates that it was previously rejected for being undersized.", sickrage.srCore.srLogger.DEBUG) failed = True elif folder_name.upper().startswith('_UNPACK'): result.output += logHelper( "The directory name indicates that this release is in the process of being unpacked.", sickrage.srCore.srLogger.DEBUG) result.missedfiles.append(dirName + " : Being unpacked") return False if failed: process_failed(os.path.join(path, dirName), nzbNameOriginal, result) result.missedfiles.append(dirName + " : Failed download") return False if is_hidden_folder(os.path.join(path, dirName)): result.output += logHelper("Ignoring hidden folder: " + dirName, sickrage.srCore.srLogger.DEBUG) result.missedfiles.append(dirName + " : Hidden folder") return False # make sure the dir isn't inside a show dir for dbData in [x['doc'] for x in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True)]: if dirName.lower().startswith(os.path.realpath(dbData["location"]).lower() + os.sep) or \ dirName.lower() == os.path.realpath(dbData["location"]).lower(): result.output += logHelper( "Cannot process an episode that's already been moved to its show dir, skipping " + dirName, sickrage.srCore.srLogger.WARNING) return False # Get the videofile list for the next checks allFiles = [] allDirs = [] for _, processdir, fileList in os.walk(os.path.join(path, dirName), topdown=False): allDirs += processdir allFiles += fileList videoFiles = [x for x in allFiles if isMediaFile(x)] allDirs.append(dirName) # check if the dir have at least one tv video file for video in videoFiles: try: NameParser().parse(video, cache_result=False) return True except (InvalidNameException, InvalidShowException): pass for proc_dir in allDirs: try: NameParser().parse(proc_dir, cache_result=False) return True except (InvalidNameException, InvalidShowException): pass if sickrage.srCore.srConfig.UNPACK: # Search for packed release packedFiles = [x for x in allFiles if isRarFile(x)] for packed in packedFiles: try: NameParser().parse(packed, cache_result=False) return True except (InvalidNameException, InvalidShowException): pass result.output += logHelper(dirName + " : No processable items found in folder", sickrage.srCore.srLogger.DEBUG) return False
def validateDir(process_path, release_name, failed, result): """ Check if directory is valid for processing :param process_path: Directory to check :param release_name: Original NZB/Torrent name :param failed: Previously failed objects :param result: Previous results :return: True if dir is valid for processing, False if not """ result.output += logHelper("Processing folder " + process_path, sickrage.app.log.DEBUG) upper_name = os.path.basename(process_path).upper() if upper_name.startswith('_FAILED_') or upper_name.endswith('_FAILED_'): result.output += logHelper("The directory name indicates it failed to extract.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNDERSIZED_') or upper_name.endswith('_UNDERSIZED_'): result.output += logHelper("The directory name indicates that it was previously rejected for being undersized.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNPACK') or upper_name.endswith('_UNPACK'): result.output += logHelper( "The directory name indicates that this release is in the process of being unpacked.", sickrage.app.log.DEBUG) result.missed_files.append("{0} : Being unpacked".format(process_path)) return False if failed: process_failed(process_path, release_name, result) result.missed_files.append("{0} : Failed download".format(process_path)) return False if sickrage.app.config.tv_download_dir and real_path(process_path) != real_path( sickrage.app.config.tv_download_dir) and is_hidden_folder(process_path): result.output += logHelper("Ignoring hidden folder: {0}".format(process_path), sickrage.app.log.DEBUG) result.missed_files.append("{0} : Hidden folder".format(process_path)) return False # make sure the dir isn't inside a show dir for show in sickrage.app.showlist: if process_path.lower().startswith(os.path.realpath(show.location).lower() + os.sep) or \ process_path.lower() == os.path.realpath(show.location).lower(): result.output += logHelper( "Cannot process an episode that's already been moved to its show dir, skipping " + process_path, sickrage.app.log.WARNING) return False for current_directory, directory_names, file_names in os.walk(process_path, topdown=False, followlinks=sickrage.app.config.processor_follow_symlinks): sync_files = filter(is_sync_file, file_names) if sync_files and sickrage.app.config.postpone_if_sync_files: result.output += logHelper("Found temporary sync files: {0} in path: {1}".format(sync_files, os.path.join(process_path, sync_files[ 0]))) result.output += logHelper("Skipping post processing for folder: {0}".format(process_path)) result.missed_files.append("{0} : Sync files found".format(os.path.join(process_path, sync_files[0]))) continue found_files = filter(is_media_file, file_names) if sickrage.app.config.unpack == 1: found_files += filter(is_rar_file, file_names) if current_directory != sickrage.app.config.tv_download_dir and found_files: found_files.append(os.path.basename(current_directory)) for found_file in found_files: try: NameParser().parse(found_file, cache_result=False) except (InvalidNameException, InvalidShowException) as e: pass else: return True result.output += logHelper("{0} : No processable items found in folder".format(process_path), sickrage.app.log.DEBUG) return False
def validateDir(self, process_path, release_name, failed): """ Check if directory is valid for processing :param process_path: Directory to check :param release_name: Original NZB/Torrent name :param failed: Previously failed objects :return: True if dir is valid for processing, False if not """ self.log("Processing folder " + process_path, sickrage.app.log.DEBUG) upper_name = os.path.basename(process_path).upper() if upper_name.startswith('_FAILED_') or upper_name.endswith('_FAILED_'): self.log("The directory name indicates it failed to extract.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNDERSIZED_') or upper_name.endswith('_UNDERSIZED_'): self.log( "The directory name indicates that it was previously rejected for being undersized.", sickrage.app.log.DEBUG) failed = True elif upper_name.startswith('_UNPACK') or upper_name.endswith('_UNPACK'): self.log( "The directory name indicates that this release is in the process of being unpacked.", sickrage.app.log.DEBUG) self.missed_files.append("{0} : Being unpacked".format(process_path)) return False if failed: self.process_failed(process_path, release_name) self.missed_files.append("{0} : Failed download".format(process_path)) return False if sickrage.app.config.tv_download_dir and real_path(process_path) != real_path( sickrage.app.config.tv_download_dir) and is_hidden_folder(process_path): self.log("Ignoring hidden folder: {0}".format(process_path), sickrage.app.log.DEBUG) self.missed_files.append("{0} : Hidden folder".format(process_path)) return False # make sure the dir isn't inside a show dir for show in get_show_list(): if process_path.lower().startswith(os.path.realpath(show.location).lower() + os.sep) or \ process_path.lower() == os.path.realpath(show.location).lower(): self.log("Cannot process an episode that's already been moved to its show dir, skipping " + process_path, sickrage.app.log.WARNING) return False for current_directory, directory_names, file_names in os.walk(process_path, topdown=False, followlinks=sickrage.app.config.processor_follow_symlinks): sync_files = list(filter(is_sync_file, file_names)) if sync_files and sickrage.app.config.postpone_if_sync_files: self.log("Found temporary sync files: {0} in path: {1}".format(sync_files, os.path.join( process_path, sync_files[ 0]))) self.log("Skipping post processing for folder: {0}".format(process_path)) self.missed_files.append("{0} : Sync files found".format(os.path.join(process_path, sync_files[0]))) continue found_files = list(filter(is_media_file, file_names)) if sickrage.app.config.unpack == 1: found_files += list(filter(is_rar_file, file_names)) if current_directory != sickrage.app.config.tv_download_dir and found_files: found_files.append(os.path.basename(current_directory)) for found_file in found_files: try: NameParser().parse(found_file, cache_result=False) except (InvalidNameException, InvalidShowException) as e: pass else: return True self.log("Folder {} : No processable items found in folder".format(process_path), sickrage.app.log.DEBUG) return False