forked from LBRYCommunity/lbry-sdk
Added a max key price set in autofetcher.conf
This commit is contained in:
parent
45eb4f7201
commit
35d5c585ec
2 changed files with 45 additions and 17 deletions
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
from twisted.internet import defer
|
||||
from twisted.internet.task import LoopingCall
|
||||
from lbrynet.core.Error import InvalidStreamInfoError, InsufficientFundsError
|
||||
|
@ -10,7 +12,7 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class AutoAddStreamFromLBRYcrdName(object):
|
||||
def __init__(self, console, sd_identifier, session, wallet, lbry_file_manager):
|
||||
def __init__(self, console, sd_identifier, session, wallet, lbry_file_manager, max_key_fee):
|
||||
self.finished_deferred = defer.Deferred(None)
|
||||
self.console = console
|
||||
self.wallet = wallet
|
||||
|
@ -31,6 +33,8 @@ class AutoAddStreamFromLBRYcrdName(object):
|
|||
self.key_fee = None
|
||||
self.key_fee_address = None
|
||||
self.stream_hash = None
|
||||
self.max_key_fee = max_key_fee
|
||||
self.stream_info = None
|
||||
|
||||
def start(self, stream_info):
|
||||
self.stream_info = stream_info
|
||||
|
@ -47,10 +51,14 @@ class AutoAddStreamFromLBRYcrdName(object):
|
|||
self.key_fee_address = json.loads(self.stream_info['value']).get('key_fee_address', None)
|
||||
self.stream_hash = json.loads(self.stream_info['value'])['stream_hash']
|
||||
|
||||
if self.key_fee > self.max_key_fee:
|
||||
self.console.sendLine("Key fee (" + str(self.key_fee) + ") above limit of " + str(
|
||||
self.max_key_fee) + ", didn't download lbry://" + str(self.resolved_name))
|
||||
return self.finished_deferred.callback(None)
|
||||
|
||||
self.loading_metadata_deferred = defer.Deferred(None)
|
||||
self.loading_metadata_deferred.addCallback(lambda _: download_sd_blob(self.session,
|
||||
self.stream_hash, self.payment_rate_manager))
|
||||
self.loading_metadata_deferred.addCallback(
|
||||
lambda _: download_sd_blob(self.session, self.stream_hash, self.payment_rate_manager))
|
||||
self.loading_metadata_deferred.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
|
||||
self.loading_metadata_deferred.addCallback(self._handle_metadata)
|
||||
self.loading_metadata_deferred.addErrback(self._handle_load_canceled)
|
||||
|
@ -95,14 +103,18 @@ class AutoAddStreamFromLBRYcrdName(object):
|
|||
if err.check(InsufficientFundsError):
|
||||
self.console.sendLine("Download stopped due to insufficient funds.")
|
||||
else:
|
||||
self.console.sendLine("Autoaddstream: An unexpected error has caused the download to stop: %s" % err.getTraceback())
|
||||
self.console.sendLine(
|
||||
"Autoaddstream: An unexpected error has caused the download to stop: %s" % err.getTraceback())
|
||||
|
||||
def _make_downloader(self):
|
||||
self.downloader = self.factory.make_downloader(self.metadata, [0.5, True], self.payment_rate_manager)
|
||||
return self.downloader
|
||||
|
||||
|
||||
class AutoFetcher(object):
|
||||
def __init__(self, session, lbry_file_manager, lbry_file_metadata_manager, wallet, sd_identifier):
|
||||
def __init__(self, session, lbry_file_manager, lbry_file_metadata_manager, wallet, sd_identifier, autofetcher_conf):
|
||||
self.autofetcher_conf = autofetcher_conf
|
||||
self.max_key_fee = 0.0
|
||||
self.console = None
|
||||
self.sd_identifier = sd_identifier
|
||||
self.wallet = wallet
|
||||
|
@ -115,6 +127,7 @@ class AutoFetcher(object):
|
|||
self.search = None
|
||||
self.first_run = True
|
||||
self.is_running = False
|
||||
self._get_autofetcher_conf()
|
||||
|
||||
def start(self, console):
|
||||
# TODO first search through the nametrie before monitoring live updates
|
||||
|
@ -156,12 +169,10 @@ class AutoFetcher(object):
|
|||
transactions = [self.rpc_conn.decoderawtransaction(self.rpc_conn.getrawtransaction(t)) for t in txids]
|
||||
for t in transactions:
|
||||
claims = self.rpc_conn.getclaimsfortx(t['txid'])
|
||||
|
||||
# uncomment to make it download lbry://y on startup
|
||||
# uncomment to make it download lbry://yyyy on startup
|
||||
# if self.first_run:
|
||||
# claims = self.rpc_conn.getclaimsfortx("38da801a2c3620a79252e5b0b619d1d3f4d53aa9edd9cdc76d9ba65660fb9f06")
|
||||
# claims = self.rpc_conn.getclaimsfortx("43a784085949f7bebe5c2a2b74f4e2c6abec36219a5d04d285206b4056ea218b")
|
||||
# self.first_run = False
|
||||
|
||||
if claims:
|
||||
for claim in claims:
|
||||
if claim not in self.seen:
|
||||
|
@ -183,7 +194,7 @@ class AutoFetcher(object):
|
|||
for claim in claims:
|
||||
download = defer.Deferred()
|
||||
stream = AutoAddStreamFromLBRYcrdName(self.console, self.sd_identifier, self.session,
|
||||
self.wallet, self.lbry_file_manager)
|
||||
self.wallet, self.lbry_file_manager, self.max_key_fee)
|
||||
download.addCallback(lambda _: stream.start(claim))
|
||||
download.callback(None)
|
||||
|
||||
|
@ -194,3 +205,19 @@ class AutoFetcher(object):
|
|||
d.addCallback(lambda _: self._get_names())
|
||||
d.addCallback(self._download_claims)
|
||||
d.callback(None)
|
||||
|
||||
def _get_autofetcher_conf(self):
|
||||
settings = {"maxkey": "0.0"}
|
||||
if os.path.exists(self.autofetcher_conf):
|
||||
conf = open(self.autofetcher_conf)
|
||||
for l in conf:
|
||||
if l.startswith("maxkey="):
|
||||
settings["maxkey"] = float(l[7:].rstrip('\n'))
|
||||
else:
|
||||
self.console.sendLine("Autofetcher using default max key price of 0.0")
|
||||
self.console.sendLine("To change this create the file:")
|
||||
self.console.sendLine(str(self.autofetcher_conf))
|
||||
self.console.sendLine("Example contents of conf file:")
|
||||
self.console.sendLine("maxkey=1.0")
|
||||
|
||||
self.max_key_fee = settings["maxkey"]
|
||||
|
|
|
@ -66,6 +66,7 @@ class LBRYConsole():
|
|||
self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
|
||||
if not self.lbrycrd_conf:
|
||||
self.lbrycrd_conf = os.path.join(self.lbrycrd_dir, "lbrycrd.conf")
|
||||
self.autofetcher_conf = os.path.join(self.lbrycrd_dir, "autofetcher.conf")
|
||||
self.lbrycrdd_path = lbrycrdd_path
|
||||
self.default_lbrycrdd_path = "./lbrycrdd"
|
||||
self.start_lbrycrdd = start_lbrycrdd
|
||||
|
@ -104,7 +105,7 @@ class LBRYConsole():
|
|||
d.addCallback(lambda _: add_lbry_file_to_sd_identifier(self.sd_identifier))
|
||||
d.addCallback(lambda _: self._setup_lbry_file_manager())
|
||||
d.addCallback(lambda _: self._setup_lbry_file_opener())
|
||||
d.addCallback(lambda _: self._get_autofetcher()),
|
||||
d.addCallback(lambda _: self._get_autofetcher())
|
||||
d.addCallback(lambda _: self._setup_control_handlers())
|
||||
d.addCallback(lambda _: self._setup_query_handlers())
|
||||
d.addCallback(lambda _: self._load_plugins())
|
||||
|
@ -115,7 +116,7 @@ class LBRYConsole():
|
|||
|
||||
def _get_autofetcher(self):
|
||||
self.autofetcher = AutoFetcher(self.session, self.lbry_file_manager, self.lbry_file_metadata_manager,
|
||||
self.session.wallet, self.sd_identifier)
|
||||
self.session.wallet, self.sd_identifier, self.autofetcher_conf)
|
||||
|
||||
def _show_start_error(self, error):
|
||||
print error.getErrorMessage()
|
||||
|
|
Loading…
Reference in a new issue