forked from LBRYCommunity/lbry-sdk
endpoint to call get and redirect to the partial content stream
This commit is contained in:
parent
2d314dce60
commit
60c9ae64b4
2 changed files with 13 additions and 0 deletions
|
@ -273,6 +273,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
app.router.add_get('/lbryapi', self.handle_old_jsonrpc)
|
app.router.add_get('/lbryapi', self.handle_old_jsonrpc)
|
||||||
app.router.add_post('/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('/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_get('/stream/{sd_hash}', self.handle_stream_range_request)
|
||||||
app.router.add_post('/', self.handle_old_jsonrpc)
|
app.router.add_post('/', self.handle_old_jsonrpc)
|
||||||
self.runner = web.AppRunner(app)
|
self.runner = web.AppRunner(app)
|
||||||
|
@ -463,6 +465,16 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
content_type='text/html'
|
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):
|
async def handle_stream_range_request(self, request: web.Request):
|
||||||
sd_hash = request.path.split("/stream/")[1]
|
sd_hash = request.path.split("/stream/")[1]
|
||||||
if sd_hash not in self.stream_manager.streams:
|
if sd_hash not in self.stream_manager.streams:
|
||||||
|
|
|
@ -381,6 +381,7 @@ class StreamManager:
|
||||||
file_name, ManagedStream.STATUS_RUNNING, content_fee=content_fee,
|
file_name, ManagedStream.STATUS_RUNNING, content_fee=content_fee,
|
||||||
analytics_manager=self.analytics_manager
|
analytics_manager=self.analytics_manager
|
||||||
)
|
)
|
||||||
|
log.info("starting download for %s", uri)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(stream.setup(
|
await asyncio.wait_for(stream.setup(
|
||||||
self.node, save_file=save_file, file_name=file_name, download_directory=download_directory
|
self.node, save_file=save_file, file_name=file_name, download_directory=download_directory
|
||||||
|
|
Loading…
Reference in a new issue