Skip to content

Commit

Permalink
Daemon.jsonrpc_get: add download_repost option for downloading reposts
Browse files Browse the repository at this point in the history
Normally, if a particular claim is in fact a repost,
it will not be downloaded, as it is not a stream.
```
lbrynet get reposted-content
```

Will result in
```
{
  "error": "Claim is not a stream."
}
```

To resolve the repost and download the actual claim
we can use the option `--download_repost`.
```
lbrynet get reposted-content --download_repost
```
  • Loading branch information
belikor committed Sep 3, 2021
1 parent 42de18c commit 2712dda
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,14 @@ async def jsonrpc_resolve(self, urls: typing.Union[str, list], wallet_id=None, *
FILE_MANAGER_COMPONENT)
async def jsonrpc_get(
self, uri, file_name=None, download_directory=None, timeout=None, save_file=None, wallet_id=None,
claim_id=False):
claim_id=False, download_repost=False):
"""
Download stream from a LBRY name.
Usage:
get <uri> [<file_name> | --file_name=<file_name>]
[<download_directory> | --download_directory=<download_directory>] [<timeout> | --timeout=<timeout>]
[--save_file=<save_file>] [--wallet_id=<wallet_id>] [--claim_id]
[--save_file=<save_file>] [--wallet_id=<wallet_id>] [--claim_id] [--download_repost]
Options:
Expand All @@ -1099,20 +1099,28 @@ async def jsonrpc_get(
--wallet_id=<wallet_id> : (str) wallet to check for claim purchase receipts
--claim_id : (bool) treat <uri> as a claim_id, that is, download by claim_id
instead of canonical URL
--download_repost : (bool) resolve the claim, and if it is a repost, download the original claim
Returns: {File}
"""
if download_directory and not os.path.isdir(download_directory):
return {"error": f'specified download directory "{download_directory}" does not exist'}

if claim_id:
out = await self.jsonrpc_claim_search(claim_id=uri, wallet_id=wallet_id)
if out["total_items"] < 1:
return {"error":
f'No item found with specified claim_id "{uri}"'}
if claim_id or download_repost:
if claim_id:
out = await self.jsonrpc_claim_search(claim_id=uri, wallet_id=wallet_id)
if out["total_items"] < 1:
return {"error":
f'No item found with specified claim_id "{uri}"'}

txo = out["items"][-1]
uri = txo.meta["canonical_url"]
else:
out = await self.jsonrpc_resolve(uri, wallet_id=wallet_id)
txo = out[uri]

txo = out["items"][-1]
uri = txo.meta["canonical_url"]
if download_repost and txo.reposted_claim:
uri = txo.reposted_claim.meta["canonical_url"]

wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
try:
Expand Down

0 comments on commit 2712dda

Please sign in to comment.