2016-06-20 10:42:06 +02:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import webbrowser
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from time import sleep
|
|
|
|
from jsonrpc.proxy import JSONRPCProxy
|
|
|
|
|
|
|
|
API_CONNECTION_STRING = "http://localhost:5279/lbryapi"
|
|
|
|
UI_ADDRESS = "http://localhost:5279"
|
|
|
|
|
|
|
|
|
|
|
|
class LBRYURIHandler(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.started_daemon = False
|
|
|
|
self.daemon = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
|
|
|
|
|
|
|
def handle_osx(self, lbry_name):
|
|
|
|
try:
|
|
|
|
status = self.daemon.is_running()
|
|
|
|
except:
|
|
|
|
os.system("open /Applications/LBRY.app")
|
|
|
|
sleep(3)
|
|
|
|
|
|
|
|
if lbry_name == "lbry" or lbry_name == "":
|
|
|
|
webbrowser.open(UI_ADDRESS)
|
|
|
|
else:
|
2017-02-03 19:34:16 +01:00
|
|
|
webbrowser.open(UI_ADDRESS + "/?show=" + lbry_name)
|
2016-06-20 10:42:06 +02:00
|
|
|
|
|
|
|
def handle_linux(self, lbry_name):
|
|
|
|
try:
|
|
|
|
status = self.daemon.is_running()
|
|
|
|
except:
|
|
|
|
cmd = r'DIR = "$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"' \
|
|
|
|
r'if [-z "$(pgrep lbrynet-daemon)"]; then' \
|
2017-01-04 23:10:36 +01:00
|
|
|
r'echo "running lbrynet-daemon"' \
|
2016-06-20 10:42:06 +02:00
|
|
|
r'$DIR / lbrynet - daemon &' \
|
|
|
|
r'sleep 3 # let the daemon load before connecting' \
|
|
|
|
r'fi'
|
|
|
|
subprocess.Popen(cmd, shell=True)
|
|
|
|
|
|
|
|
if lbry_name == "lbry" or lbry_name == "":
|
|
|
|
webbrowser.open(UI_ADDRESS)
|
|
|
|
else:
|
2017-02-03 19:34:16 +01:00
|
|
|
webbrowser.open(UI_ADDRESS + "/?show=" + lbry_name)
|
2016-06-20 10:42:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main(args):
|
|
|
|
if len(args) != 1:
|
|
|
|
args = ['lbry://lbry']
|
|
|
|
|
|
|
|
name = args[0][7:]
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
LBRYURIHandler().handle_osx(lbry_name=name)
|
|
|
|
else:
|
|
|
|
LBRYURIHandler().handle_linux(lbry_name=name)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv[1:])
|