forked from LBRYCommunity/lbry-sdk
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"
|
DEFAULT_WALLET = "lbryum"
|
||||||
|
|
||||||
API_CONNECTION_STRING = "http://%s:%i/%s" % (API_INTERFACE, API_PORT, API_ADDRESS)
|
API_CONNECTION_STRING = "http://%s:%i/%s" % (API_INTERFACE, API_PORT, API_ADDRESS)
|
||||||
|
UI_ADDRESS = "http://" + API_INTERFACE + ":" + str(API_PORT)
|
||||||
|
|
||||||
PROTOCOL_PREFIX = "lbry"
|
PROTOCOL_PREFIX = "lbry"
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 30
|
DEFAULT_TIMEOUT = 30
|
|
@ -1,54 +1,61 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import xmlrpclib, sys
|
import sys
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
def render_video(path):
|
from jsonrpc.proxy import JSONRPCProxy
|
||||||
r = r'<center><video src="' + path + r'" controls autoplay width="960" height="720"></center>'
|
from lbrynet.conf import API_CONNECTION_STRING, UI_ADDRESS
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
class LBRYURIHandler(object):
|
||||||
if len(args) == 0:
|
def __init__(self):
|
||||||
args.append('lbry://wonderfullife')
|
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:
|
except:
|
||||||
daemon.is_running()
|
if self.started_daemon:
|
||||||
|
if self.start_timeout < 30:
|
||||||
if len(args) > 1:
|
sleep(1)
|
||||||
exit(1)
|
self.start_timeout += 1
|
||||||
|
self.check_status()
|
||||||
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)
|
|
||||||
else:
|
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:
|
else:
|
||||||
webbrowser.get('safari').open('http://lbry.io/get')
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1147,7 +1147,9 @@ class LBRYFileRender(resource.Resource):
|
||||||
isLeaf = False
|
isLeaf = False
|
||||||
|
|
||||||
def _render_path(self, path):
|
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):
|
def _delayed_render(self, request, results):
|
||||||
request.write(str(results))
|
request.write(str(results))
|
||||||
|
|
|
@ -4,7 +4,9 @@ import os
|
||||||
APP = [os.path.join('lbrynet', 'lbrynet_daemon', 'Apps', 'LBRYURIHandler.py')]
|
APP = [os.path.join('lbrynet', 'lbrynet_daemon', 'Apps', 'LBRYURIHandler.py')]
|
||||||
DATA_FILES = []
|
DATA_FILES = []
|
||||||
OPTIONS = {'argv_emulation': True,
|
OPTIONS = {'argv_emulation': True,
|
||||||
|
'packages': ['lbrynet', 'jsonrpc'],
|
||||||
'plist': {
|
'plist': {
|
||||||
|
'LSUIElement': True,
|
||||||
'CFBundleURLTypes': [
|
'CFBundleURLTypes': [
|
||||||
{
|
{
|
||||||
'CFBundleURLTypes': 'LBRYURIHandler',
|
'CFBundleURLTypes': 'LBRYURIHandler',
|
||||||
|
|
Loading…
Reference in a new issue