diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 227589def..f3903ae6a 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -36,6 +36,8 @@ APP_NAME = "LBRY" DEFAULT_WALLET = "lbryum" API_CONNECTION_STRING = "http://%s:%i/%s" % (API_INTERFACE, API_PORT, API_ADDRESS) +UI_ADDRESS = "http://" + API_INTERFACE + ":" + str(API_PORT) + PROTOCOL_PREFIX = "lbry" DEFAULT_TIMEOUT = 30 \ No newline at end of file diff --git a/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py b/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py index 1cc1bf3f8..1bc8c3399 100644 --- a/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py +++ b/lbrynet/lbrynet_daemon/Apps/LBRYURIHandler.py @@ -1,54 +1,61 @@ import os import json import webbrowser -import xmlrpclib, sys +import sys +from time import sleep -def render_video(path): - r = r'
' - return r +from jsonrpc.proxy import JSONRPCProxy +from lbrynet.conf import API_CONNECTION_STRING, UI_ADDRESS -def main(args): - if len(args) == 0: - args.append('lbry://wonderfullife') +class LBRYURIHandler(object): + def __init__(self): + self.started_daemon = False + self.start_timeout = 0 + self.daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING) - daemon = xmlrpclib.ServerProxy('http://localhost:7080/') + def check_status(self): + try: + self.daemon.is_running() - try: - daemon.is_running() - - if len(args) > 1: - exit(1) - - if args[0][7:] == 'lbry': - daemon.render_gui() - - elif args[0][7:] == 'settings': - r = daemon.get_settings() - html = "" + json.dumps(r) + "" - daemon.render_html(html) - - else: - r = daemon.get(args[0][7:]) - if r[0] == 200: - path = r[1]['path'] - if path[0] != '/': - path = '/' + path - - filename = os.path.basename(path) - extension = os.path.splitext(filename)[1] - - if extension in ['mp4', 'flv', 'mov']: - html = render_video(path) - daemon.render_html(html) + except: + if self.started_daemon: + if self.start_timeout < 30: + sleep(1) + self.start_timeout += 1 + self.check_status() else: - webbrowser.get('safari').open('file://' + str(path)) + exit(1) + else: + os.system("open /Applications/LBRY.app") + self.started_daemon = True + self.start_timeout += 1 + self.check_status() + def handle(self, lbry_name): + self.check_status() + + if lbry_name == "lbry": + webbrowser.get('safari').open(UI_ADDRESS) + else: + r = json.loads(self.daemon.get({'name': lbry_name})) + if r['code'] == 200: + path = r['result']['path'].encode('utf-8') + extension = os.path.splitext(path)[1] + if extension in ['mp4', 'flv', 'mov', 'ogv']: + webbrowser.get('safari').open(UI_ADDRESS + "/view?name=" + lbry_name) + else: + webbrowser.get('safari').open('file://' + path) else: webbrowser.get('safari').open('http://lbry.io/get') - except: - webbrowser.get('safari').open('http://lbry.io/get') + +def main(args): + if len(args) != 1: + args = ['lbry://lbry'] + + name = args[0][7:] + LBRYURIHandler().handle(lbry_name=name) if __name__ == "__main__": diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index 84ca4478b..b3e37a1f7 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -1147,7 +1147,9 @@ class LBRYFileRender(resource.Resource): isLeaf = False def _render_path(self, path): - return r'
' + extension = os.path.splitext(path)[1] + if extension in ['mp4', 'flv', 'mov', 'ogv']: + return r'
' def _delayed_render(self, request, results): request.write(str(results)) diff --git a/setup_uri_handler.py b/setup_uri_handler.py index 37a38826e..02f437e64 100644 --- a/setup_uri_handler.py +++ b/setup_uri_handler.py @@ -4,7 +4,9 @@ import os APP = [os.path.join('lbrynet', 'lbrynet_daemon', 'Apps', 'LBRYURIHandler.py')] DATA_FILES = [] OPTIONS = {'argv_emulation': True, + 'packages': ['lbrynet', 'jsonrpc'], 'plist': { + 'LSUIElement': True, 'CFBundleURLTypes': [ { 'CFBundleURLTypes': 'LBRYURIHandler',