Merge pull request #603 from lbryio/get-availability-by-uri

get availability by uri
This commit is contained in:
Jack Robison 2017-04-10 14:30:05 -04:00 committed by GitHub
commit 16221d08a9
4 changed files with 24 additions and 8 deletions

View file

@ -14,7 +14,7 @@ at anytime.
* Add an `error` field to to file responses if an error occurs * Add an `error` field to to file responses if an error occurs
### Changed ### Changed
* * Use `uri` instead of `name` in `get_availability`
* *
* *

View file

@ -534,7 +534,7 @@ class Wallet(object):
claim['value'] = claim_dict claim['value'] = claim_dict
defer.returnValue(claim) defer.returnValue(claim)
try: try:
decoded = ClaimDict.load_dict(claim['value']) decoded = smart_decode(claim['value'])
claim_dict = decoded.claim_dict claim_dict = decoded.claim_dict
outpoint = ClaimOutpoint(claim['txid'], claim['nout']) outpoint = ClaimOutpoint(claim['txid'], claim['nout'])
name = claim['name'] name = claim['name']
@ -593,6 +593,8 @@ class Wallet(object):
claims_for_return.append(formatted) claims_for_return.append(formatted)
resolve_results['claims_in_channel'] = claims_for_return resolve_results['claims_in_channel'] = claims_for_return
result = resolve_results result = resolve_results
elif 'error' in resolve_results:
raise Exception(resolve_results['error'])
else: else:
result = None result = None
defer.returnValue(result) defer.returnValue(result)

View file

@ -684,7 +684,10 @@ class Daemon(AuthJSONRPCServer):
def eb(): def eb():
if not finished_d.called: if not finished_d.called:
finished_d.errback(Exception("Blob (%s) download timed out" % finished_d.errback(Exception("Blob (%s) download timed out" %
blob_hash[:SHORT_ID_LEN])) blob_hash[:SHORT_ID_LEN]))
if not blob_hash:
raise Exception("Nothing to download")
rate_manager = rate_manager or self.session.payment_rate_manager rate_manager = rate_manager or self.session.payment_rate_manager
timeout = timeout or 30 timeout = timeout or 30
@ -2414,12 +2417,12 @@ class Daemon(AuthJSONRPCServer):
return d return d
@defer.inlineCallbacks @defer.inlineCallbacks
def jsonrpc_get_availability(self, name, sd_timeout=None, peer_timeout=None): def jsonrpc_get_availability(self, uri, sd_timeout=None, peer_timeout=None):
""" """
Get stream availability for a winning claim Get stream availability for lbry uri
Args: Args:
'name' : (str) lbry name 'uri' : (str) lbry uri
'sd_timeout' (optional): (int) sd blob download timeout 'sd_timeout' (optional): (int) sd blob download timeout
'peer_timeout' (optional): (int) how long to look for peers 'peer_timeout' (optional): (int) how long to look for peers
@ -2443,7 +2446,16 @@ class Daemon(AuthJSONRPCServer):
sd_blob.close_read_handle(sd_blob_file) sd_blob.close_read_handle(sd_blob_file)
return decoded_sd_blob return decoded_sd_blob
metadata = yield self._resolve_name(name) try:
resolved = yield self.session.wallet.resolve_uri(uri)
except Exception:
defer.returnValue(None)
if resolved and 'claim' in resolved:
metadata = resolved['claim']['value']
else:
defer.returnValue(None)
sd_hash = utils.get_sd_hash(metadata) sd_hash = utils.get_sd_hash(metadata)
sd_timeout = sd_timeout or conf.settings['sd_download_timeout'] sd_timeout = sd_timeout or conf.settings['sd_download_timeout']
peer_timeout = peer_timeout or conf.settings['peer_search_timeout'] peer_timeout = peer_timeout or conf.settings['peer_search_timeout']
@ -2455,6 +2467,7 @@ class Daemon(AuthJSONRPCServer):
except NoSuchSDHash: except NoSuchSDHash:
need_sd_blob = True need_sd_blob = True
log.info("Need sd blob") log.info("Need sd blob")
blob_hashes = [blob.blob_hash for blob in blobs] blob_hashes = [blob.blob_hash for blob in blobs]
if need_sd_blob: if need_sd_blob:
# we don't want to use self._download_descriptor here because it would create a stream # we don't want to use self._download_descriptor here because it would create a stream
@ -2462,6 +2475,7 @@ class Daemon(AuthJSONRPCServer):
sd_blob = yield self._download_blob(sd_hash, timeout=sd_timeout) sd_blob = yield self._download_blob(sd_hash, timeout=sd_timeout)
except Exception as err: except Exception as err:
response = yield self._render_response(0.0) response = yield self._render_response(0.0)
log.warning(err)
defer.returnValue(response) defer.returnValue(response)
decoded = read_sd_blob(sd_blob) decoded = read_sd_blob(sd_blob)
blob_hashes = [blob.get("blob_hash") for blob in decoded['blobs'] blob_hashes = [blob.get("blob_hash") for blob in decoded['blobs']

View file

@ -19,7 +19,7 @@ requires = [
'envparse', 'envparse',
'jsonrpc', 'jsonrpc',
'jsonschema', 'jsonschema',
'lbryum>=2.7.15', 'lbryum>=2.7.16',
'lbryschema>=0.0.2', 'lbryschema>=0.0.2',
'miniupnpc', 'miniupnpc',
'pycrypto', 'pycrypto',