Esempio n. 1
0
 def _results_with_valid_urls(self, results: list):
     return results_with_valid_urls(results, self.nefarious_settings)
Esempio n. 2
0
def cross_seed_task(torrent_hash: str):
    # TODO - this isn't used and is a work in progress

    nefarious_settings = NefariousSettings.get()
    transmission_client = get_transmission_client(nefarious_settings)

    try:
        torrent = transmission_client.get_torrent(torrent_hash)
    except KeyError:
        logging.warning('{} no longer in transmission'.format(torrent_hash))
        return

    logging.info('Attempting cross seed for {}'.format(torrent.name))

    valid_results = []

    search = SearchTorrents(MEDIA_TYPE_MOVIE,
                            torrent.name,
                            search_seed_only=True)
    if search.ok:
        for result in search.results:
            transmission_client.add_torrent()
            normalized_title = regex.sub(ParserBase.word_delimiter_regex, ' ',
                                         torrent.name)
            if result['Title'].lower() in [
                    torrent.name.lower(),
                    normalized_title.lower()
            ]:
                # TODO - the sizes won't match due to the inaccuracy of the scraping values
                # add paused torrent and verify the sizes match
                valid_results.append(result)

    # trace the "torrent url" (sometimes magnet) in each valid result
    valid_results = results_with_valid_urls(valid_results, nefarious_settings)

    logging.info(valid_results)

    seed_only_indexers = get_seed_only_indexers(nefarious_settings)

    if valid_results:
        for seed_only_indexer in seed_only_indexers:

            logging.info(
                'Looking for cross seed results for indexer {}'.format(
                    seed_only_indexer))

            # filter results to this seed-only indexer
            indexer_results = [
                r for r in valid_results if r['TrackerId'] == seed_only_indexer
            ]
            if not indexer_results:
                logging.info(
                    'Indexer {} does not have any results for {}'.format(
                        seed_only_indexer, torrent.name))
                continue

            # get the "best" result
            best_result = get_best_torrent_result(indexer_results)

            logging.info('Cross seeding {} for indexer {}'.format(
                best_result['Title'], best_result['Tracker']))

            # add a new key to our result object with the traced torrent url
            best_result[
                'torrent_url'] = best_result['MagnetUri'] or trace_torrent_url(
                    swap_jackett_host(best_result['Link'], nefarious_settings))

            # add to transmission
            transmission_session = transmission_client.session_stats()
            torrent = transmission_client.add_torrent(
                best_result['torrent_url'],
                paused=True,  # TODO
                # TODO
                #download_dir=self._get_download_dir(transmission_session)
            )
    else:
        logging.info('No valid cross seeding options for {}'.format(
            torrent.name))