endpoint to call get and redirect to the partial content stream

This commit is contained in:
Jack Robison 2019-04-05 00:23:34 -04:00
parent 2d314dce60
commit 60c9ae64b4
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 13 additions and 0 deletions

View file

@ -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:

View file

@ -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