Skip to content

Commit

Permalink
fallback for stream name and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba authored and eukreign committed Oct 18, 2022
1 parent de3528c commit 47db91b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lbry/extras/daemon/json_response_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def encode_file(self, managed_stream):
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,
Expand Down
14 changes: 9 additions & 5 deletions lbry/stream/managed_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ def file_name(self) -> Optional[str]:

@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:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/stream/test_managed_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async def test_empty_name_fallback(self):
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)
Expand Down

0 comments on commit 47db91b

Please sign in to comment.