From 60c9ae64b42a24f39f40c1d578904b33af6f1338 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 5 Apr 2019 00:23:34 -0400 Subject: [PATCH] endpoint to call get and redirect to the partial content stream --- lbrynet/extras/daemon/Daemon.py | 12 ++++++++++++ lbrynet/stream/stream_manager.py | 1 + 2 files changed, 13 insertions(+) diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index addffec4a..de2a49d74 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -273,6 +273,8 @@ class Daemon(metaclass=JSONRPCServerType): app.router.add_get('/lbryapi', self.handle_old_jsonrpc) app.router.add_post('/lbryapi', self.handle_old_jsonrpc) app.router.add_get('/streams', self.handle_streams_index) + app.router.add_get('/get/{claim_name}', self.handle_stream_get_request) + app.router.add_get('/get/{claim_name}/{claim_id}', self.handle_stream_get_request) app.router.add_get('/stream/{sd_hash}', self.handle_stream_range_request) app.router.add_post('/', self.handle_old_jsonrpc) self.runner = web.AppRunner(app) @@ -463,6 +465,16 @@ class Daemon(metaclass=JSONRPCServerType): content_type='text/html' ) + async def handle_stream_get_request(self, request: web.Request): + name_and_claim_id = request.path.split("/get/")[1] + if "/" not in name_and_claim_id: + uri = f"lbry://{name_and_claim_id}" + else: + name, claim_id = name_and_claim_id.split("/") + uri = f"lbry://{name}#{claim_id}" + stream = await self.jsonrpc_get(uri) + return web.HTTPFound(f"http://localhost:5279/stream/{stream['sd_hash']}") + async def handle_stream_range_request(self, request: web.Request): sd_hash = request.path.split("/stream/")[1] if sd_hash not in self.stream_manager.streams: diff --git a/lbrynet/stream/stream_manager.py b/lbrynet/stream/stream_manager.py index 730df8078..7205761dd 100644 --- a/lbrynet/stream/stream_manager.py +++ b/lbrynet/stream/stream_manager.py @@ -381,6 +381,7 @@ class StreamManager: file_name, ManagedStream.STATUS_RUNNING, content_fee=content_fee, analytics_manager=self.analytics_manager ) + log.info("starting download for %s", uri) try: await asyncio.wait_for(stream.setup( self.node, save_file=save_file, file_name=file_name, download_directory=download_directory