예제 #1
0
def init_indexer_table_entry(indexer_name):
    try:
        Indexer.get(fn.lower(Indexer.name) == indexer_name.lower())
    except Indexer.DoesNotExist as e:
        logger.info("Unable to find indexer with name %s in database. Will add it" % indexer_name)
        indexer = Indexer().create(name=indexer_name)
        IndexerStatus.create_or_get(indexer=indexer, first_failure=None, latest_failure=None, disabled_until=None)
예제 #2
0
파일: search.py 프로젝트: dexdays/nzbhydra
def search_and_handle_db(dbsearch, indexers_and_search_requests):
    results_by_indexer = start_search_futures(indexers_and_search_requests)
    dbsearch.username = request.authorization.username if request.authorization is not None else None
    saveSearch(dbsearch)
    with databaseLock:
        with db.atomic():
            for indexer, result in results_by_indexer.items():
                if result.didsearch:
                    indexersearchentry = result.indexerSearchEntry
                    indexersearchentry.search = dbsearch
                    indexersearchentry.save()
                    result.indexerApiAccessEntry.username = request.authorization.username if request.authorization is not None else None
                    try:
                        result.indexerApiAccessEntry.indexer = Indexer.get(
                            Indexer.name == indexer)
                        result.indexerApiAccessEntry.save()
                        result.indexerStatus.save()
                    except Indexer.DoesNotExist:
                        logger.error(
                            "Tried to save indexer API access but no indexer with name %s was found in the database. Adding it now. This shouldn't've happened. If possible send a bug report with a full log."
                            % indexer)
                        Indexer().create(name=indexer)
                    except Exception as e:
                        logger.exception("Error saving IndexerApiAccessEntry")

    return {"results": results_by_indexer, "dbsearch": dbsearch}
예제 #3
0
def init_indexer_table_entry(indexer_name):
    try:
        Indexer.get(fn.lower(Indexer.name) == indexer_name.lower())
    except Indexer.DoesNotExist as e:
        logger.info(
            "Unable to find indexer with name %s in database. Will add it" %
            indexer_name)
        Indexer().create(name=indexer_name)
예제 #4
0
    def setUp(self):
        set_and_drop()

        self.indexercom = Indexer(name="indexer.com")
        self.indexercom.save()

        self.newznab1 = Bunch()
        self.newznab1.enabled = True
        self.newznab1.name = "indexer.com"
        self.newznab1.host = "https://indexer.com"
        self.newznab1.apikey = "apikeyindexer.com"
        self.newznab1.timeout = None
        self.newznab1.score = 0
        self.newznab1.search_ids = ["imdbid", "rid", "tvdbid"]
        self.n1 = NewzNab(self.newznab1)
예제 #5
0
    def testIndexersApiLimits(self):

        config.settings.searching.generate_queries = []
        self.newznab1.hitLimit = 3
        self.newznab1.hitLimitResetTime = None
        config.settings.indexers = [self.newznab1]
        read_indexers_from_config()
        search_request = SearchRequest()
        indexers = search.pick_indexers(search_request)
        self.assertEqual(1, len(indexers))
        dbsearch = Search(internal=True, time=arrow.utcnow().datetime)
        dbsearch.save()
        indexer = Indexer().get(name="newznab1")
        
        #Two accesses one and 12 hours ago
        IndexerApiAccess(indexer=indexer, search=dbsearch, time=arrow.utcnow().replace(hours=-1).datetime, type="search", url="", response_successful=True).save()
        IndexerApiAccess(indexer=indexer, search=dbsearch, time=arrow.utcnow().replace(hours=-12).datetime, type="search", url="", response_successful=True).save()
        self.assertEqual(1, len(search.pick_indexers(search_request)))

        #Another one 20 hours ago, so limit should be reached
        IndexerApiAccess(indexer=indexer, search=dbsearch, time=arrow.utcnow().replace(hours=-20).datetime, type="search", url="", response_successful=True).save()
        self.assertEqual(0, len(search.pick_indexers(search_request)))
예제 #6
0
 def testGetEntryById(self):
     Indexer(name="nzbindex").save()
     n = NzbIndex(getIndexerSettingByName("nzbindex"))
     with open("mock/nzbindex--details.html", encoding="latin-1") as f:
         xml = f.read()
     with responses.RequestsMock(
             assert_all_requests_are_fired=False) as rsps:
         url_re = re.compile(r'.*')
         rsps.add(responses.GET,
                  url_re,
                  body=xml,
                  status=200,
                  content_type='application/x-html')
         item = n.get_entry_by_id("aguid", "atitle")
         self.assertEqual("atitle", item.title)
         self.assertEqual(3816816, item.size)
         self.assertEqual(
             "alt.binaries.pwp | alt.binaries.usenetrevolution", item.group)
         self.assertEqual("[email protected] (Janusch)", item.poster)
         self.assertEqual("https://nzbindex.com/download/aguid/atitle.nzb",
                          item.link)
         self.assertEqual("https://nzbindex.com/release/aguid/atitle.nzb",
                          item.details_link)
예제 #7
0
    def testHandleIndexerFailureAndSuccess(self):
        Indexer(module="newznab", name="newznab1").save()
        indexer_model = Indexer.get(Indexer.name == "newznab1")
        with freeze_time("2015-09-20 14:00:00", tz_offset=-4):
            sm = search_module.SearchModule(self.newznab1)
            sm.handle_indexer_failure(indexer_model)
            # First error, so level 1
            self.assertEqual(1, indexer_model.status.get().level)
            now = arrow.utcnow()
            first_failure = arrow.get(arrow.get(indexer_model.status.get().first_failure))
            disabled_until = arrow.get(indexer_model.status.get().disabled_until)
            self.assertEqual(now, first_failure)
            self.assertEqual(now.replace(minutes=+sm.disable_periods[1]), disabled_until)

            sm.handle_indexer_failure()
            self.assertEqual(2, indexer_model.status.get().level)
            disabled_until = arrow.get(indexer_model.status.get().disabled_until)
            self.assertEqual(now.replace(minutes=+sm.disable_periods[2]), disabled_until)

            sm.handle_indexer_success()
            self.assertEqual(1, indexer_model.status.get().level)
            self.assertEqual(arrow.get(0), indexer_model.status.get().disabled_until)
            self.assertIsNone(indexer_model.status.get().reason)