示例#1
0
def rss_sync(movies):
    ''' Gets latests RSS feed from all indexers
    movies (list): dicts of movies to look for

    Gets latest rss feed from all supported indexers.

    Looks through rss for anything that matches a movie in 'movies'

    Only stores new results. If you need to update scores or old results
        force a backlog search.

    Finally stores results in SEARCHRESULTS

    Returns bool
    '''
    logging.info('Syncing indexer RSS feeds.')

    newznab_results = []
    torrent_results = []

    proxy.create()

    if core.CONFIG['Downloader']['Sources']['usenetenabled']:
        newznab_results = nn.get_rss()
    if core.CONFIG['Downloader']['Sources']['torrentenabled']:
        torrent_results = torrent.get_rss()

    proxy.destroy()

    for movie in movies:
        imdbid = movie['imdbid']
        title = movie['title']
        year = movie['year']
        english_title = movie.get('english_title')

        logging.info('Parsing RSS for {} {}'.format(title, year))

        nn_found = [i for i in newznab_results if i['imdbid'] == imdbid]

        tor_found = []
        for i in torrent_results:
            if _match_torrent_name(title, year, i['title']):
                tor_found.append(i)
            elif english_title and _match_torrent_name(english_title, year,
                                                       i['title']):
                tor_found.append(i)
        for idx, result in enumerate(tor_found):
            result['imdbid'] = imdbid
            tor_found[idx] = result

        results = nn_found + tor_found

        if not results:
            logging.info('Nothing found in RSS for {} {}'.format(title, year))
            continue

        # Ignore results we've already stored
        old_results = core.sql.get_search_results(imdbid, rejected=True)
        new_results = []
        for res in results:
            guid = res['guid']
            if all(guid != i['guid'] for i in old_results):
                new_results.append(res)
            else:
                continue

        logging.info('Found {} new results for {} {}.'.format(
            len(new_results), title, year))

        # Get source media and resolution
        for idx, result in enumerate(new_results):
            logging.debug('Parse {}'.format(result['title']))
            new_results[idx]['ptn'] = PTN.parse(result['title'])
            new_results[idx]['resolution'] = get_source(
                new_results[idx]['ptn'])

        scored_results = searchresults.score(new_results, imdbid=imdbid)

        if len(scored_results) == 0:
            logging.info('No acceptable results found for {}'.format(imdbid))
            continue

        if not store_results(scored_results, imdbid):
            return False

        if not Manage.movie_status(imdbid):
            return False

    return True
示例#2
0
def search(movie):
    ''' Executes backlog search for required movies
    movie (dict): movie to run search for

    Gets new search results from newznab providers.
    Pulls existing search results and updates new data with old. This way the
        found_date doesn't change and scores can be updated if the quality profile
        was modified since last search.

    Sends ALL results to searchresults.score() to be (re-)scored and filtered.

    Checks if guid matches entries in MARKEDRESULTS and
        sets status if found.
default status Available.

    Finally stores results in SEARCHRESULTS

    Returns Bool if movie is found.
    '''

    imdbid = movie['imdbid']
    title = movie['title']
    year = movie['year']
    quality = movie['quality']
    english_title = movie.get('english_title', '')
    language = movie.get('download_language', '')

    logging.info('Performing backlog search for {} {}.'.format(title, year))
    proxy.create()

    results = []

    if core.CONFIG['Downloader']['Sources']['usenetenabled']:
        for i in nn.search_all(imdbid):
            results.append(i)
    if core.CONFIG['Downloader']['Sources']['torrentenabled']:
        if title != english_title:
            for i in torrent.search_all(imdbid, title, year):
                results.append(i)
        if english_title and language:
            for i in torrent.search_all(imdbid, english_title, year,
                                        title != english_title):
                results.append(i)

    proxy.destroy()

    old_results = core.sql.get_search_results(imdbid, quality)

    for old in old_results:
        if old['type'] == 'import':
            results.append(old)

    active_old_results = remove_inactive(old_results)

    # update results with old info if guids match
    for idx, result in enumerate(results):
        for old in active_old_results:
            if old['guid'] == result['guid']:
                if 'seeders' in result:
                    old['seeders'] = result['seeders']
                if 'leechers' in result:
                    old['leechers'] = result['leechers']
                result.update(old)
                results[idx] = result

    for idx, result in enumerate(results):
        logging.debug('Parse {}'.format(result['title']))
        results[idx]['ptn'] = PTN.parse(result['title'])
        results[idx]['resolution'] = get_source(results[idx]['ptn'])

    scored_results = searchresults.score(results, imdbid=imdbid)

    # sets result status based off marked results table
    marked_results = core.sql.get_marked_results(imdbid)
    if marked_results:
        for result in scored_results:
            if result['guid'] in marked_results:
                result['status'] = marked_results[result['guid']]

    if not store_results(scored_results, imdbid, backlog=True):
        logging.error('Unable to store search results for {}'.format(imdbid))
        return False

    if not Manage.movie_status(imdbid):
        logging.error('Unable to update movie status for {}'.format(imdbid))
        return False

    if not core.sql.update('MOVIES', 'backlog', '1', 'imdbid', imdbid):
        logging.error(
            'Unable to flag backlog search as complete for {}'.format(imdbid))
        return False

    return True
示例#3
0
    def search(self, imdbid, title, year, quality):
        ''' Executes backlog search for required movies
        imdbid (str): imdb identification number
        title (str): movie title
        year (str/int): year of movie release
        quality (str): name of quality profile

        Gets new search results from newznab providers.
        Pulls existing search results and updates new data with old. This way the
            found_date doesn't change and scores can be updated if the quality profile
            was modified since last search.

        Sends ALL results to searchresults.Score.score() to be (re-)scored and filtered.

        Checks if guid matches entries in MARKEDRESULTS and
            sets status if found. Default status Available.

        Finally stores results in SEARCHRESULTS

        Returns Bool if movie is found.
        '''

        logging.info('Performing backlog search for {} {}.'.format(title, year))
        proxy.create()

        results = []

        if core.CONFIG['Downloader']['Sources']['usenetenabled']:
            for i in self.nn.search_all(imdbid):
                results.append(i)
        if core.CONFIG['Downloader']['Sources']['torrentenabled']:
            for i in self.torrent.search_all(imdbid, title, year):
                results.append(i)

        proxy.destroy()

        old_results = core.sql.get_search_results(imdbid, quality)

        for old in old_results:
            if old['type'] == 'import':
                results.append(old)

        active_old_results = self.remove_inactive(old_results)

        # update results with old info if guids match
        for idx, result in enumerate(results):
            for old in active_old_results:
                if old['guid'] == result['guid']:
                    result.update(old)
                    results[idx] = result

        for idx, result in enumerate(results):
            results[idx]['resolution'] = self.get_source(result)

        scored_results = self.score.score(results, imdbid=imdbid)

        # sets result status based off marked results table
        marked_results = core.sql.get_marked_results(imdbid)
        if marked_results:
            for result in scored_results:
                if result['guid'] in marked_results:
                    result['status'] = marked_results[result['guid']]

        if not self.store_results(scored_results, imdbid, backlog=True):
            logging.error('Unable to store search results for {}'.format(imdbid))
            return False

        if not core.manage.movie_status(imdbid):
            logging.error('Unable to update movie status for {}'.format(imdbid))
            return False

        if not core.sql.update('MOVIES', 'backlog', '1', 'imdbid', imdbid):
            logging.error('Unable to flag backlog search as complete for {}'.format(imdbid))
            return False

        return True