update uri handler
-use new jsonrpc daemon, start app if it isn’t running on first lbry:// request
This commit is contained in:
parent
a55e3d8578
commit
13acbfb64f
4 changed files with 52 additions and 39 deletions
|
@ -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
|
|
@ -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'<center><video src="' + path + r'" controls autoplay width="960" height="720"></center>'
|
||||
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 = "<body>" + json.dumps(r) + "</body>"
|
||||
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__":
|
||||
|
|
|
@ -1147,7 +1147,9 @@ class LBRYFileRender(resource.Resource):
|
|||
isLeaf = False
|
||||
|
||||
def _render_path(self, path):
|
||||
return r'<html><center><video src="' + path + r'" controls autoplay width="960" height="720"></center></html>'
|
||||
extension = os.path.splitext(path)[1]
|
||||
if extension in ['mp4', 'flv', 'mov', 'ogv']:
|
||||
return r'<html><center><video src="' + path + r'" controls autoplay width="960" height="720"></center></html>'
|
||||
|
||||
def _delayed_render(self, request, results):
|
||||
request.write(str(results))
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue