def get_peerlist(self): key = 'get_peerlist_%s' % self.info_hash peerlist = mc.get(key) if peerlist is None: peerlist = ''.join( [binascii.unhexlify(peer.split(':')[2]) for peer in self.find_peers()] ) mc.set(key, peerlist, INTERVAL) return peerlist
def get_torrents(): """ Returns a list of all torrent objects currently stored in the database. """ key = 'get_torrents' torrents = mc.get(key) if torrents is None: torrents = [db.Torrent(key.lstrip('!')) for key in db.client.keys('!*')] mc.set(key, torrents, INTERVAL) return torrents
def torrent_info(request): info_hash = request.args.get('id') key = 'torrent_info_%s' % info_hash interval = 2400 information = mc.get(key) if information is None: information = list(db.database.view( 'torrent_info_detailed/by_info_hash' )[info_hash])[0].value mc.set(key, information, interval) return information
def scrapedict(torrent): key = 'scrapedict_%s' % torrent.info_hash scrape = mc.get(key) if scrape is None: scrape = { torrent.binary_hash(): { 'complete': len(torrent.find_peers(status='seed')), 'downloaded': torrent.completed(), 'incomplete': len(torrent.find_peers(status='leech')), }, } mc.set(key, scrape, INTERVAL) return scrape