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({
|
||||
'streaming_url': managed_stream.stream_url,
|
||||
'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,
|
||||
'sd_hash': managed_stream.descriptor.sd_hash,
|
||||
'mime_type': managed_stream.mime_type,
|
||||
|
|
|
@ -86,11 +86,15 @@ class ManagedStream(ManagedDownloadSource):
|
|||
|
||||
@property
|
||||
def suggested_file_name(self) -> Optional[str]:
|
||||
if self.descriptor and self.descriptor.suggested_file_name and self.descriptor.suggested_file_name.strip():
|
||||
return self.descriptor.suggested_file_name
|
||||
elif self.stream_claim_info and self.stream_claim_info.claim:
|
||||
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
|
||||
first_option = ((self.descriptor and self.descriptor.suggested_file_name) or '').strip()
|
||||
return sanitize_file_name(first_option or (self.stream_claim_info and self.stream_claim_info.claim and
|
||||
self.stream_claim_info.claim.stream.source.name))
|
||||
|
||||
@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
|
||||
def written_bytes(self) -> int:
|
||||
|
|
|
@ -64,6 +64,7 @@ class TestManagedStream(BlobExchangeTestBase):
|
|||
await self._test_transfer_stream(10, skip_setup=True)
|
||||
self.assertTrue(self.stream.completed)
|
||||
self.assertEqual(self.stream.suggested_file_name, "cool.mp4")
|
||||
self.assertEqual(self.stream.stream_name, "cool.mp4")
|
||||
|
||||
async def test_status_file_completed(self):
|
||||
await self._test_transfer_stream(10)
|
||||
|
|
Loading…
Reference in a new issue