예제 #1
0
    def guess_show(self, pass_=1):
        if pass_ == 1:
            match = self._matches.get('episodes')[0]
            # Determine episode type:
            self['air_date'] = datetime.strptime(match.group('air_date'), '%Y.%m.%d') if 'air_date' in match.groupdict() else None
            self['season'] = int(match.group('season')) if match.groupdict().get('season') is not None else None
            if match.groupdict().get('min_ep') is not None:
                min_ep = utils.to_int(match.group('min_ep'))
                max_ep = utils.to_int(match.group('max_ep')) if match.groupdict().get('max_ep') is not None else min_ep
                self['episodes'] = tuple([x for x in range(int(min_ep), int(max_ep) + 1)])
            else:
                self['episodes'] = ()

        elif pass_ == 2:
            # Determine episode's title:
            self.find_matches(self._mask, attributes=['video.episode_title'], index=0)

            # Detect yearly special episodes:
            if re.search(r'(?:{EPISODES}{EPISODE_TITLE}){YEAR}', self._mask) and 'special' in self['episode_title'].lower():
                self.remove_matches(['episode_title', 'year'])
                self.find_matches(self._mask, attributes=['video.episode_title'], index=0)

            # Get show's country information:
            if 'title' in self._matches:
                self.find_matches(self['title'], attributes=['video.country'], index=0)
                if 'country' in self._matches:
                    self['title'] = self['title'].replace(self._matches.get('country')[0].group(), '').strip()
                    self._mask = self._mask.replace('{TITLE}', '{TITLE}{COUNTRY}')
예제 #2
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
예제 #3
0
def test_to_int_french():
    assert utils.to_int('six') == 6
예제 #4
0
def test_to_int_english():
    assert utils.to_int('four') == 4
예제 #5
0
def test_to_int_roman():
    assert utils.to_int('IV') == 4
예제 #6
0
def test_to_int_subscript():
    assert utils.to_int('₂') == 2
예제 #7
0
def test_to_int_superscript():
    assert utils.to_int('³') == 3