def _format_string(pattern, replace_map): """ Replaces all template strings with the correct value """ result_name = pattern # do the replacements for cur_replacement in sorted(replace_map.keys(), reverse=True): result_name = result_name.replace(cur_replacement, sanitizeFileName(replace_map[cur_replacement])) result_name = result_name.replace(cur_replacement.lower(), sanitizeFileName(replace_map[cur_replacement].lower())) return result_name
def addDefaultShow(indexer, indexer_id, name, status): """ Adds a new show with the default settings """ if not findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id)): sickrage.srCore.srLogger.info("Adding show " + str(indexer_id)) root_dirs = sickrage.srCore.srConfig.ROOT_DIRS.split('|') try: location = root_dirs[int(root_dirs[0]) + 1] except Exception: location = None if location: showPath = os.path.join(location, sanitizeFileName(name)) dir_exists = makeDir(showPath) if not dir_exists: sickrage.srCore.srLogger.warning("Unable to create the folder %s , can't add the show" % showPath) return else: chmodAsParent(showPath) sickrage.srCore.SHOWQUEUE.addShow(int(indexer), int(indexer_id), showPath, default_status=status, quality=int(sickrage.srCore.srConfig.QUALITY_DEFAULT), flatten_folders=int(sickrage.srCore.srConfig.FLATTEN_FOLDERS_DEFAULT), paused=sickrage.srCore.srConfig.TRAKT_START_PAUSED, default_status_after=status, archive=sickrage.srCore.srConfig.ARCHIVE_DEFAULT) else: sickrage.srCore.srLogger.warning( "There was an error creating the show, no root directory setting found") return
def addDefaultShow(indexer, indexer_id, name, status): """ Adds a new show with the default settings """ if not findCertainShow(int(indexer_id)): sickrage.app.log.info("Adding show " + str(indexer_id)) root_dirs = sickrage.app.config.root_dirs.split('|') try: location = root_dirs[int(root_dirs[0]) + 1] except Exception: location = None if location: showPath = os.path.join(location, sanitizeFileName(name)) dir_exists = makeDir(showPath) if not dir_exists: sickrage.app.log.warning("Unable to create the folder %s , can't add the show" % showPath) return else: chmodAsParent(showPath) sickrage.app.show_queue.addShow(int(indexer), int(indexer_id), showPath, default_status=status, quality=int(sickrage.app.config.quality_default), flatten_folders=int(sickrage.app.config.flatten_folders_default), paused=sickrage.app.config.trakt_start_paused, default_status_after=status, archive=sickrage.app.config.archive_default) else: sickrage.app.log.warning( "There was an error creating the show, no root directory setting found") return
def formatted_filename(show, episode, pattern=None, multi=None, anime_type=None): """ Just the filename of the episode, formatted based on the naming settings """ if pattern is None: # we only use ABD if it's enabled, this is an ABD show, AND this is not a multi-ep if show.air_by_date and sickrage.NAMING_CUSTOM_ABD and not episode.relatedEps: pattern = sickrage.NAMING_ABD_PATTERN elif show.sports and sickrage.NAMING_CUSTOM_SPORTS and not episode.relatedEps: pattern = sickrage.NAMING_SPORTS_PATTERN elif show.anime and sickrage.NAMING_CUSTOM_ANIME: pattern = sickrage.NAMING_ANIME_PATTERN else: pattern = sickrage.NAMING_PATTERN # split off the dirs only, if they exist name_groups = re.split(r'[\\/]', pattern) return sanitizeFileName( _format_pattern(show, episode, name_groups[-1], multi, anime_type))
def _format_string(pattern, replace_map): """ Replaces all template strings with the correct value """ result_name = pattern # do the replacements for cur_replacement in sorted(replace_map.keys(), reverse=True): result_name = result_name.replace( cur_replacement, sanitizeFileName(replace_map[cur_replacement])) result_name = result_name.replace( cur_replacement.lower(), sanitizeFileName(replace_map[cur_replacement].lower())) return result_name
def addDefaultShow(indexer, indexer_id, name, status): """ Adds a new show with the default settings """ if not findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id)): sickrage.srCore.srLogger.info("Adding show " + str(indexer_id)) root_dirs = sickrage.srCore.srConfig.ROOT_DIRS.split('|') try: location = root_dirs[int(root_dirs[0]) + 1] except Exception: location = None if location: showPath = os.path.join(location, sanitizeFileName(name)) dir_exists = makeDir(showPath) if not dir_exists: sickrage.srCore.srLogger.warning("Unable to create the folder %s , can't add the show" % showPath) return else: chmodAsParent(showPath) sickrage.srCore.SHOWQUEUE.addShow(int(indexer), int(indexer_id), showPath, default_status=status, quality=int(sickrage.srCore.srConfig.QUALITY_DEFAULT), flatten_folders=int(sickrage.srCore.srConfig.FLATTEN_FOLDERS_DEFAULT), paused=sickrage.srCore.srConfig.TRAKT_START_PAUSED, default_status_after=status, archive=sickrage.srCore.srConfig.ARCHIVE_DEFAULT) else: sickrage.srCore.srLogger.warning("There was an error creating the show, no root directory setting found") return
def addDefaultShow(indexer, indexer_id, name, status): """ Adds a new show with the default settings """ if not findCertainShow(int(indexer_id)): sickrage.app.log.info("Adding show " + str(indexer_id)) root_dirs = sickrage.app.config.root_dirs.split('|') try: location = root_dirs[int(root_dirs[0]) + 1] except Exception: location = None if location: showPath = os.path.join(location, sanitizeFileName(name)) dir_exists = makeDir(showPath) if not dir_exists: sickrage.app.log.warning("Unable to create the folder %s , can't add the show" % showPath) return else: chmod_as_parent(showPath) sickrage.app.show_queue.addShow(int(indexer), int(indexer_id), showPath, default_status=status, quality=int(sickrage.app.config.quality_default), flatten_folders=int(sickrage.app.config.flatten_folders_default), paused=sickrage.app.config.trakt_start_paused, default_status_after=status, skip_downloaded=sickrage.app.config.skip_downloaded_default) else: sickrage.app.log.warning( "There was an error creating the show, no root directory setting found") return
def test_encoding(self): rootDir = 'C:\\Temp\\TV' strings = ['Les Enfants De La T\xe9l\xe9', 'RT� One'] sickrage.app.sys_encoding = None try: locale.setlocale(locale.LC_ALL, "") sickrage.app.sys_encoding = locale.getpreferredencoding() except (locale.Error, IOError): pass # For OSes that are poorly configured I'll just randomly force UTF-8 if not sickrage.app.sys_encoding or sickrage.app.sys_encoding in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'): sickrage.app.sys_encoding = 'UTF-8' for s in strings: show_dir = os.path.join(rootDir, sanitizeFileName(s)) self.assertIsInstance(show_dir, unicode)
def test_encoding(self): rootDir = 'C:\\Temp\\TV' strings = ['Les Enfants De La T\xe9l\xe9', 'RT� One'] sickrage.SYS_ENCODING = None try: locale.setlocale(locale.LC_ALL, "") sickrage.SYS_ENCODING = locale.getpreferredencoding() except (locale.Error, IOError): pass # For OSes that are poorly configured I'll just randomly force UTF-8 if not sickrage.SYS_ENCODING or sickrage.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'): sickrage.SYS_ENCODING = 'UTF-8' for s in strings: show_dir = os.path.join(rootDir, sanitizeFileName(s)) self.assertIsInstance(show_dir, unicode)
def formatted_filename(show, episode, pattern=None, multi=None, anime_type=None): """ Just the filename of the episode, formatted based on the naming settings """ if pattern is None: # we only use ABD if it's enabled, this is an ABD show, AND this is not a multi-ep if show.air_by_date and sickrage.NAMING_CUSTOM_ABD and not episode.relatedEps: pattern = sickrage.NAMING_ABD_PATTERN elif show.sports and sickrage.NAMING_CUSTOM_SPORTS and not episode.relatedEps: pattern = sickrage.NAMING_SPORTS_PATTERN elif show.anime and sickrage.NAMING_CUSTOM_ANIME: pattern = sickrage.NAMING_ANIME_PATTERN else: pattern = sickrage.NAMING_PATTERN # split off the dirs only, if they exist name_groups = re.split(r'[\\/]', pattern) return sanitizeFileName(_format_pattern(show, episode, name_groups[-1], multi, anime_type))
def make_url(self, result): urls, filename = super(NZBProvider, self).make_url(result) filename = os.path.join(sickrage.srCore.srConfig.NZB_DIR, sanitizeFileName(result.name) + '.' + self.type) return urls, filename
def make_filename(self, name): return os.path.join(sickrage.srCore.srConfig.NZB_DIR, '{}.{}'.format(sanitizeFileName(name), self.type))