From 82a54706232b031056f80c43d726dbed9a209a20 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Mon, 20 Aug 2018 21:37:18 +1200 Subject: [PATCH] Genius proxy working, with client_id auth --- mopidy_iris/core.py | 40 ++++++++++++++++++++++++++++++++++++---- mopidy_iris/handlers.py | 2 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/mopidy_iris/core.py b/mopidy_iris/core.py index 5010d40f..6b512dd4 100755 --- a/mopidy_iris/core.py +++ b/mopidy_iris/core.py @@ -976,14 +976,46 @@ class IrisCore(object): def get_lyrics(self, *args, **kwargs): callback = kwargs.get('callback', False) - data = kwargs.get('data', False) + request = kwargs.get('request', False) error = False + url = "" - url = 'https://genius.com'+data['path'] + try: + path = request.get_argument('path') + url = 'https://genius.com'+path + except Exception, e: + logger.error(e) + error = { + 'message': "Path not valid", + 'description': str(e) + } + try: + client_id = request.get_argument('client_id') + + if client_id not in self.connections: + error = { + 'message': 'Unauthorized request', + 'description': client_id+' not connected' + } + + except Exception, e: + logger.error(e) + error = { + 'message': "Unauthorized request", + 'description': "client_id missing" + } + + if error: + if (callback): + callback(False, error) + return + else: + return error + + http_request = tornado.httpclient.HTTPRequest(url) http_client = tornado.httpclient.HTTPClient() - request = tornado.httpclient.HTTPRequest(url) - response = http_client.fetch(request, callback=callback) + http_client.fetch(http_request, callback=callback) ## diff --git a/mopidy_iris/handlers.py b/mopidy_iris/handlers.py index 74fb47d8..11fffae0 100755 --- a/mopidy_iris/handlers.py +++ b/mopidy_iris/handlers.py @@ -164,7 +164,7 @@ class HttpHandler(tornado.web.RequestHandler): # make sure the method exists if hasattr(mem.iris, slug): - getattr(mem.iris, slug)(request=self.request, callback=lambda response, error=False: self.handle_result(id=id, method=slug, response=response, error=error)) + getattr(mem.iris, slug)(request=self, callback=lambda response, error=False: self.handle_result(id=id, method=slug, response=response, error=error)) else: self.handle_result(id=id, error={'code': 32601, 'message': "Method "+slug+" does not exist"})