예제 #1
0
    def _search(self, title, year=None, language='en'):
        """ Search the api for a show.

        :param title: the title to search for
        :type title: str
        :param year: the year (optional)
        :type year: int or None
        :param language: the language to search for
        :type language: str
        :return: the search result or None if not found
        :rtype : tvdb_api_v2.models.series_search_result.SeriesSearchResult or None
        """
        name = title
        if year:
            name += ' (' + text_type(year) + ')'
        log.info('Searching tvdb api for %s', name)
        # Make sure to convert it to native string before searching (to prevent unicode encoding error)
        search_results = self._client.search_series_by_name(s2n(name),
                                                            language=language)

        # Only return 1 result or None
        for search_result in search_results.data:
            if sanitize(search_result.series_name) == sanitize(name):
                return search_result
            elif search_result.aliases:
                # If no match, fallback to aliases (if aliases are available)
                for alias in search_result.aliases:
                    if sanitize(alias) == sanitize(name):
                        return search_result
            else:
                continue

        return None
예제 #2
0
 def skip_movie(self, wanted_item_index, title, year):
     if not wanted_item_index:
         raise cherrypy.HTTPError(400, 'No wanted_item index supplied')
     if not title:
         raise cherrypy.HTTPError(400, 'No title supplied')
     movie = title
     if year:
         movie += ' (' + year + ')'
     # Check if already skipped
     movie_sanitized = sanitize(movie)
     for x in autosubliminal.SKIPMOVIE:
         if movie_sanitized == sanitize(x):
             send_websocket_notification('Already skipped movie %s.' %
                                         movie)
             redirect('/home')
     # Skip movie
     if subchecker.skip_movie(wanted_item_index):
         config.write_config_property('skipmovie', movie, '00')
         config.apply_skipmovie()
         send_websocket_notification('Skipped movie %s.' % movie)
     else:
         send_websocket_notification(
             'Could not skip movie! Please check the log file!',
             type='error')
     redirect('/home')
예제 #3
0
    def _search(self, title, year=None, language='en'):
        """ Search the api for a show.

        :param title: the title to search for
        :type title: str
        :param year: the year (optional)
        :type year: int or None
        :param language: the language to search for
        :type language: str
        :return: the search result or None if not found
        :rtype : tvdb_api_v2.models.series_search_result.SeriesSearchResult or None
        """
        name = title
        if year:
            name += ' (' + text_type(year) + ')'
        log.info('Searching tvdb api for %s', name)
        # Make sure to convert it to native string before searching (to prevent unicode encoding error)
        search_results = self._client.search_series_by_name(s2n(name), language=language)

        # Only return 1 result or None
        for search_result in search_results.data:
            if sanitize(search_result.series_name) == sanitize(name):
                return search_result
            elif search_result.aliases:
                # If no match, fallback to aliases (if aliases are available)
                for alias in search_result.aliases:
                    if sanitize(alias) == sanitize(name):
                        return search_result
            else:
                continue

        return None
예제 #4
0
def skip_movie(title, year):
    """Check if a movie should be skipped."""
    movie = title
    if year:
        movie += ' (' + text_type(year) + ')'
    movie_sanitized = sanitize(movie)
    for x in autosubliminal.SKIPMOVIE:
        if movie_sanitized == sanitize(x):
            log.debug('Found match in skipmovie, skipping movie %s', movie)
            return True
예제 #5
0
def skip_movie(title, year):
    """Check if a movie should be skipped."""
    movie = title
    if year:
        movie += ' (' + text_type(year) + ')'
    movie_sanitized = sanitize(movie)
    for x in autosubliminal.SKIPMOVIE:
        if movie_sanitized == sanitize(x):
            log.debug('Found match in skipmovie, skipping movie %s', movie)
            return True
예제 #6
0
def get_addic7ed_show_name_mapping(show_name):
    """
    Get the addic7ed show name mapping for a show.

    :param show_name: the show name to get the addic7ed id for
    :return: the addic7ed show id or None
    :rtype: int | None
    """
    show_name_sanitized = sanitize(show_name)
    for x in autosubliminal.ADDIC7EDSHOWNAMEMAPPING:
        if show_name_sanitized == sanitize(x):
            log.debug('Found match in addic7edshownamemapping for %s', show_name)
            return int(autosubliminal.ADDIC7EDSHOWNAMEMAPPING[x])
예제 #7
0
def skip_show(show_name, season):
    """Check if a show should be skipped."""
    show_name_sanitized = sanitize(show_name)
    for x in autosubliminal.SKIPSHOW:
        if show_name_sanitized == sanitize(x):
            log.debug('Found match in skipshow for %s', show_name)
            for s in autosubliminal.SKIPSHOW[x].split(','):
                if s == '00':
                    log.debug('Found all season match in skipshow, skipping all seasons for %s', show_name)
                    return True
                elif int(s) == int(season):
                    log.debug('Found season match in skipshow, skipping season %s for %s', season, show_name)
                    return True
예제 #8
0
def get_alternative_show_name_mapping(show_name):
    """
    Get the list of alternative show names for a show.

    :param show_name: the show name to get the alternatives for
    :return: a list of alternative show names or None
    :rtype: list | None
    """
    show_name_sanitized = sanitize(show_name)
    for x in autosubliminal.ALTERNATIVESHOWNAMEMAPPING:
        if show_name_sanitized == sanitize(x):
            log.debug('Found match in alternativeshownamemapping for %s', show_name)
            alternatives = autosubliminal.ALTERNATIVESHOWNAMEMAPPING[x]
            return [sanitize(x) for x in alternatives.split(',')]  # Needs to return a list
예제 #9
0
def get_movie_name_mapping(title, year):
    """
    Get the imdb movie name mapping for a movie.

    :param title: the title of the movie
    :param year: the year of the movie
    :return: the imdb id of the movie or None
    :rtype: str | None
    """
    movie = title
    if year:
        movie += ' (' + text_type(year) + ')'
    movie_sanitized = sanitize(movie)
    for x in autosubliminal.MOVIENAMEMAPPING:
        if movie_sanitized == sanitize(x):
            log.debug('Found match in movienamemapping for %s', movie)
            return autosubliminal.MOVIENAMEMAPPING[x]
예제 #10
0
def skip_show(show_name, season):
    """Check if a show should be skipped."""
    show_name_sanitized = sanitize(show_name)
    for x in autosubliminal.SKIPSHOW:
        if show_name_sanitized == sanitize(x):
            log.debug('Found match in skipshow for %s', show_name)
            for s in autosubliminal.SKIPSHOW[x].split(','):
                if s == '00':
                    log.debug(
                        'Found all season match in skipshow, skipping all seasons for %s',
                        show_name)
                    return True
                elif int(s) == int(season):
                    log.debug(
                        'Found season match in skipshow, skipping season %s for %s',
                        season, show_name)
                    return True
예제 #11
0
    def skip_show(self, wanted_item_index, title, season=None):
        if not season:
            return PageTemplate('/home/home-skipshow.mako').render(
                wanted_item_index=wanted_item_index, title=title)
        else:
            if not wanted_item_index:
                raise cherrypy.HTTPError(400, 'No wanted_item index supplied')
            if not title:
                raise cherrypy.HTTPError(400, 'No show supplied')
            # Check if season is a number to be sure
            if not season == '00':
                season = text_type(int(season))
            config_season = season
            # Check if already skipped
            title_sanitized = sanitize(title)
            for x in autosubliminal.SKIPSHOW:
                if title_sanitized == sanitize(x):
                    for s in autosubliminal.SKIPSHOW[x].split(','):
                        if s == season or s == '00':
                            send_websocket_notification(
                                'Already skipped show %s season %s.' %
                                (title, season))
                            redirect('/home')
                    # Not skipped yet, skip all or append season the seasons to skip
                    if season == '00':
                        config_season = '00'
                    else:
                        seasons = autosubliminal.SKIPSHOW[x].split(',')
                        seasons.append(season)
                        config_season = ','.join(sorted(seasons))
            # Skip show
            if subchecker.skip_show(wanted_item_index, season):
                config.write_config_property('skipshow', title, config_season)
                config.apply_skipshow()
                if season == '00':
                    send_websocket_notification(
                        'Skipped show %s all seasons.' % title)
                else:
                    send_websocket_notification('Skipped show %s season %s.' %
                                                (title, season))
            else:
                send_websocket_notification(
                    'Could not skip show! Please check the log file!',
                    type='error')

            redirect('/home')
예제 #12
0
def get_alternative_movie_name_mapping(title, year):
    """
    Get the list of alternative movie titles (without year).

    :param title: the title of the movie
    :param year: the year of the movie
    :return: a list of alternative titles (without year) or None
    :rtype: list | None
    """
    movie = title
    if year:
        movie += ' (' + text_type(year) + ')'
    movie_sanitized = sanitize(movie)
    for x in autosubliminal.ALTERNATIVEMOVIENAMEMAPPING:
        if movie_sanitized == sanitize(x):
            log.debug('Found match in alternativemovienamemapping for %s', movie)
            alternatives = autosubliminal.ALTERNATIVEMOVIENAMEMAPPING[x]
            return [sanitize(x) for x in alternatives.split(',')]  # Needs to return a list
예제 #13
0
    def sanitize_imdb_title(string_value, ignore_characters=None):
        # Remove (I), (II), ... from imdb titles (this is added when there are multiple titles with the same name)
        # Example response from imdb: see http://www.imdb.com/find?q=Aftermath&s=tt&mx=20
        string_value = re.sub('^(.+)(\(\w+\))$', r'\1', string_value)

        # Sanitize on ascii level (replaces à by a)
        string_value = unidecode(string_value)

        # Return sanitized title
        return sanitize(string_value, ignore_characters)
예제 #14
0
    def sanitize_imdb_title(string_value, ignore_characters=None):
        # Remove (I), (II), ... from imdb titles (this is added when there are multiple titles with the same name)
        # Example response from imdb: see http://www.imdb.com/find?q=Aftermath&s=tt&mx=20
        string_value = re.sub('^(.+)(\(\w+\))$', r'\1', string_value)

        # Sanitize on ascii level (replaces à by a)
        string_value = unidecode(string_value)

        # Return sanitized title
        return sanitize(string_value, ignore_characters)
예제 #15
0
    def skip_show(self, wanted_item_index, title, season=None):
        if not season:
            return PageTemplate('/home/home-skipshow.mako').render(wanted_item_index=wanted_item_index, title=title)
        else:
            if not wanted_item_index:
                raise cherrypy.HTTPError(400, 'No wanted_item index supplied')
            if not title:
                raise cherrypy.HTTPError(400, 'No show supplied')
            # Check if season is a number to be sure
            if not season == '00':
                season = text_type(int(season))
            config_season = season
            # Check if already skipped
            title_sanitized = sanitize(title)
            for x in autosubliminal.SKIPSHOW:
                if title_sanitized == sanitize(x):
                    for s in autosubliminal.SKIPSHOW[x].split(','):
                        if s == season or s == '00':
                            send_websocket_notification('Already skipped show %s season %s.' % (title, season))
                            redirect('/home')
                    # Not skipped yet, skip all or append season the seasons to skip
                    if season == '00':
                        config_season = '00'
                    else:
                        seasons = autosubliminal.SKIPSHOW[x].split(',')
                        seasons.append(season)
                        config_season = ','.join(sorted(seasons))
            # Skip show
            if subchecker.skip_show(wanted_item_index, season):
                config.write_config_property('skipshow', title, config_season)
                config.apply_skipshow()
                if season == '00':
                    send_websocket_notification('Skipped show %s all seasons.' % title)
                else:
                    send_websocket_notification('Skipped show %s season %s.' % (title, season))
            else:
                send_websocket_notification('Could not skip show! Please check the log file!', type='error')

            redirect('/home')
예제 #16
0
 def skip_movie(self, wanted_item_index, title, year):
     if not wanted_item_index:
         raise cherrypy.HTTPError(400, 'No wanted_item index supplied')
     if not title:
         raise cherrypy.HTTPError(400, 'No title supplied')
     movie = title
     if year:
         movie += ' (' + year + ')'
     # Check if already skipped
     movie_sanitized = sanitize(movie)
     for x in autosubliminal.SKIPMOVIE:
         if movie_sanitized == sanitize(x):
             send_websocket_notification('Already skipped movie %s.' % movie)
             redirect('/home')
     # Skip movie
     if subchecker.skip_movie(wanted_item_index):
         config.write_config_property('skipmovie', movie, '00')
         config.apply_skipmovie()
         send_websocket_notification('Skipped movie %s.' % movie)
     else:
         send_websocket_notification('Could not skip movie! Please check the log file!', type='error')
     redirect('/home')
예제 #17
0
def test_sanitize():
    assert sanitize(None) is None
    assert sanitize('(Mr.-Robot! / :),') == 'mr robot'