Esempio n. 1
0
    def test_remove_extension(self):
        tests = {
            None: None,
            42: 42,
            '': '',
            u'': u'',
            '.': '.',
            u'.': u'.',
            'filename': 'filename',
            u'filename': u'filename',
            '.bashrc': '.bashrc',
            u'.bashrc': u'.bashrc',
            '.nzb': '.nzb',
            u'.nzb': u'.nzb',
            'file.nzb': 'file',
            u'file.nzb': u'file',
            'file.name.nzb': 'file.name',
            u'file.name.nzb': u'file.name',
            '.torrent': '.torrent',
            u'.torrent': u'.torrent',
            'file.torrent': 'file',
            u'file.torrent': u'file',
            'file.name.torrent': 'file.name',
            u'file.name.torrent': u'file.name',
            '.avi': '.avi',
            u'.avi': u'.avi',
            'file.avi': 'file',
            u'file.avi': u'file',
            'file.name.avi': 'file.name',
            u'file.name.avi': u'file.name',
        }

        for (extension, result) in tests.iteritems():
            self.assertEqual(remove_extension(extension), result)
Esempio n. 2
0
    def test_remove_extension(self):
        """
        Test remove extension
        """
        test_cases = {
            None: None,
            42: 42,
            '': '',
            '.': '.',
            'filename': 'filename',
            '.bashrc': '.bashrc',
            '.nzb': '.nzb',
            'file.nzb': 'file',
            'file.name.nzb': 'file.name',
            '.torrent': '.torrent',
            'file.torrent': 'file',
            'file.name.torrent': 'file.name',
            '.avi': '.avi',
            'file.avi': 'file',
            'file.name.avi': 'file.name',
        }

        unicode_test_cases = {
            u'': u'',
            u'.': u'.',
            u'filename': u'filename',
            u'.bashrc': u'.bashrc',
            u'.nzb': u'.nzb',
            u'file.nzb': u'file',
            u'file.name.nzb': u'file.name',
            u'.torrent': u'.torrent',
            u'file.torrent': u'file',
            u'file.name.torrent': u'file.name',
            u'.avi': u'.avi',
            u'file.avi': u'file',
            u'file.name.avi': u'file.name',
        }
        for tests in test_cases, unicode_test_cases:
            for (extension, result) in tests.iteritems():
                self.assertEqual(remove_extension(extension), result)
Esempio n. 3
0
    def test_remove_extension(self):
        """
        Test remove extension
        """
        test_cases = {
            None: None,
            42: 42,
            '': '',
            '.': '.',
            'filename': 'filename',
            '.bashrc': '.bashrc',
            '.nzb': '.nzb',
            'file.nzb': 'file',
            'file.name.nzb': 'file.name',
            '.torrent': '.torrent',
            'file.torrent': 'file',
            'file.name.torrent': 'file.name',
            '.avi': '.avi',
            'file.avi': 'file',
            'file.name.avi': 'file.name',
        }

        unicode_test_cases = {
            '': '',
            '.': '.',
            'filename': 'filename',
            '.bashrc': '.bashrc',
            '.nzb': '.nzb',
            'file.nzb': 'file',
            'file.name.nzb': 'file.name',
            '.torrent': '.torrent',
            'file.torrent': 'file',
            'file.name.torrent': 'file.name',
            '.avi': '.avi',
            'file.avi': 'file',
            'file.name.avi': 'file.name',
        }
        for tests in test_cases, unicode_test_cases:
            for (extension, result) in six.iteritems(tests):
                self.assertEqual(remove_extension(extension), result)
Esempio n. 4
0
    def parse(self, name, cache_result=True, skip_scene_detection=False):
        name = self._unicodify(name)

        if self.naming_pattern:
            cache_result = False

        cached = name_parser_cache.get(name)
        if cached:
            return cached

        # break it into parts if there are any (dirname, file name, extension)
        dir_name, file_name = ek(os.path.split, name)

        if self.file_name:
            base_file_name = remove_extension(file_name)
        else:
            base_file_name = file_name

        # set up a result to use
        final_result = ParseResult(name)

        # try parsing the file name
        file_name_result = self._parse_string(base_file_name, skip_scene_detection)

        # use only the direct parent dir
        dir_name = ek(os.path.basename, dir_name)

        # parse the dirname for extra info if needed
        dir_name_result = self._parse_string(dir_name, skip_scene_detection)

        # build the ParseResult object
        final_result.air_date = self._combine_results(file_name_result, dir_name_result, 'air_date')

        # anime absolute numbers
        final_result.ab_episode_numbers = self._combine_results(file_name_result, dir_name_result, 'ab_episode_numbers')

        # season and episode numbers
        final_result.season_number = self._combine_results(file_name_result, dir_name_result, 'season_number')
        final_result.episode_numbers = self._combine_results(file_name_result, dir_name_result, 'episode_numbers')
        final_result.scene_season = self._combine_results(file_name_result, dir_name_result, 'scene_season')

        # if the dirname has a release group/show name I believe it over the filename
        final_result.series_name = self._combine_results(dir_name_result, file_name_result, 'series_name')
        final_result.extra_info = self._combine_results(dir_name_result, file_name_result, 'extra_info')
        final_result.release_group = self._combine_results(dir_name_result, file_name_result, 'release_group')
        final_result.version = self._combine_results(dir_name_result, file_name_result, 'version')

        final_result.which_regex = []
        if final_result == file_name_result:
            final_result.which_regex = file_name_result.which_regex
        elif final_result == dir_name_result:
            final_result.which_regex = dir_name_result.which_regex
        else:
            if file_name_result:
                final_result.which_regex += file_name_result.which_regex
            if dir_name_result:
                final_result.which_regex += dir_name_result.which_regex

        final_result.show = self._combine_results(file_name_result, dir_name_result, 'show')
        final_result.quality = self._combine_results(file_name_result, dir_name_result, 'quality')

        if not final_result.show:
            raise InvalidShowException("Unable to match {0} to a show in your database. Parser result: {1}".format(
                name, six.text_type(final_result)))

        # if there's no useful info in it then raise an exception
        if final_result.season_number is None and not final_result.episode_numbers and final_result.air_date is None and not final_result.ab_episode_numbers and not final_result.series_name:
            raise InvalidNameException("Unable to parse {0} to a valid episode of {1}. Parser result: {2}".format(
                name, final_result.show.name, six.text_type(final_result)))

        if cache_result:
            name_parser_cache.add(name, final_result)

        logger.log("Parsed " + name + " into " + six.text_type(final_result), logger.DEBUG)
        return final_result
Esempio n. 5
0
    def parse(self, name, cache_result=True, skip_scene_detection=False):
        name = self._unicodify(name)

        if self.naming_pattern:
            cache_result = False

        cached = name_parser_cache.get(name)
        if cached:
            return cached

        # break it into parts if there are any (dirname, file name, extension)
        dir_name, file_name = ek(os.path.split, name)

        if self.file_name:
            base_file_name = remove_extension(file_name)
        else:
            base_file_name = file_name

        # set up a result to use
        final_result = ParseResult(name)

        # try parsing the file name
        file_name_result = self._parse_string(base_file_name,
                                              skip_scene_detection)

        # use only the direct parent dir
        dir_name = ek(os.path.basename, dir_name)

        # parse the dirname for extra info if needed
        dir_name_result = self._parse_string(dir_name, skip_scene_detection)

        # build the ParseResult object
        final_result.air_date = self._combine_results(file_name_result,
                                                      dir_name_result,
                                                      'air_date')

        # anime absolute numbers
        final_result.ab_episode_numbers = self._combine_results(
            file_name_result, dir_name_result, 'ab_episode_numbers')

        # season and episode numbers
        final_result.season_number = self._combine_results(
            file_name_result, dir_name_result, 'season_number')
        final_result.episode_numbers = self._combine_results(
            file_name_result, dir_name_result, 'episode_numbers')
        final_result.scene_season = self._combine_results(
            file_name_result, dir_name_result, 'scene_season')

        # if the dirname has a release group/show name I believe it over the filename
        final_result.series_name = self._combine_results(
            dir_name_result, file_name_result, 'series_name')
        final_result.extra_info = self._combine_results(
            dir_name_result, file_name_result, 'extra_info')
        final_result.release_group = self._combine_results(
            dir_name_result, file_name_result, 'release_group')
        final_result.version = self._combine_results(dir_name_result,
                                                     file_name_result,
                                                     'version')

        final_result.which_regex = []
        if final_result == file_name_result:
            final_result.which_regex = file_name_result.which_regex
        elif final_result == dir_name_result:
            final_result.which_regex = dir_name_result.which_regex
        else:
            if file_name_result:
                final_result.which_regex += file_name_result.which_regex
            if dir_name_result:
                final_result.which_regex += dir_name_result.which_regex

        final_result.show = self._combine_results(file_name_result,
                                                  dir_name_result, 'show')
        final_result.quality = self._combine_results(file_name_result,
                                                     dir_name_result,
                                                     'quality')

        if not final_result.show:
            raise InvalidShowException(
                u"Unable to match {0} to a show in your database. Parser result: {1}"
                .format(name,
                        str(final_result).decode('utf-8',
                                                 'xmlcharrefreplace')))

        # if there's no useful info in it then raise an exception
        if final_result.season_number is None and not final_result.episode_numbers and final_result.air_date is None and not final_result.ab_episode_numbers and not final_result.series_name:
            raise InvalidNameException(
                u"Unable to parse {0} to a valid episode of {1}. Parser result: {2}"
                .format(name, final_result.show.name,
                        str(final_result).decode('utf-8',
                                                 'xmlcharrefreplace')))

        if cache_result:
            name_parser_cache.add(name, final_result)

        logger.log(
            u"Parsed " + name + " into " +
            str(final_result).decode('utf-8', 'xmlcharrefreplace'),
            logger.DEBUG)
        return final_result
Esempio n. 6
0
    def parse(self, name, cache_result=True):
        name = self._unicodify(name)

        if self.naming_pattern:
            cache_result = False

        cached = name_parser_cache.get(name)
        if cached:
            return cached

        # break it into parts if there are any (dirname, file name, extension)
        dir_name, file_name = ek(os.path.split, name)

        if self.file_name:
            base_file_name = remove_extension(file_name)
        else:
            base_file_name = file_name

        # set up a result to use
        final_result = ParseResult(name)

        # try parsing the file name
        file_name_result = self._parse_string(base_file_name)

        # use only the direct parent dir
        dir_name = os.path.basename(dir_name)

        # parse the dirname for extra info if needed
        dir_name_result = self._parse_string(dir_name)

        # build the ParseResult object
        final_result.air_date = self._combine_results(file_name_result, dir_name_result, 'air_date')

        # anime absolute numbers
        final_result.ab_episode_numbers = self._combine_results(file_name_result, dir_name_result, 'ab_episode_numbers')

        # season and episode numbers
        final_result.season_number = self._combine_results(file_name_result, dir_name_result, 'season_number')
        final_result.episode_numbers = self._combine_results(file_name_result, dir_name_result, 'episode_numbers')

        # if the dirname has a release group/show name I believe it over the filename
        final_result.series_name = self._combine_results(dir_name_result, file_name_result, 'series_name')
        final_result.extra_info = self._combine_results(dir_name_result, file_name_result, 'extra_info')
        final_result.release_group = self._combine_results(dir_name_result, file_name_result, 'release_group')
        final_result.version = self._combine_results(dir_name_result, file_name_result, 'version')

        final_result.which_regex = []
        if final_result == file_name_result:
            final_result.which_regex = file_name_result.which_regex
        elif final_result == dir_name_result:
            final_result.which_regex = dir_name_result.which_regex
        else:
            if file_name_result:
                final_result.which_regex += file_name_result.which_regex
            if dir_name_result:
                final_result.which_regex += dir_name_result.which_regex

        final_result.show = self._combine_results(file_name_result, dir_name_result, 'show')
        final_result.quality = self._combine_results(file_name_result, dir_name_result, 'quality')

        if not final_result.show:
            raise InvalidShowException(
                "Unable to parse " + name.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))

        # if there's no useful info in it then raise an exception
        if final_result.season_number is None and not final_result.episode_numbers and final_result.air_date is None and not final_result.ab_episode_numbers and not final_result.series_name:
            raise InvalidNameException("Unable to parse " + name.encode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace'))

        if cache_result:
            name_parser_cache.add(name, final_result)

        logger.log(u"Parsed " + name + " into " + str(final_result).decode('utf-8', 'xmlcharrefreplace'), logger.DEBUG)
        return final_result
Esempio n. 7
0
    def parse(self, name, cache_result=True):
        name = self._unicodify(name)
        name = pre_cleanup_re.sub('', name)

        if self.naming_pattern:
            cache_result = False

        cached = name_parser_cache.get(name)
        if cached:
            return cached

        # break it into parts if there are any (dirname, file name, extension)
        dir_name, file_name = ek(os.path.split, name) if not self.use_guessit else ('', name)

        if self.file_name:
            base_file_name = remove_extension(file_name)
        else:
            base_file_name = file_name

        # set up a result to use
        final_result = ParseResult(name)

        # try parsing the file name
        file_name_result = self._parse_string(base_file_name)

        # use only the direct parent dir
        dir_name = ek(os.path.basename, dir_name)

        # parse the dirname for extra info if needed
        dir_name_result = self._parse_string(dir_name)

        final_result.guess = file_name_result.guess if file_name_result else None

        # build the ParseResult object
        final_result.air_date = self._combine_results(file_name_result, dir_name_result, 'air_date')

        # anime absolute numbers
        final_result.ab_episode_numbers = self._combine_results(file_name_result, dir_name_result, 'ab_episode_numbers')

        # season and episode numbers
        final_result.season_number = self._combine_results(file_name_result, dir_name_result, 'season_number')
        final_result.episode_numbers = self._combine_results(file_name_result, dir_name_result, 'episode_numbers')

        # if the dirname has a release group/show name I believe it over the filename
        final_result.series_name = self._combine_results(dir_name_result, file_name_result, 'series_name')
        final_result.extra_info = self._combine_results(dir_name_result, file_name_result, 'extra_info')
        final_result.release_group = self._combine_results(dir_name_result, file_name_result, 'release_group')
        final_result.version = self._combine_results(dir_name_result, file_name_result, 'version')
        final_result.proper_tags =  self._combine_results(dir_name_result, file_name_result, 'proper_tags')

        final_result.which_regex = []
        if final_result == file_name_result:
            final_result.which_regex = file_name_result.which_regex
        elif final_result == dir_name_result:
            final_result.which_regex = dir_name_result.which_regex
        else:
            if file_name_result:
                final_result.which_regex += file_name_result.which_regex
            if dir_name_result:
                final_result.which_regex += dir_name_result.which_regex

        final_result.show = self._combine_results(file_name_result, dir_name_result, 'show')
        final_result.quality = self._combine_results(file_name_result, dir_name_result, 'quality')

        self.assert_supported(final_result)

        if cache_result:
            name_parser_cache.add(name, final_result)

        logger.log('Parsed {0} into {1}'.format(name, str(final_result).decode('utf-8', 'xmlcharrefreplace')), logger.DEBUG)
        return final_result