Example #1
0
    def test_apply_replacements(self):
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample.avi', None))
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample.avi', []))

        reps = [{'match': '_test',
                 'replacement': '',
                 'with_extension': False,
                 'is_regex': False},
                ]
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample_test.avi', reps))

        reps = [{'match': '_test',
                 'replacement': '',
                 'with_extension': True,
                 'is_regex': False},
                ]
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample_test.avi', reps))

        reps = [{'match': '[ua]+',
                 'replacement': 'x',
                 'with_extension': False,
                 'is_regex': True},
                ]
        self.assertEqual('sxmple_test.avi',
                         formatter.apply_replacements('sample_test.avi', reps))
Example #2
0
    def test_apply_replacements(self):
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample.avi', None))
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample.avi', []))

        reps = [
            {
                'match': '_test',
                'replacement': '',
                'with_extension': False,
                'is_regex': False
            },
        ]
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample_test.avi', reps))

        reps = [
            {
                'match': '_test',
                'replacement': '',
                'with_extension': True,
                'is_regex': False
            },
        ]
        self.assertEqual('sample.avi',
                         formatter.apply_replacements('sample_test.avi', reps))

        reps = [
            {
                'match': '[ua]+',
                'replacement': 'x',
                'with_extension': False,
                'is_regex': True
            },
        ]
        self.assertEqual('sxmple_test.avi',
                         formatter.apply_replacements('sample_test.avi', reps))
Example #3
0
    def parse(self):
        """Extracts component keys from filename.

        :raises tvrenamer.exceptions.InvalidFilename:
            when filename was not parseable
        :raises tvrenamer.exceptions.ConfigValueError:
            when regex used for parsing was incorrectly configured
        """

        self.clean_name = formatter.apply_replacements(
            self.name, cfg.CONF.input_filename_replacements)

        output = parser.parse_filename(self.clean_name)

        if output is None:
            self.messages.append(
                'Invalid filename: unable to parse {0}'.format(
                    self.clean_name))
            LOG.info(self.messages[-1])
            raise exc.InvalidFilename(self.messages[-1])

        self.episode_numbers = output.get('episode_numbers')
        if self.episode_numbers is None:
            self.messages.append(
                'Regex does not contain episode number group, '
                'should contain episodenumber, episodenumber1-9, '
                'or episodenumberstart and episodenumberend\n\n'
                'Pattern was:\n' + output.get('pattern'))
            LOG.info(self.messages[-1])
            raise exc.ConfigValueError(self.messages[-1])

        self.series_name = output.get('series_name')
        if self.series_name is None:
            self.messages.append(
                'Regex must contain seriesname. Pattern was:\n' +
                output.get('pattern'))
            LOG.info(self.messages[-1])
            raise exc.ConfigValueError(self.messages[-1])

        self.series_name = formatter.clean_series_name(self.series_name)
        self.season_number = output.get('season_number')
Example #4
0
    def parse(self):
        """Extracts component keys from filename.

        :raises tvrenamer.exceptions.InvalidFilename:
            when filename was not parseable
        :raises tvrenamer.exceptions.ConfigValueError:
            when regex used for parsing was incorrectly configured
        """

        self.clean_name = formatter.apply_replacements(
            self.name, cfg.CONF.input_filename_replacements)

        output = parser.parse_filename(self.clean_name)

        if output is None:
            self.messages.append(
                'Invalid filename: unable to parse {0}'.format(
                    self.clean_name))
            LOG.info(self.messages[-1])
            raise exc.InvalidFilename(self.messages[-1])

        self.episode_numbers = output.get('episode_numbers')
        if self.episode_numbers is None:
            self.messages.append(
                'Regex does not contain episode number group, '
                'should contain episodenumber, episodenumber1-9, '
                'or episodenumberstart and episodenumberend\n\n'
                'Pattern was:\n' + output.get('pattern'))
            LOG.info(self.messages[-1])
            raise exc.ConfigValueError(self.messages[-1])

        self.series_name = output.get('series_name')
        if self.series_name is None:
            self.messages.append(
                'Regex must contain seriesname. Pattern was:\n' +
                output.get('pattern'))
            LOG.info(self.messages[-1])
            raise exc.ConfigValueError(self.messages[-1])

        self.series_name = formatter.clean_series_name(self.series_name)
        self.season_number = output.get('season_number')