forked from LBRYCommunity/lbry-sdk
fallback for stream name and tests
This commit is contained in:
parent
97fef21f75
commit
1027337833
3 changed files with 11 additions and 6 deletions
|
@ -328,7 +328,7 @@ class JSONResponseEncoder(JSONEncoder):
|
||||||
result.update({
|
result.update({
|
||||||
'streaming_url': managed_stream.stream_url,
|
'streaming_url': managed_stream.stream_url,
|
||||||
'stream_hash': managed_stream.stream_hash,
|
'stream_hash': managed_stream.stream_hash,
|
||||||
'stream_name': managed_stream.descriptor.stream_name,
|
'stream_name': managed_stream.stream_name,
|
||||||
'suggested_file_name': managed_stream.suggested_file_name,
|
'suggested_file_name': managed_stream.suggested_file_name,
|
||||||
'sd_hash': managed_stream.descriptor.sd_hash,
|
'sd_hash': managed_stream.descriptor.sd_hash,
|
||||||
'mime_type': managed_stream.mime_type,
|
'mime_type': managed_stream.mime_type,
|
||||||
|
|
|
@ -86,11 +86,15 @@ class ManagedStream(ManagedDownloadSource):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def suggested_file_name(self) -> Optional[str]:
|
def suggested_file_name(self) -> Optional[str]:
|
||||||
if self.descriptor and self.descriptor.suggested_file_name and self.descriptor.suggested_file_name.strip():
|
first_option = ((self.descriptor and self.descriptor.suggested_file_name) or '').strip()
|
||||||
return self.descriptor.suggested_file_name
|
return sanitize_file_name(first_option or (self.stream_claim_info and self.stream_claim_info.claim and
|
||||||
elif self.stream_claim_info and self.stream_claim_info.claim:
|
self.stream_claim_info.claim.stream.source.name))
|
||||||
return sanitize_file_name(self.stream_claim_info.claim.stream.source.name)
|
|
||||||
return "lbry_download" # default replacement for invalid name. Ideally we should never get here
|
@property
|
||||||
|
def stream_name(self) -> Optional[str]:
|
||||||
|
first_option = ((self.descriptor and self.descriptor.stream_name) or '').strip()
|
||||||
|
return first_option or (self.stream_claim_info and self.stream_claim_info.claim and
|
||||||
|
self.stream_claim_info.claim.stream.source.name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def written_bytes(self) -> int:
|
def written_bytes(self) -> int:
|
||||||
|
|
|
@ -64,6 +64,7 @@ class TestManagedStream(BlobExchangeTestBase):
|
||||||
await self._test_transfer_stream(10, skip_setup=True)
|
await self._test_transfer_stream(10, skip_setup=True)
|
||||||
self.assertTrue(self.stream.completed)
|
self.assertTrue(self.stream.completed)
|
||||||
self.assertEqual(self.stream.suggested_file_name, "cool.mp4")
|
self.assertEqual(self.stream.suggested_file_name, "cool.mp4")
|
||||||
|
self.assertEqual(self.stream.stream_name, "cool.mp4")
|
||||||
|
|
||||||
async def test_status_file_completed(self):
|
async def test_status_file_completed(self):
|
||||||
await self._test_transfer_stream(10)
|
await self._test_transfer_stream(10)
|
||||||
|
|
Loading…
Reference in a new issue