Exemplo n.º 1
0
def transform_filename(fname):
    # type: (str) -> str

    if Config['titlecase_filename']:
        from tvnamer._titlecase import titlecase
        fname = titlecase(fname)

    if Config['lowercase_filename']:
        fname = fname.lower()

    # Replace accented characters with ASCII equivalent
    if Config['normalize_unicode_filenames']:
        import unicodedata
        fname = unicodedata.normalize('NFKD',
                                      fname).encode('ascii',
                                                    'ignore').decode("utf-8")

    return fname
Exemplo n.º 2
0
    def generateFilename(self, lowercase = False, preview_orig_filename = False):
        epdata = self.getepdata()

        # Add in extra dict keys, without clobbering existing values in epdata
        extra = self.extra.copy()
        extra.update(epdata)
        epdata = extra

        if self.episodename is None:
            fname = Config[self.CFG_KEY_WITHOUT_EP] % epdata
        else:
            if isinstance(self.episodename, list):
                epdata['episodename'] = formatEpisodeName(
                    self.episodename,
                    join_with = Config['multiep_join_name_with'])
            fname = Config[self.CFG_KEY_WITH_EP] % epdata

        if Config['titlecase_filename']:
            from tvnamer._titlecase import titlecase
            fname = titlecase(fname)

        if lowercase or Config['lowercase_filename']:
            fname = fname.lower()

        if preview_orig_filename:
            # Return filename without custom replacements or filesystem-validness
            return fname

        if len(Config['output_filename_replacements']) > 0:
            # Only apply replacements to filename, not extension
            splitname, splitext = os.path.splitext(fname)
            newname = applyCustomOutputReplacements(splitname)
            fname = newname + splitext

        return makeValidFilename(
            fname,
            normalize_unicode = Config['normalize_unicode_filenames'],
            windows_safe = Config['windows_safe_filenames'],
            custom_blacklist = Config['custom_filename_character_blacklist'],
            replace_with = Config['replace_invalid_characters_with'])
Exemplo n.º 3
0
    def generateFilename(self, lowercase=False, preview_orig_filename=False):
        epdata = self.getepdata()

        # Add in extra dict keys, without clobbering existing values in epdata
        extra = self.extra.copy()
        extra.update(epdata)
        epdata = extra

        if self.episodename is None:
            fname = Config[self.CFG_KEY_WITHOUT_EP] % epdata
        else:
            if isinstance(self.episodename, list):
                epdata['episodename'] = formatEpisodeName(
                    self.episodename,
                    join_with=Config['multiep_join_name_with'])
            fname = Config[self.CFG_KEY_WITH_EP] % epdata

        if Config['titlecase_filename']:
            from tvnamer._titlecase import titlecase
            fname = titlecase(fname)

        if lowercase or Config['lowercase_filename']:
            fname = fname.lower()

        if preview_orig_filename:
            # Return filename without custom replacements or filesystem-validness
            return fname

        if len(Config['output_filename_replacements']) > 0:
            # Only apply replacements to filename, not extension
            splitname, splitext = os.path.splitext(fname)
            newname = applyCustomOutputReplacements(splitname)
            fname = newname + splitext

        return makeValidFilename(
            fname,
            normalize_unicode=Config['normalize_unicode_filenames'],
            windows_safe=Config['windows_safe_filenames'],
            custom_blacklist=Config['custom_filename_character_blacklist'],
            replace_with=Config['replace_invalid_characters_with'])