コード例 #1
0
 def test_pct(self):
     s1 = '(and:!((field:!(fetched,equals,!t)),(field:!(url,contains,%))))'
     self.assertEquals(
         loads(s1),
         {
             'and': [
                 {'field': ['fetched', 'equals', True]},
                 {'field': ['url', 'contains', '%']}
             ]
         }
     )
     self.assertEquals(loads("""!(url,contains,'!'%!'!!!!')"""),
                       ['url', 'contains', "'%'!!"])
コード例 #2
0
ファイル: db_util.py プロジェクト: deepblueparticle/efetch
    def get_filters(self, a_parameter, g_parameter, timefield, must=[], must_not=[]):
        """Returns the query from _a RISON"""
        a_parsed = rison.loads(a_parameter)
        g_parsed = rison.loads(g_parameter)

        if 'time' in g_parsed:
            # pprint.pprint(g_parsed)
            must.append({'range': {timefield: {
                'gte': g_parsed['time']['from'],
                'lte': g_parsed['time']['to']
            }}})

        # pprint.PrettyPrinter(indent=4).pprint(a_parsed)
        if 'filters' in a_parsed:
            for filter in a_parsed['filters']:
                if not filter['meta']['negate']:
                    must.append({'query': filter['query']})  # , '$state': filter['$state']})
                else:
                    must_not.append({'query': filter['query']})  # , '$state': filter['$state']})

        query = {
            'query': {
                'filtered': {
                    'query': {
                        'query_string': {
                            'query': '*',
                            'analyze_wildcard': True
                        }
                    }
                }
            }
        }

        if 'query' in a_parsed:
            must.append({'query': a_parsed['query']})

        if not must and not must_not:
            return query

        query['query']['filtered']['filter'] = {'bool': {}}

        if must:
            # if len(must) == 1:
            #    must = must[0]
            query['query']['filtered']['filter']['bool']['must'] = must
        if must_not:
            # if len(must_not) == 1:
            #    must_not = must_not[0]
            query['query']['filtered']['filter']['bool']['must_not'] = must_not

        return query
コード例 #3
0
ファイル: web.py プロジェクト: nomnomtastic/nzbhydra
def get_details(guid):
    # GUID is not the GUID-item from the RSS but the newznab GUID which in our case is just a rison string 
    d = rison.loads(urlparse.unquote(guid))
    details_link = get_details_link(d["indexer"], d["indexerguid"])
    if details_link:
        return redirect(details_link)
    return "Unable to find details", 500
コード例 #4
0
def get_details(guid):
    # GUID is not the GUID-item from the RSS but the newznab GUID which in our case is just a rison string 
    d = rison.loads(urlparse.unquote(guid))
    details_link = get_details_link(d["indexer"], d["guid"])
    if details_link:
        return redirect(details_link)
    return "Unable to find details", 500
コード例 #5
0
ファイル: web.py プロジェクト: w33ty/nzbhydra
def api(args):
    logger.debug(request.url)
    logger.debug("API request: %s" % args)
    # Map newznab api parameters to internal
    args["category"] = args["cat"]
    args["episode"] = args["ep"]

    if args["q"] is not None and args["q"] != "":
        args["query"] = args[
            "q"]  # Because internally we work with "query" instead of "q"
    if config.settings.main.apikey and ("apikey" not in args or args["apikey"]
                                        != config.settings.main.apikey):
        logger.error("Tried API access with invalid or missing API key")
        raise Unauthorized("API key not provided or invalid")
    elif args["t"] in ("search", "tvsearch", "movie", "book"):
        return api_search(args)
    elif args["t"] == "get":
        args = rison.loads(args["id"])
        logger.info("API request to download %s from %s" %
                    (args["title"], args["indexer"]))
        return extract_nzb_infos_and_return_response(args["indexer"],
                                                     args["indexerguid"],
                                                     args["title"],
                                                     args["searchid"])
    elif args["t"] == "caps":
        xml = render_template("caps.html")
        return Response(xml, mimetype="text/xml")
    else:
        logger.error(
            "Unknown API request. Supported functions: search, tvsearch, movie, get, caps"
        )
        return "Unknown API request. Supported functions: search, tvsearch, movie, get, caps", 500
コード例 #6
0
ファイル: web.py プロジェクト: mehdroid/nzbhydra
def internalapi_addnzb(args):
    logger.debug("Add NZB request with args %s" % args)
    guids = json.loads(args["guids"])
    if downloaderSettings.downloader.isSetting(config.DownloaderSelection.nzbget):
        downloader = Nzbget()
    elif downloaderSettings.downloader.isSetting(config.DownloaderSelection.sabnzbd):
        downloader = Sabnzbd()
    else:
        logger.error("Adding an NZB without set downloader should not be possible")
        return jsonify({"success": False})
    added = 0
    for guid in guids:
        guid = dict(urllib.parse.parse_qsl(urllib.parse.urlparse(guid).query))["id"]
        guid = rison.loads(guid)
        if downloaderSettings.nzbAddingType.isSetting(config.NzbAddingTypeSelection.link):  # We send a link to the downloader. The link is either to us (where it gets answered or redirected, thet later getnzb will be called) or directly to the indexer
            add_success = downloader.add_link(guid, guid["title"], args["category"])

        else:  # We download an NZB send it to the downloader
            nzbdownloadresult = download_nzb_and_log(guid["indexer"], guid["guid"], guid["title"], guid["searchid"])
            if nzbdownloadresult is not None:
                add_success = downloader.add_nzb(nzbdownloadresult.content, guid["title"], args["category"])
            else:
                add_success = False
        if add_success:
            added += 1

    if added:
        return jsonify({"success": True, "added": added, "of": len(guids)})
    else:
        return jsonify({"success": False})
コード例 #7
0
ファイル: db_util.py プロジェクト: deepblueparticle/efetch
 def get_theme(self, a_parameter):
     """Returns the theme from _a RISON"""
     try:
         a_parsed = rison.loads(a_parameter)
     except Exception, err:
         logging.error('Failed to parse rison: ' + a_parameter)
         traceback.print_exc()
         return 'gray'
コード例 #8
0
ファイル: db_util.py プロジェクト: deepblueparticle/efetch
 def get_query(self, a_parameter):
     """Returns the query from _a RISON"""
     try:
         a_parsed = rison.loads(a_parameter)
     except Exception, err:
         logging.error('Failed to parse rison: ' + a_parameter)
         traceback.print_exc()
         return {'query_string': {'analyze_wildcard': True, 'query': '*'}}
コード例 #9
0
 def test_dict(self):
     self.assertEqual(loads('()'), {})
     self.assertEqual(loads('(a:0,b:1)'), {
         'a': 0,
         'b': 1
     })
     self.assertEqual(loads("(a:0,b:foo,c:'23skidoo')"), {
         'a': 0,
         'c': '23skidoo',
         'b': 'foo'
     })
     self.assertEqual(loads('(id:!n,type:/common/document)'), {
         'type': '/common/document',
         'id': None
     })
     self.assertEqual(loads("(a:0)"), {
         'a': 0
     })
コード例 #10
0
ファイル: web.py プロジェクト: w33ty/nzbhydra
def getnzb(args):
    logger.debug("Get NZB request with args %s" % args)
    args = rison.loads(args["id"])
    logger.info("API request to download %s from %s" %
                (args["title"], args["indexer"]))
    return extract_nzb_infos_and_return_response(args["indexer"],
                                                 args["indexerguid"],
                                                 args["title"],
                                                 args["searchid"])
コード例 #11
0
 def test_dict(self):
     self.assertEqual(loads('()'), {})
     self.assertEqual(loads('(a:0,b:1)'), {
         'a': 0,
         'b': 1
     })
     self.assertEqual(loads("(a:0,b:foo,c:'23skidoo')"), {
         'a': 0,
         'c': '23skidoo',
         'b': 'foo'
     })
     self.assertEqual(loads('(id:!n,type:/common/document)'), {
         'type': '/common/document',
         'id': None
     })
     self.assertEqual(loads("(a:0)"), {
         'a': 0
     })
コード例 #12
0
ファイル: web.py プロジェクト: mehdroid/nzbhydra
def api(args):
    logger.debug(request.url)
    logger.debug("API request: %s" % args)
    # Map newznab api parameters to internal
    args["category"] = args["cat"]
    args["episode"] = args["ep"]

    if args["q"] is not None and args["q"] != "":
        args["query"] = args["q"]  # Because internally we work with "query" instead of "q"
    if mainSettings.apikey.get_with_default(None) and ("apikey" not in args or args["apikey"] != mainSettings.apikey.get()):
        logger.error("Tried API access with invalid or missing API key")
        raise Unauthorized("API key not provided or invalid")
    elif args["t"] in ("search", "tvsearch", "movie"):
        search_request = SearchRequest(category=args["cat"], offset=args["offset"], limit=args["limit"], query=args["q"])
        if args["t"] == "search":
            search_request.type = "general"
        elif args["t"] == "tvsearch":
            search_request.type = "tv"
            identifier_key = "rid" if args["rid"] else "tvdbid" if args["tvdbid"] else None
            if identifier_key is not None:
                identifier_value = args[identifier_key]
                search_request.identifier_key = identifier_key
                search_request.identifier_value = identifier_value
            search_request.season = int(args["season"]) if args["season"] else None
            search_request.episode = int(args["episode"]) if args["episode"] else None
        elif args["t"] == "movie":
            search_request.type = "movie"
            search_request.identifier_key = "imdbid" if args["imdbid"] is not None else None
            search_request.identifier_value = args["imdbid"] if args["imdbid"] is not None else None
        result = search.search(False, search_request)
        results = process_for_external_api(result)
        content = render_search_results_for_api(results, result["total"], result["offset"])
        response = make_response(content)
        response.headers["Content-Type"] = "application/xml"
        return content
    elif args["t"] == "get":
        args = rison.loads(urllib.parse.unquote(args["id"]))
        return extract_nzb_infos_and_return_response(args["indexer"], args["guid"], args["title"], args["searchid"])
    elif args["t"] == "caps":
        xml = render_template("caps.html")
        return Response(xml, mimetype="text/xml")
    else:
        pprint(request)
        return "Unknown API request. Supported functions: search, tvsearch, movie, get, caps", 500
コード例 #13
0
ファイル: web.py プロジェクト: nomnomtastic/nzbhydra
def api(args):
    logger.debug(request.url)
    logger.debug("API request: %s" % args)
    # Map newznab api parameters to internal
    args["category"] = args["cat"]
    args["episode"] = args["ep"]

    if args["q"] is not None and args["q"] != "":
        args["query"] = args["q"]  # Because internally we work with "query" instead of "q"
    if config.settings.main.apikey and ("apikey" not in args or args["apikey"] != config.settings.main.apikey):
        logger.error("Tried API access with invalid or missing API key")
        raise Unauthorized("API key not provided or invalid")
    elif args["t"] in ("search", "tvsearch", "movie", "book"):
        return api_search(args)
    elif args["t"] == "get":
        args = rison.loads(args["id"])
        logger.info("API request to download %s from %s" % (args["title"], args["indexer"]))
        return extract_nzb_infos_and_return_response(args["indexer"], args["indexerguid"], args["title"], args["searchid"])
    elif args["t"] == "caps":
        xml = render_template("caps.html")
        return Response(xml, mimetype="text/xml")
    else:
        logger.error("Unknown API request. Supported functions: search, tvsearch, movie, get, caps")
        return "Unknown API request. Supported functions: search, tvsearch, movie, get, caps", 500
コード例 #14
0
 def test_string(self):
     self.assertEqual(loads("''"), '')
     self.assertEqual(loads('G.'), 'G.')
     self.assertEqual(loads('a'), 'a')
     self.assertEqual(loads("'0a'"), '0a')
     self.assertEqual(loads("'abc def'"), 'abc def')
     self.assertEqual(loads("'-h'"), '-h')
     self.assertEqual(loads('a-z'), 'a-z')
     self.assertEqual(loads("'wow!!'"), 'wow!')
     self.assertEqual(loads('domain.com'), 'domain.com')
     self.assertEqual(loads("'*****@*****.**'"), '*****@*****.**')
     self.assertEqual(loads("'US $10'"), 'US $10')
     self.assertEqual(loads("'can!'t'"), "can't")
コード例 #15
0
 def test_string(self):
     self.assertEqual(loads("''"), '')
     self.assertEqual(loads('G.'), 'G.')
     self.assertEqual(loads('a'), 'a')
     self.assertEqual(loads("'0a'"), '0a')
     self.assertEqual(loads("'abc def'"), 'abc def')
     self.assertEqual(loads("'-h'"), '-h')
     self.assertEqual(loads('a-z'), 'a-z')
     self.assertEqual(loads("'wow!!'"), 'wow!')
     self.assertEqual(loads('domain.com'), 'domain.com')
     self.assertEqual(loads("'*****@*****.**'"), '*****@*****.**')
     self.assertEqual(loads("'US $10'"), 'US $10')
     self.assertEqual(loads("'can!'t'"), "can't")
コード例 #16
0
 def test_list(self):
     self.assertEqual(loads('!(1,2,3)'), [1, 2, 3])
     self.assertEqual(loads('!()'), [])
     self.assertEqual(loads("!(!t,!f,!n,'')"), [True, False, None, ''])
コード例 #17
0
 def test_number(self):
     self.assertEqual(loads('0'), 0)
     self.assertEqual(loads('1.5'), 1.5)
     self.assertEqual(loads('-3'), -3)
     self.assertEqual(loads('1e30'), 1e+30)
     self.assertEqual(loads('1e-30'), 1.0000000000000001e-30)
コード例 #18
0
 def test_bool(self):
     self.assertEqual(loads('!t'), True)
     self.assertEqual(loads('!f'), False)
コード例 #19
0
 def test_none(self):
     self.assertEqual(loads('!n'), None)
コード例 #20
0
ファイル: web.py プロジェクト: nomnomtastic/nzbhydra
def getnzb(args):
    logger.debug("Get NZB request with args %s" % args)
    args = rison.loads(args["id"])
    logger.info("API request to download %s from %s" % (args["title"], args["indexer"]))
    return extract_nzb_infos_and_return_response(args["indexer"], args["indexerguid"], args["title"], args["searchid"])
コード例 #21
0
 def test_bool(self):
     self.assertEqual(loads('!t'), True)
     self.assertEqual(loads('!f'), False)
コード例 #22
0
 def test_none(self):
     self.assertEqual(loads('!n'), None)
コード例 #23
0
 def test_list(self):
     self.assertEqual(loads('!(1,2,3)'), [1, 2, 3])
     self.assertEqual(loads('!()'), [])
     self.assertEqual(loads("!(!t,!f,!n,'')"), [True, False, None, ''])
コード例 #24
0
 def test_number(self):
     self.assertEqual(loads('0'), 0)
     self.assertEqual(loads('1.5'), 1.5)
     self.assertEqual(loads('-3'), -3)
     self.assertEqual(loads('1e30'), 1e+30)
     self.assertEqual(loads('1e-30'), 1.0000000000000001e-30)