Get managed lbry files

This commit is contained in:
Jack 2016-01-13 09:42:30 -05:00
parent ebb495ab8b
commit 2085012874
2 changed files with 37 additions and 5 deletions

View file

@ -1,3 +1,4 @@
import binascii
from lbrynet.core.Error import UnknownNameError from lbrynet.core.Error import UnknownNameError
from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType
from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory
@ -19,6 +20,7 @@ import logging
import os import os
import sys import sys
import sqlite3 import sqlite3
import json
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -392,7 +394,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
if files: if files:
if not os.path.isfile(files[0][2]): if not os.path.isfile(files[0][2]):
print "Couldn't find", files[0][2], ", trying to redownload it" print "[" + str(datetime.now()) + "] Couldn't find", files[0][2], ", trying to redownload it"
self.cur.execute("delete from history where stream_hash='" + files[0][0] + "'") self.cur.execute("delete from history where stream_hash='" + files[0][0] + "'")
self.db.commit() self.db.commit()
return [] return []
@ -412,7 +414,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
self.cur.execute("insert into history values (?, ?, ?)", vals) self.cur.execute("insert into history values (?, ?, ?)", vals)
self.db.commit() self.db.commit()
else: else:
print 'Already downloaded', path['stream_hash'], '-->', path['path'] print '[' + str(datetime.now()) + '] Already downloaded', path['stream_hash'], '-->', path['path']
return path return path
@ -424,12 +426,14 @@ class LBRYDaemon(xmlrpc.XMLRPC):
if not self.session_settings: if not self.session_settings:
self.session_settings = {'data_rate': self.data_rate, 'max_key_fee': self.max_key_fee} self.session_settings = {'data_rate': self.data_rate, 'max_key_fee': self.max_key_fee}
print '[' + str(datetime.now()) + '] Get daemon settings'
return self.session_settings return self.session_settings
def xmlrpc_set_settings(self, settings): def xmlrpc_set_settings(self, settings):
self.session_settings = settings self.session_settings = settings
self._update_settings() self._update_settings()
print '[' + str(datetime.now()) + '] Set daemon settings'
return 'Set' return 'Set'
def xmlrpc_start_fetcher(self): def xmlrpc_start_fetcher(self):
@ -438,7 +442,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
""" """
self.fetcher.start() self.fetcher.start()
print '[' + str(datetime.now()) + '] Start autofetcher'
return str('Started autofetching') return str('Started autofetching')
def xmlrpc_stop_fetcher(self): def xmlrpc_stop_fetcher(self):
@ -447,7 +451,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
""" """
self.fetcher.stop() self.fetcher.stop()
print '[' + str(datetime.now()) + '] Stop autofetcher'
return str('Started autofetching') return str('Started autofetching')
def xmlrpc_fetcher_status(self): def xmlrpc_fetcher_status(self):
@ -455,6 +459,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
Start autofetcher Start autofetcher
""" """
print '[' + str(datetime.now()) + '] Get fetcher status'
return str(self.fetcher.check_if_running()) return str(self.fetcher.check_if_running())
def xmlrpc_get_balance(self): def xmlrpc_get_balance(self):
@ -462,6 +467,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
Get LBC balance Get LBC balance
""" """
print '[' + str(datetime.now()) + '] Get balance'
return str(self.session.wallet.wallet_balance) return str(self.session.wallet.wallet_balance)
def xmlrpc_stop(self): def xmlrpc_stop(self):
@ -486,7 +492,24 @@ class LBRYDaemon(xmlrpc.XMLRPC):
@return: Managed LBRY files @return: Managed LBRY files
""" """
return [[str(i), str(dir(i))] for i in self.lbry_file_manager.lbry_files] r = []
for f in self.lbry_file_manager.lbry_files:
if f.key:
t = {'completed': f.completed, 'file_handle': f.file_handle, 'file_name': f.file_name,
'key': binascii.b2a_hex(f.key), 'points_paid': f.points_paid, 'stopped': f.stopped,
'stream_hash': f.stream_hash, 'stream_name': f.stream_name, 'suggested_file_name': f.suggested_file_name,
'upload_allowed': f.upload_allowed}
else:
t = {'completed': f.completed, 'file_handle': f.file_handle, 'file_name': f.file_name,
'key': None, 'points_paid': f.points_paid, 'stopped': f.stopped,
'stream_hash': f.stream_hash, 'stream_name': f.stream_name, 'suggested_file_name': f.suggested_file_name,
'upload_allowed': f.upload_allowed}
r.append(json.dumps(t))
print '[' + str(datetime.now()) + '] Get LBRY files'
return r
def xmlrpc_resolve_name(self, name): def xmlrpc_resolve_name(self, name):
""" """
@ -522,6 +545,7 @@ class LBRYDaemon(xmlrpc.XMLRPC):
except: except:
pass pass
print '[' + str(datetime.now()) + '] Get downloads'
return downloads return downloads
def xmlrpc_download_name(self, name): def xmlrpc_download_name(self, name):
@ -580,6 +604,11 @@ class LBRYDaemon(xmlrpc.XMLRPC):
d.addCallback(lambda path: self._add_to_history(name, path)) d.addCallback(lambda path: self._add_to_history(name, path))
return d return d
def xmlrpc_toggle_lbry_file_status(self, stream_hash):
d = self.lbry_file_manager.toggle_lbry_file_running(stream_hash)
d.addErrback(lambda err: str(err))
return d
def main(): def main():
daemon = LBRYDaemon() daemon = LBRYDaemon()

3
x.sh Executable file
View file

@ -0,0 +1,3 @@
python setup.py install
clear
lbrynet-daemon