forked from LBRYCommunity/lbry-sdk
add file_name and stream_info fields to get()
-file_name is the name of the file in the downloads folder -stream_info is a dict of the metadata in a name claim, it can be used to download streams where the claim hasn’t yet been added to the nametrie
This commit is contained in:
parent
461c2f9055
commit
509b8f3a29
4 changed files with 37 additions and 15 deletions
|
@ -136,7 +136,7 @@ class ManagedLBRYFileDownloaderFactory(object):
|
||||||
def can_download(self, sd_validator):
|
def can_download(self, sd_validator):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def make_downloader(self, metadata, options, payment_rate_manager, download_directory=None):
|
def make_downloader(self, metadata, options, payment_rate_manager, download_directory=None, file_name=None):
|
||||||
data_rate = options[0]
|
data_rate = options[0]
|
||||||
upload_allowed = options[1]
|
upload_allowed = options[1]
|
||||||
|
|
||||||
|
@ -155,7 +155,8 @@ class ManagedLBRYFileDownloaderFactory(object):
|
||||||
payment_rate_manager,
|
payment_rate_manager,
|
||||||
data_rate,
|
data_rate,
|
||||||
upload_allowed,
|
upload_allowed,
|
||||||
download_directory=download_directory))
|
download_directory=download_directory,
|
||||||
|
file_name=file_name))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -94,7 +94,7 @@ class LBRYFileManager(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def start_lbry_file(self, rowid, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True,
|
def start_lbry_file(self, rowid, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True,
|
||||||
download_directory=None):
|
download_directory=None, file_name=None):
|
||||||
if not download_directory:
|
if not download_directory:
|
||||||
download_directory = self.download_directory
|
download_directory = self.download_directory
|
||||||
payment_rate_manager.min_blob_data_payment_rate = blob_data_rate
|
payment_rate_manager.min_blob_data_payment_rate = blob_data_rate
|
||||||
|
@ -105,16 +105,18 @@ class LBRYFileManager(object):
|
||||||
self.stream_info_manager, self,
|
self.stream_info_manager, self,
|
||||||
payment_rate_manager, self.session.wallet,
|
payment_rate_manager, self.session.wallet,
|
||||||
download_directory,
|
download_directory,
|
||||||
upload_allowed)
|
upload_allowed,
|
||||||
|
file_name=file_name)
|
||||||
self.lbry_files.append(lbry_file_downloader)
|
self.lbry_files.append(lbry_file_downloader)
|
||||||
d = lbry_file_downloader.set_stream_info()
|
d = lbry_file_downloader.set_stream_info()
|
||||||
d.addCallback(lambda _: lbry_file_downloader)
|
d.addCallback(lambda _: lbry_file_downloader)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def add_lbry_file(self, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True, download_directory=None):
|
def add_lbry_file(self, stream_hash, payment_rate_manager, blob_data_rate=None, upload_allowed=True,
|
||||||
|
download_directory=None, file_name=None):
|
||||||
d = self._save_lbry_file(stream_hash, blob_data_rate)
|
d = self._save_lbry_file(stream_hash, blob_data_rate)
|
||||||
d.addCallback(lambda rowid: self.start_lbry_file(rowid, stream_hash, payment_rate_manager,
|
d.addCallback(lambda rowid: self.start_lbry_file(rowid, stream_hash, payment_rate_manager,
|
||||||
blob_data_rate, upload_allowed, download_directory))
|
blob_data_rate, upload_allowed, download_directory, file_name))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def delete_lbry_file(self, lbry_file):
|
def delete_lbry_file(self, lbry_file):
|
||||||
|
|
|
@ -889,7 +889,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, downloader_factory)
|
self.sd_identifier.add_stream_downloader_factory(LBRYFileStreamType, downloader_factory)
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
def _download_name(self, name, timeout=DEFAULT_TIMEOUT, download_directory=None):
|
def _download_name(self, name, timeout=DEFAULT_TIMEOUT, download_directory=None, file_name=None, stream_info=None):
|
||||||
"""
|
"""
|
||||||
Add a lbry file to the file manager, start the download, and return the new lbry file.
|
Add a lbry file to the file manager, start the download, and return the new lbry file.
|
||||||
If it already exists in the file manager, return the existing lbry file
|
If it already exists in the file manager, return the existing lbry file
|
||||||
|
@ -923,17 +923,21 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
self.streams[name] = GetStream(self.sd_identifier, self.session, self.session.wallet,
|
self.streams[name] = GetStream(self.sd_identifier, self.session, self.session.wallet,
|
||||||
self.lbry_file_manager, max_key_fee=self.max_key_fee,
|
self.lbry_file_manager, max_key_fee=self.max_key_fee,
|
||||||
data_rate=self.data_rate, timeout=timeout,
|
data_rate=self.data_rate, timeout=timeout,
|
||||||
download_directory=download_directory)
|
download_directory=download_directory, file_name=file_name)
|
||||||
d = self.streams[name].start(stream_info, name)
|
d = self.streams[name].start(stream_info, name)
|
||||||
d.addCallback(lambda _: self.streams[name].downloader)
|
d.addCallback(lambda _: self.streams[name].downloader)
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
self.waiting_on[name] = True
|
if not stream_info:
|
||||||
d = self._resolve_name(name)
|
self.waiting_on[name] = True
|
||||||
|
d = self._resolve_name(name)
|
||||||
|
else:
|
||||||
|
d = defer.succeed(stream_info)
|
||||||
d.addCallback(_setup_stream)
|
d.addCallback(_setup_stream)
|
||||||
d.addCallback(lambda (stream_info, lbry_file): _get_stream(stream_info) if not lbry_file else _disp_file(lbry_file))
|
d.addCallback(lambda (stream_info, lbry_file): _get_stream(stream_info) if not lbry_file else _disp_file(lbry_file))
|
||||||
d.addCallback(_remove_from_wait)
|
if not stream_info:
|
||||||
|
d.addCallback(_remove_from_wait)
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -1418,7 +1422,9 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
'name': name to download, string
|
'name': name to download, string
|
||||||
optional 'download_directory': path to directory where file will be saved, string
|
'download_directory': optional, path to directory where file will be saved, string
|
||||||
|
'file_name': optional, a user specified name for the downloaded file
|
||||||
|
'stream_info': optional, specified stream info overrides name
|
||||||
Returns:
|
Returns:
|
||||||
'stream_hash': hex string
|
'stream_hash': hex string
|
||||||
'path': path of download
|
'path': path of download
|
||||||
|
@ -1434,10 +1440,21 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
else:
|
else:
|
||||||
download_directory = p['download_directory']
|
download_directory = p['download_directory']
|
||||||
|
|
||||||
|
if 'file_name' in p.keys():
|
||||||
|
file_name = p['file_name']
|
||||||
|
else:
|
||||||
|
file_name = None
|
||||||
|
|
||||||
|
if 'stream_info' in p.keys():
|
||||||
|
stream_info = p['stream_info']
|
||||||
|
else:
|
||||||
|
stream_info = None
|
||||||
|
|
||||||
if 'name' in p.keys():
|
if 'name' in p.keys():
|
||||||
name = p['name']
|
name = p['name']
|
||||||
if p['name'] not in self.waiting_on.keys():
|
if p['name'] not in self.waiting_on.keys():
|
||||||
d = self._download_name(name=name, timeout=timeout, download_directory=download_directory)
|
d = self._download_name(name=name, timeout=timeout, download_directory=download_directory,
|
||||||
|
stream_info=stream_info, file_name=file_name)
|
||||||
d.addCallback(lambda l: {'stream_hash': l.sd_hash, 'path': os.path.join(self.download_directory, l.file_name)})
|
d.addCallback(lambda l: {'stream_hash': l.sd_hash, 'path': os.path.join(self.download_directory, l.file_name)})
|
||||||
d.addCallback(lambda message: self._render_response(message, OK_CODE))
|
d.addCallback(lambda message: self._render_response(message, OK_CODE))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -44,7 +44,7 @@ log.setLevel(logging.INFO)
|
||||||
|
|
||||||
class GetStream(object):
|
class GetStream(object):
|
||||||
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True, data_rate=0.5,
|
def __init__(self, sd_identifier, session, wallet, lbry_file_manager, max_key_fee, pay_key=True, data_rate=0.5,
|
||||||
timeout=DEFAULT_TIMEOUT, download_directory=None):
|
timeout=DEFAULT_TIMEOUT, download_directory=None, file_name=None):
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.resolved_name = None
|
self.resolved_name = None
|
||||||
self.description = None
|
self.description = None
|
||||||
|
@ -53,6 +53,7 @@ class GetStream(object):
|
||||||
self.data_rate = data_rate
|
self.data_rate = data_rate
|
||||||
self.pay_key = pay_key
|
self.pay_key = pay_key
|
||||||
self.name = None
|
self.name = None
|
||||||
|
self.file_name = file_name
|
||||||
self.session = session
|
self.session = session
|
||||||
self.payment_rate_manager = PaymentRateManager(self.session.base_payment_rate_manager)
|
self.payment_rate_manager = PaymentRateManager(self.session.base_payment_rate_manager)
|
||||||
self.lbry_file_manager = lbry_file_manager
|
self.lbry_file_manager = lbry_file_manager
|
||||||
|
@ -135,7 +136,8 @@ class GetStream(object):
|
||||||
self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata,
|
self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata,
|
||||||
[self.data_rate, True],
|
[self.data_rate, True],
|
||||||
self.payment_rate_manager,
|
self.payment_rate_manager,
|
||||||
download_directory=self.download_directory))
|
download_directory=self.download_directory,
|
||||||
|
file_name=self.file_name))
|
||||||
self.d.addCallbacks(self._start_download, lambda _: _cause_timeout())
|
self.d.addCallbacks(self._start_download, lambda _: _cause_timeout())
|
||||||
self.d.callback(None)
|
self.d.callback(None)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue