Exemplo n.º 1
0
    def search_web(self):
        # Search an exact title:
        results = self.provider.search(self['type'], self['title'], self.get('year'), self.get('country'), limit=20, strict_search=True)
        #results = self.match_title(self['title'], results, exclude_beginning_match=True, exclude_ending_match=True)

        # If no results, explore exceptions:
        if not results or (self.get('year') is not None and not list(filter(lambda x: x['year'] == self.get('year'), results))):
            ## EXCEPTION 1: Movie may have been identified as a show because it contains "Episode" or "Part":
            if self['type'] == 'shows':
                # Form an aggregated title composed of "title", "episode" and "episode_title" matches results:
                title_agr = '%s %s %s' % (self['title'], self._matches['episodes'][0].group(), self.get('episode_title', ''))
                # Search new title (no exact match is required as concatenated attributes will already narrow results):
                results = self.provider.search('movies', title_agr, self.get('year'), limit=20, strict_search=True, strict_search_options=)
                # results = self.match_title(title_agr, results, strict_search=True, struexclude_ending_match=True)
                # Clean-up:
                if results:
                    self['type'] == 'movies'
                    self.remove_matches(['season', 'episodes', 'episode_title', 'air_date'])

            ## EXCEPTION 2: Movie may have a roman number (e.g. II, III, IV...), convert it to a regular number:
            if self['type'] == 'movies' and re.search(r'[\s](?P<number>%s)(?:[\s]|$)' % '|'.join(reversed(constants.get('video.numerals.roman')[2:])), self['title'], flags=re.I):
                title = utils.normalize(re.sub(r'[\s](?P<number>%s)(?:[\s]|$)' % '|'.join(reversed(constants.get('video.numerals.roman')[2:])), lambda m: ' %s ' % utils.to_int(m.group('number')), self['title'], flags=re.I))
                # Search newly formatted title (no exact match is required as concatenated attributes will narrow results):
                results = self.provider.search(self['type'], title, self.get('year'), self.get('country'), limit=20)

        # If still no results, refine search:
        if not results:
            # Search results:
            results = self.provider.search(self['type'], self['title'], self.get('year'), self.get('country'), limit=20)
            # results = self.match_title(self['title'], results, include_alternative_titles=True)
        return results
Exemplo n.º 2
0
def test_normalize():
    tests = [
        ('Alien³', 'Alien 3', {'repl': None, 'convert_numerals': True, 'convert_possessive': True, 'unidecode': True}),
        ('Grey\'s Anatomy', 'Greys Anatomy', {'repl': None, 'convert_numerals': True, 'convert_possessive': True, 'unidecode': True}),
    ]
    for i in tests:
        assert utils.normalize(i[0], **i[2]) == i[1].lower()