add /view to dynamically generate a video containing page

-uses UI stored in Resources folder of app

-going to /view?name=  will download the corresponding stream and
display the file in the browser

-adds default daemon settings, currently they don’t do anything, to be
added to

-adds missing packages to setup.py
This commit is contained in:
Jack 2016-03-22 00:03:17 -04:00
parent 55f25c2613
commit ba991b47ea
3 changed files with 87 additions and 35 deletions

View file

@ -126,7 +126,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
else: else:
self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd") self.wallet_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads') self.download_directory = os.path.join(os.path.expanduser("~"), 'Downloads')
self.daemon_conf = os.path.join(self.wallet_dir, 'daemon_settings.conf')
self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf") self.wallet_conf = os.path.join(self.wallet_dir, "lbrycrd.conf")
self.wallet_user = None self.wallet_user = None
self.wallet_password = None self.wallet_password = None
@ -164,6 +164,14 @@ class LBRYDaemon(jsonrpc.JSONRPC):
self.announced_startup = False self.announced_startup = False
self.search_timeout = 3.0 self.search_timeout = 3.0
self.query_handlers = {} self.query_handlers = {}
self.default_settings = {
'run_on_startup': False,
'data_rate': MIN_BLOB_DATA_PAYMENT_RATE,
'max_key_fee': 10.0,
'default_download_directory': self.download_directory,
'max_upload': 0.0,
'max_download': 0.0
}
return defer.succeed(None) return defer.succeed(None)
@ -178,7 +186,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
log.info("[" + str(datetime.now()) + "] Starting lbrynet-daemon") log.info("[" + str(datetime.now()) + "] Starting lbrynet-daemon")
d = defer.Deferred() d = defer.Deferred()
d.addCallback(lambda _: _set_vars(wallet_type, check_for_updates)) d.addCallback(lambda _:_set_vars(wallet_type, check_for_updates))
d.addCallback(lambda _: self._setup_daemon_settings())
d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory)) d.addCallback(lambda _: threads.deferToThread(self._setup_data_directory))
d.addCallback(lambda _: self._check_db_migration()) d.addCallback(lambda _: self._check_db_migration())
d.addCallback(lambda _: self._get_settings()) d.addCallback(lambda _: self._get_settings())
@ -201,6 +210,10 @@ class LBRYDaemon(jsonrpc.JSONRPC):
def _initial_setup(self): def _initial_setup(self):
return NotImplemented return NotImplemented
def _setup_daemon_settings(self):
self.session_settings = self.default_settings
return defer.succeed(None)
def _update(self): def _update(self):
def _check_for_updater(): def _check_for_updater():
if os.path.isdir("/Applications/LBRY Updater.app"): if os.path.isdir("/Applications/LBRY Updater.app"):
@ -370,9 +383,28 @@ class LBRYDaemon(jsonrpc.JSONRPC):
d.addCallback(lambda _: self.session.shut_down()) d.addCallback(lambda _: self.session.shut_down())
return d return d
def _update_settings(self): def _update_settings(self, settings):
self.data_rate = self.session_settings['data_rate'] if not isinstance(settings['run_on_startup'], bool):
self.max_key_fee = self.session_settings['max_key_fee'] return defer.fail()
elif not isinstance(settings['data_rate'], float):
return defer.fail()
elif not isinstance(settings['max_key_fee'], float):
return defer.fail()
elif not isinstance(settings['default_download_directory'], unicode):
return defer.fail()
elif not isinstance(settings['max_upload'], float):
return defer.fail()
elif not isinstance(settings['max_download'], float):
return defer.fail()
self.session_settings['run_on_startup'] = settings['run_on_startup']
self.session_settings['data_rate'] = settings['data_rate']
self.session_settings['max_key_fee'] = settings['max_key_fee']
self.session_settings['default_download_directory'] = settings['default_download_directory']
self.session_settings['max_upload'] = settings['max_upload']
self.session_settings['max_download'] = settings['max_download']
return defer.succeed(True)
def _setup_fetcher(self): def _setup_fetcher(self):
self.fetcher = FetcherDaemon(self.session, self.lbry_file_manager, self.lbry_file_metadata_manager, self.fetcher = FetcherDaemon(self.session, self.lbry_file_manager, self.lbry_file_metadata_manager,
@ -739,9 +771,6 @@ class LBRYDaemon(jsonrpc.JSONRPC):
@return {'data_rate': float, 'max_key_fee': float} @return {'data_rate': float, 'max_key_fee': float}
""" """
if not self.session_settings:
self.session_settings = {'data_rate': self.data_rate, 'max_key_fee': self.max_key_fee}
log.info("[" + str(datetime.now()) + "] Get daemon settings") log.info("[" + str(datetime.now()) + "] Get daemon settings")
return self._render_response(self.session_settings, OK_CODE) return self._render_response(self.session_settings, OK_CODE)
@ -751,10 +780,8 @@ class LBRYDaemon(jsonrpc.JSONRPC):
@param settings: {'settings': {'data_rate': float, 'max_key_fee': float}} @param settings: {'settings': {'data_rate': float, 'max_key_fee': float}}
""" """
params = Bunch(p)
self.session_settings = params.settings d = self._update_settings(p)
self._update_settings()
log.info("[" + str(datetime.now()) + "] Set daemon settings") log.info("[" + str(datetime.now()) + "] Set daemon settings")
return self._render_response(True, OK_CODE) return self._render_response(True, OK_CODE)
@ -1194,39 +1221,60 @@ class LBRYindex(resource.Resource):
request.write(str(results)) request.write(str(results))
request.finish() request.finish()
def getChild(self, name, request):
if name == '':
return self
return resource.Resource.getChild(self, name, request)
def render_GET(self, request): def render_GET(self, request):
def _disp(r): def _disp(r):
log.info(r) log.info(r)
return "<html><table style='width:100%'>" + ''.join(r) + "</html>" return "<html><table style='width:100%'>" + ''.join(r) + "</html>"
return static.File("./dist/index.html").render_GET(request)
d = LBRYDaemonCommandHandler('__dir__').run()
d.addCallback(lambda functions: ["<tr><td><a href=/webapi?function=%s>%s</a></td></tr>" % (function, function) for function in functions])
d.addCallback(_disp)
d.addCallbacks(lambda results: self._delayed_render(request, results),
lambda err: self._delayed_render(request, err.getTraceback()))
return server.NOT_DONE_YET
class LBRYFilePage(resource.Resource): class LBRYFileRender(resource.Resource):
isLeaf = False isLeaf = False
def _render_path(self, path):
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))
request.finish() request.finish()
h = "<tr><td><a href=/webapi?function=delete_lbry_file&file_name=%s>%s</a></td></tr>" def render_GET(self, request):
if 'name' in request.args.keys():
api = jsonrpc.Proxy(API_CONNECTION_STRING)
d = api.callRemote("get", {'name': request.args['name'][0]})
d.addCallback(lambda response: self._delayed_render(request, self._render_path(json.loads(response)['result']['path']))
if json.loads(response)['code'] == 200
else self._delayed_render(request, "Error"))
d = LBRYDaemonCommandHandler('get_lbry_files').run() return server.NOT_DONE_YET
d.addCallback(lambda r: json.loads(r)['result']) else:
d.addCallback(lambda lbry_files: [h % (json.loads(lbry_file)['file_name'], json.loads(lbry_file)['file_name']) for lbry_file in lbry_files]) self._delayed_render(request, "Error")
d.addCallback(lambda r: "<html><table style='width:100%'>" + ''.join(r) + "</html>") return server.NOT_DONE_YET
d.addCallbacks(lambda results: self._delayed_render(request, results),
lambda err: self._delayed_render(request, err.getTraceback()))
return server.NOT_DONE_YET
# class LBRYFilePage(resource.Resource):
# isLeaf = False
#
# def _delayed_render(self, request, results):
# request.write(str(results))
# request.finish()
#
# h = "<tr><td><a href=/webapi?function=delete_lbry_file&file_name=%s>%s</a></td></tr>"
#
# d = LBRYDaemonCommandHandler('get_lbry_files').run()
# d.addCallback(lambda r: json.loads(r)['result'])
# d.addCallback(lambda lbry_files: [h % (json.loads(lbry_file)['file_name'], json.loads(lbry_file)['file_name']) for lbry_file in lbry_files])
# d.addCallback(lambda r: "<html><table style='width:100%'>" + ''.join(r) + "</html>")
# d.addCallbacks(lambda results: self._delayed_render(request, results),
# lambda err: self._delayed_render(request, err.getTraceback()))
#
# return server.NOT_DONE_YET
class LBRYDaemonWeb(resource.Resource): class LBRYDaemonWeb(resource.Resource):

View file

@ -1,11 +1,11 @@
import argparse import argparse
import logging import logging
from twisted.web import server from twisted.web import server, static
from twisted.internet import reactor, defer from twisted.internet import reactor, defer
from jsonrpc.proxy import JSONRPCProxy from jsonrpc.proxy import JSONRPCProxy
from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon, LBRYindex, LBRYDaemonWeb, LBRYFilePage from lbrynet.lbrynet_daemon.LBRYDaemon import LBRYDaemon, LBRYindex, LBRYDaemonWeb, LBRYFileRender
from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, DEFAULT_WALLET from lbrynet.conf import API_CONNECTION_STRING, API_INTERFACE, API_ADDRESS, API_PORT, DEFAULT_WALLET
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -43,9 +43,13 @@ def start():
daemon.setup(args.wallet, args.update) daemon.setup(args.wallet, args.update)
root = LBRYindex() root = LBRYindex()
root.putChild("", root) root.putChild("css", static.File("./css"))
root.putChild("webapi", LBRYDaemonWeb()) root.putChild("font", static.File("./font"))
root.putChild("img", static.File("./img"))
root.putChild("js", static.File("./js"))
root.putChild(API_ADDRESS, daemon) root.putChild(API_ADDRESS, daemon)
root.putChild("myfiles", LBRYFilePage()) root.putChild("webapi", LBRYDaemonWeb())
root.putChild("view", LBRYFileRender())
reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE) reactor.listenTCP(API_PORT, server.Site(root), interface=API_INTERFACE)
reactor.run() reactor.run()

View file

@ -29,7 +29,7 @@ setup(name='lbrynet',
packages=find_packages(), packages=find_packages(),
install_requires=['six>=1.9.0', 'pycrypto', 'twisted', 'miniupnpc', 'yapsy', 'seccure', install_requires=['six>=1.9.0', 'pycrypto', 'twisted', 'miniupnpc', 'yapsy', 'seccure',
'python-bitcoinrpc==0.1', 'txJSON-RPC', 'requests>=2.4.2', 'unqlite==0.2.0', 'python-bitcoinrpc==0.1', 'txJSON-RPC', 'requests>=2.4.2', 'unqlite==0.2.0',
'leveldb', 'lbryum'], 'leveldb', 'lbryum', 'jsonrpc', 'simplejson', 'appdirs'],
entry_points={'console_scripts': console_scripts}, entry_points={'console_scripts': console_scripts},
data_files=[ data_files=[
('lbrynet/lbrynet_console/plugins', ('lbrynet/lbrynet_console/plugins',