def retrieve_from_magnet(url, callback, timeout=30.0, max_connections=30.0): """ If the URL conforms to a magnet link, the .torrent info is downloaded and converted into a TorrentDef. The resulting TorrentDef is provided through CALLBACK. Returns True when attempting to obtain the TorrentDef, in this case CALLBACK will always be called. Otherwise False is returned, in this case CALLBACK will not be called. The thread making the callback should be used very briefly. """ assert isinstance(url, str), "URL has invalid type: %s" % type(url) assert callable(callback), "CALLBACK must be callable" def metainfo_retrieved(metadata): tdef = TorrentDef.load_from_dict(metadata) callback(tdef) LibtorrentMgr.getInstance().get_metainfo(url, metainfo_retrieved, timeout) return True
def lookup(self, infohash): if DEBUG: print >> sys.stderr, "mainlineDHTChecker: Lookup", repr(infohash) try: from Tribler.Core.Libtorrent.LibtorrentMgr import LibtorrentMgr LibtorrentMgr.getInstance().get_peers(infohash, self.got_peers_callback) except: print >> sys.stderr, "mainlineDHTChecker: No lookup, libtorrent not loaded"
def lookup(self, infohash): if DEBUG: print >> sys.stderr, "mainlineDHTChecker: Lookup", repr(infohash) try: from Tribler.Core.Libtorrent.LibtorrentMgr import LibtorrentMgr LibtorrentMgr.getInstance().get_peers(infohash, self.got_peers_callback) except: print >> sys.stderr, "mainlineDHTChecker: No lookup, libtorrent not loaded"
def do_supply(): # supply fake addresses (regular dht obviously wont work here) ltmgr = LibtorrentMgr.getInstance() for infohash in ltmgr.metainfo_requests: handle = ltmgr.ltsession.find_torrent( lt.big_number(infohash.decode('hex'))) handle.connect_peer(("127.0.0.1", LISTEN_PORT), 0)
def __init__(self, session, tdef): self.dllock = NoDispersyRLock() self.session = session self.tdef = tdef self.handle = None # Just enough so error saving and get_state() works self.error = None # To be able to return the progress of a stopped torrent, how far it got. self.progressbeforestop = 0.0 self.filepieceranges = [] # Libtorrent session manager performing the actual download. self.ltmgr = LibtorrentMgr.getInstance() # Libtorrent status self.dlstates = [DLSTATUS_WAITING4HASHCHECK, DLSTATUS_HASHCHECKING, DLSTATUS_DOWNLOADING, DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING, DLSTATUS_SEEDING, DLSTATUS_ALLOCATING_DISKSPACE, DLSTATUS_HASHCHECKING] self.dlstate = DLSTATUS_WAITING4HASHCHECK self.length = 0L self.progress = 0.0 self.curspeeds = {DOWNLOAD:0.0,UPLOAD:0.0} # bytes/s self.done = False self.pause_after_next_hashcheck = False self.prebuffsize = 5*1024*1024 self.queue_position = -1 self.vod_readpos = 0 self.vod_pausepos = 0 self.vod_status = "" self.lm_network_vod_event_callback = None self.pstate_for_restart = None self.cew_scheduled = False
def __init__(self): RateManager.__init__(self) self.global_max_speed = {} self.global_max_speed[UPLOAD] = 0.0 self.global_max_speed[DOWNLOAD] = 0.0 self.global_max_seedupload_speed = 0.0 self.ltmgr = LibtorrentMgr.getInstance()
def setMaxDown(self, valdown): libtorrentmgr = LibtorrentMgr.getInstance() if valdown == 'unlimited': libtorrentmgr.set_download_rate_limit(-1) self.config.Write('maxdownloadrate', '0') else: libtorrentmgr.set_download_rate_limit(int(valdown)*1024) self.config.Write('maxdownloadrate', valdown)
def setMaxDown(self, valdown): libtorrentmgr = LibtorrentMgr.getInstance() if valdown == 'unlimited': libtorrentmgr.set_download_rate_limit(-1) self.config.Write('maxdownloadrate', '0') else: libtorrentmgr.set_download_rate_limit(int(valdown)*1024) self.config.Write('maxdownloadrate', valdown)
def retrieve_from_magnet(url, callback, timeout=30.0, max_connections=30.0): """ If the URL conforms to a magnet link, the .torrent info is downloaded and converted into a TorrentDef. The resulting TorrentDef is provided through CALLBACK. Returns True when attempting to obtain the TorrentDef, in this case CALLBACK will always be called. Otherwise False is returned, in this case CALLBACK will not be called. The thread making the callback should be used very briefly. """ assert isinstance(url, str), "URL has invalid type: %s" % type(url) assert callable(callback), "CALLBACK must be callable" def metainfo_retrieved(metadata): tdef = TorrentDef.load_from_dict(metadata) callback(tdef) LibtorrentMgr.getInstance().get_metainfo(url, metainfo_retrieved, timeout) return True
def setMaxUp(self, valup): libtorrentmgr = LibtorrentMgr.getInstance() if valup == 'unlimited': libtorrentmgr.set_upload_rate_limit(-1) self.config.Write('maxuploadrate', '0') self.config.Write('maxseeduploadrate', '0') elif valup == '0': libtorrentmgr.set_upload_rate_limit(0.0001) self.config.Write('maxuploadrate', '-1') self.config.Write('maxseeduploadrate', '-1') else: libtorrentmgr.set_upload_rate_limit(int(valup)*1024) self.config.Write('maxuploadrate', valup) self.config.Write('maxseeduploadrate', valup)
def setMaxUp(self, valup): libtorrentmgr = LibtorrentMgr.getInstance() if valup == 'unlimited': libtorrentmgr.set_upload_rate_limit(-1) self.config.Write('maxuploadrate', '0') self.config.Write('maxseeduploadrate', '0') elif valup == '0': libtorrentmgr.set_upload_rate_limit(0.0001) self.config.Write('maxuploadrate', '-1') self.config.Write('maxseeduploadrate', '-1') else: libtorrentmgr.set_upload_rate_limit(int(valup)*1024) self.config.Write('maxuploadrate', valup) self.config.Write('maxseeduploadrate', valup)
def __init__(self, session, tdef): self.dllock = NoDispersyRLock() self.session = session self.tdef = tdef self.handle = None # Just enough so error saving and get_state() works self.error = None # To be able to return the progress of a stopped torrent, how far it got. self.progressbeforestop = 0.0 self.filepieceranges = [] # Libtorrent session manager self.ltmgr = LibtorrentMgr.getInstance() # Libtorrent status self.dlstates = [DLSTATUS_WAITING4HASHCHECK, DLSTATUS_HASHCHECKING, DLSTATUS_METADATA, DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING, DLSTATUS_SEEDING, DLSTATUS_ALLOCATING_DISKSPACE, DLSTATUS_HASHCHECKING] self.dlstate = DLSTATUS_WAITING4HASHCHECK self.length = 0L self.progress = 0.0 self.bufferprogress = 0.0 self.curspeeds = {DOWNLOAD:0.0,UPLOAD:0.0} # bytes/s self.all_time_upload = 0.0 self.all_time_download = 0.0 self.finished_time = 0.0 self.done = False self.pause_after_next_hashcheck = False self.checkpoint_after_next_hashcheck = False self.prebuffsize = 5*1024*1024 self.queue_position = -1 self.vod_readpos = 0 self.vod_pausepos = 0 self.vod_status = "" self.lm_network_vod_event_callback = None self.pstate_for_restart = None self.cew_scheduled = False
def do_supply(): # supply fake addresses (regular dht obviously wont work here) ltmgr = LibtorrentMgr.getInstance() for infohash in ltmgr.metainfo_requests: handle = ltmgr.ltsession.find_torrent(lt.big_number(infohash.decode('hex'))) handle.connect_peer(("127.0.0.1", LISTEN_PORT), 0)