Exemplo n.º 1
0
    def getepdata(self):
        """ Return dict of formatted data available to config'd output file format
        """

        epdata = self.extra.copy()
        epdata.update({
            'originalfilename': self.fullfilename,
            'ext': self.extension,
            'episode': formatEpisodeNumbers(self.episodenumbers),
        })

        # format dynamic parts according to config
        for key in epdata.keys():
            if key == 'originalfilename':
                continue
            if key == 'episodename':
                epdata[key] = formatEpisodeNames(epdata[key])
            if key in ('seriesname', 'episodename'):
                if Config['lowercase_dynamic_parts']:
                    epdata[key] = epdata[key].lower()
                elif Config['titlecase_dynamic_parts']:
                    epdata[key] = titlecase(epdata[key])
                epdata[key] = makeValidFilename(epdata[key])

            # TODO: would be better to expose only strings? (%s can accept int, but %d cannot accept str,
            # so using %s in format strings is less error-prone)
            if key == 'seasonnumber':
                epdata[key] = int(epdata[key])

        return epdata
Exemplo n.º 2
0
    def getNewFullPath(self):
        """ Generates final fullPath, with all replacements, formatting etc.
            It's ready to pass it to Renamer.rename().
        """

        epdata = self.getepdata()
        newName = self.getFormatString() % epdata

        if len(Config['output_filename_replacements']) > 0:
            p("Before custom output replacements: '%s'" % newName)
            newName = applyCustomOutputReplacements(newName)
            p("After custom output replacements:  '%s'" % newName)

        if self.eptype == 'dated':
            newPath = Config['move_files_destination_date'] % epdata
        else:
            newPath = Config['move_files_destination'] % epdata
        if Config['move_files_destination_is_filepath']:
            newPath, newName = os.path.split(newPath)

        # make newName lowercase if specified in config
        if Config['lowercase_filename']:
            newName = newName.lower()

        # make sure the filename is valid
        newName = makeValidFilename(newName)

        # Join new filepath to old one (to handle realtive dirs)
        oldPath = os.path.dirname(self.fullpath)
        newFullPath = os.path.abspath(os.path.join(oldPath, newPath, newName))

        # apply full-path replacements
        if len(Config['move_files_fullpath_replacements']) > 0:
            p("Before custom full path replacements: '%s'" % (newFullPath))
            newFullPath = applyCustomFullpathReplacements(newFullPath)

        return newFullPath