def add_torrent_page(target): if request.method == 'POST': if 'torrent_file' in request.files: torrent_raw = request.files['torrent_file'].read() torrent_raw_bin = xmlrpclib.Binary(torrent_raw) rtorrent = RTorrent(target) return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin) elif 'torrent_url' in request.form: torrent_url = request.form['torrent_url'] response = urllib2.urlopen(torrent_url) torrent_raw = response.read() torrent_raw_bin = xmlrpclib.Binary(torrent_raw) rtorrent = RTorrent(target) return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin) elif 'magnet' in request.form: magnet_link = request.form['magnet'] torrent = 'd10:magnet-uri' + str(len(magnet_link)) + ':' + magnet_link + 'e' rtorrent = RTorrent(target) return_code = rtorrent.add_torrent_raw(torrent) flash('Succesfully added torrent' if return_code == 0 else 'Failed to add torrent') rtorrent_data = fetch_global_info() return pyro_render_template('torrent_add.html', rtorrent_data=rtorrent_data, target=target['name'])
def main_view_page(env, view): """ Main page. Shows all torrents, per target. Does two XMLRPC calls per target. """ if not loggedin_and_require(env): return handle_login(env) rtorrent_data = fetch_global_info() user = fetch_user(env) # if view not in rtorrent_data.get_view_list: # return error_page(env, 'Invalid view: %s' % view) torrents = {} for target in targets: if user == None and USE_AUTH: continue if user and (target['name'] not in user.targets): continue try: t = TorrentRequester(target, view) t.get_name().get_download_rate().get_upload_rate() \ .is_complete().get_size_bytes().get_download_total().get_hash() torrents[target['name']] = t.all() except InvalidTorrentException, e: return error_page(env, str(e))
def add_torrent_page(target): if request.method == 'POST': if 'torrent_file' in request.files: torrent_raw = request.files['torrent_file'].read() torrent_raw_bin = xmlrpclib.Binary(torrent_raw) rtorrent = RTorrent(target) return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin) elif 'torrent_url' in request.form: torrent_url = request.form['torrent_url'] response = urllib2.urlopen(torrent_url) torrent_raw = response.read() torrent_raw_bin = xmlrpclib.Binary(torrent_raw) rtorrent = RTorrent(target) return_code = rtorrent.add_torrent_raw_start(torrent_raw_bin) elif 'magnet' in request.form: magnet_link = request.form['magnet'] torrent = 'd10:magnet-uri' + str( len(magnet_link)) + ':' + magnet_link + 'e' rtorrent = RTorrent(target) return_code = rtorrent.add_torrent_raw(torrent) flash('Succesfully added torrent' if return_code == 0 else 'Failed to add torrent') rtorrent_data = fetch_global_info() return pyro_render_template('torrent_add.html', rtorrent_data=rtorrent_data, target=target['name'])
def pyroTorrentApp(env, start_response): """ pyroTorrent main function. """ # Log here if you want r = wt.apply_rule(env['PATH_INFO'], env) # 404 if r is None: start_response('404 Not Found', [('Content-Type', 'text/html')]) tmpl = jinjaenv.get_template('404.html') rtorrent_data = fetch_global_info() return template_render(tmpl, env, {'url' : env['PATH_INFO'], 'rtorrent_data' : rtorrent_data}) elif type(r) in (tuple, list) and len(r) == 3: # Respond with custom headers start_response(r[0], r[1]) r = r[2] # 200 else: start_response('200 OK', [('Content-Type', 'text/html;charset=utf8')]) # Response data # If r is not a file, but a string # prevent an exhausting loop if type(r) == str: return [r] return r
def main_view_page(view='default'): rtorrent_data = fetch_global_info() # if view not in rtorrent_data.get_view_list: # return error_page(env, 'Invalid view: %s' % view) torrents = {} for target in targets: if g.user == None and USE_AUTH: continue if g.user and (target['name'] not in g.user.targets): continue try: t = TorrentRequester(target, view) t.get_name().get_download_rate().get_upload_rate() \ .is_complete().get_size_bytes().get_download_total().get_hash() h = hash(t) torrents[target['name']] = cache.get(h) if torrents[target['name']]: continue torrents[target['name']] = cache.get(target['name']) if torrents[target['name']] is not None: continue torrents[target['name']] = t.all() cache.set(h, torrents[target['name']], timeout=CACHE_TIMEOUT) except InvalidTorrentException, e: return error_page(env, str(e))
get_loaded_file().get_message().is_active() torrentinfo = q.all()[0] # .first() ? except InvalidTorrentException, e: return error_page(env, str(e)) # FIXME THIS IS UGLY files = TorrentFileRequester(target, torrent._hash, '')\ .get_path_components().all() files = map(lambda x: x['get_path_components'], files) tree = FileTree(files).root rtorrent_data = fetch_global_info() tmpl = jinjaenv.get_template('torrent_info.html') return template_render(tmpl, env, {'torrent' : torrentinfo, 'tree' : tree, 'rtorrent_data' : rtorrent_data, 'target' : target, 'file_downloads' : target.has_key('storage_mode')}) @webtool_callback @require_target def add_torrent_page(env, target): """ Page for adding torrents. Works: Adding a correct torrent (URL only) What doesn't work: Error handling,
p.get_address().get_client_version().is_encrypted().get_id() peers = p.all() files = TorrentFileRequester(target, torrent._hash)\ .get_path_components().get_size_chunks().get_completed_chunks() h = hash(files) f = cache.get(h) if f is None: f = files.all() cache.set(h, f, CACHE_TIMEOUT) tree = FileTree(f).root rtorrent_data = fetch_global_info() return pyro_render_template( 'torrent_info.html', torrent=torrentinfo, tree=tree, rtorrent_data=rtorrent_data, target=target, file_downloads=target.has_key('storage_mode'), peers=peers # TODO FIX ME , wn=wiz_normalise)