Skip to content

Commit

Permalink
Daemon.jsonrpc_get: add claim_id option for downloading content
Browse files Browse the repository at this point in the history
The `get` method normally expects a canonical url or permanent url.
```
lbrynet get lbry://@channel/something
```

However, since this URL can have Unicode characters
(Romance language accents, Cyrilic, Chinese ideograms, etc.)
it may not be easy to type with all keyboard layouts.

A more reliable way to share "addresses" and download content
is using the `'claim_id'` of the particular claim.
This is a 40-character alphanumeric string so it only
has the basic Latin alphabet and numbers.

It is easy to type with any keyboard layout.
```
lbrynet get 70dfefa510ca6eee7023a2a927e34d385b5a18bd --claim_id
```
  • Loading branch information
belikor committed Sep 3, 2021
1 parent 72049af commit 42de18c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,15 @@ async def jsonrpc_resolve(self, urls: typing.Union[str, list], wallet_id=None, *
@requires(WALLET_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, BLOB_COMPONENT, DATABASE_COMPONENT,
FILE_MANAGER_COMPONENT)
async def jsonrpc_get(
self, uri, file_name=None, download_directory=None, timeout=None, save_file=None, wallet_id=None):
self, uri, file_name=None, download_directory=None, timeout=None, save_file=None, wallet_id=None,
claim_id=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>]
[--save_file=<save_file>] [--wallet_id=<wallet_id>] [--claim_id]
Options:
Expand All @@ -1096,12 +1097,24 @@ async def jsonrpc_get(
--timeout=<timeout> : (int) download timeout in number of seconds
--save_file=<save_file> : (bool) save the file to the downloads directory
--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
Returns: {File}
"""
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
if download_directory and not os.path.isdir(download_directory):
return {"error": f"specified download directory \"{download_directory}\" does not exist"}
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}"'}

txo = out["items"][-1]
uri = txo.meta["canonical_url"]

wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
try:
stream = await self.file_manager.download_from_uri(
uri, self.exchange_rate_manager, timeout, file_name, download_directory,
Expand Down

0 comments on commit 42de18c

Please sign in to comment.