def get_info_multi(self, view, sortby, reverse): # wanted: # system info # ratio, dl speed, ul speed, status torrentList = self.Handler.sortTorrents(self.RT.getTorrentList2(view), sortby, reverse) returnDict = { "torrents": {}, "system": system.generalHTML(), # "system" : base64.b64encode(system.generalHTML()), "torrent_index": [x.torrent_id for x in torrentList], } for t in torrentList: returnDict["torrents"][t.torrent_id] = { "ratio": "%.02f" % (float(t.ratio) / 1000), "uprate": self.Handler.humanSize(t.up_rate), "downrate": self.Handler.humanSize(t.down_rate), "status": self.Handler.getState(t), } return json.dumps(returnDict)
def get_info_multi(self, view, sortby, reverse): #wanted: # system info # ratio, dl speed, ul speed, status torrentList = self.Handler.sortTorrents(self.RT.getTorrentList2(view), sortby, reverse) returnDict = { "torrents": {}, "system": system.generalHTML(), #"system" : base64.b64encode(system.generalHTML()), "torrent_index": [x.torrent_id for x in torrentList], } for t in torrentList: returnDict["torrents"][t.torrent_id] = { "ratio": "%.02f" % (float(t.ratio) / 1000), "uprate": self.Handler.humanSize(t.up_rate), "downrate": self.Handler.humanSize(t.down_rate), "status": self.Handler.getState(t) } return json.dumps(returnDict)
def torrentHTML(self, torrentList, sort, view, reverse=None): """ Sorts a list of torrent_ids with default information Arguments: torrentList = list : rtorrent.Torrent objects sort = str : value to sort on reverse = boolean : reverse or not Sort Options: name, size, ratio, uprate, uptotal, downrate, downtotal, leechs, leechs_connected, leechs_total, seeds, seeds_connected, seeds_total, peers, peers_connected, peers_total, priority, status, tracker, created leechs, seeds, and peers are shorthand for leechs_connected, seeds_connected and peers_connected respectively """ sorts = { "name":"", "namesort" : "none", "size":"", "sizesort" : "none", "ratio":"", "ratiosort" : "none", "uprate" : "", "upratesort" : "none", "downrate" : "", "downratesort" : "none", "status" : "", "statussort" : "none", } for type in sorts.keys(): if type in self.SORT_METHODS: sorts[type] = "?view=%s&sortby=%s" % (view, type) if type == sort and not reverse: sorts[type] += "&reverse=1" if sort in sorts.keys(): if reverse: sorts[sort + "sort"] = "down" else: sorts[sort + "sort"] = "up" torrentList = self.sortTorrents(torrentList, sort, reverse) def _genHTML(type, VIEW): if VIEW == type: return '<div class="topbar-tab selected" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % (type, type, type.capitalize()) else: return '<div class="topbar-tab" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % (type, type, type.capitalize()) infoDict = { "main" : _genHTML("main", view), "started" : _genHTML("started", view), "stopped" : _genHTML("stopped", view), "complete" : _genHTML("complete", view), "incomplete" : _genHTML("incomplete", view), "hashing" : _genHTML("hashing", view), "seeding" : _genHTML("seeding", view), "active" : _genHTML("active", view), "global_stats" : system.generalHTML(), "view" : view, "sort" : sort, "reverse" : (lambda x : not x and 'none' or x)(reverse), "torrents_html" : "\n".join([self.getTorrentRow(t) for t in torrentList]), } infoDict.update(sorts) HTML = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <!-- HEAD PLACEHOLDER --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>rTorrent - webUI</title> <link rel="stylesheet" type="text/css" href="/css/main.css"> <link rel="stylesheet" type="text/css" href="/css/smoothness/jquery-ui-1.8.13.custom.css"> <script src="/javascript/jquery-1.6.1.min.js" type="text/javascript"></script> <script src="/javascript/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script> <script src="/javascript/jquery.contextmenu.r2.js" type="text/javascript"></script> <script src="/javascript/jquery-sliderow.js" type="text/javascript"></script> <script src="/javascript/main.js" type="text/javascript"></script> </head> <body> <div id="header"> <div id="topbar"> %(main)s %(started)s %(stopped)s %(complete)s %(incomplete)s %(hashing)s %(seeding)s %(active)s <div id="tools-bar"> <div class="topbar-tab_options" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" title="Options" id="tab_options">Options</div> <div class="topbar-tab_options" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" title="RSS" id="tab_rss">RSS</div> </div> </div> <div id="actions-bar"> <a href="#" id="add-torrent-button">Add torrent</a> </div> </div> <div id="main_body"> <div id="wrapper"> <div id="add_torrent" style="display: none" title="Add a torrent"> <form id="add_torrent_form" action="ajax" method="post" enctype="multipart/form-data"> <label>Select file:</label> <input type="hidden" name="request" value="upload_torrent"> <input id="add_torrent_input" accept="application/x-bittorrent" type="file" name="torrent"> <div class="add_torrent_start_text"> <input id="add_torrent_start" type="checkbox" name="start"> Start Immediately? </div> </form> </div> <div id="global_stats"> %(global_stats)s </div> <div id="this_view" class="hidden">%(view)s</div> <div id="this_sort" class="hidden">%(sort)s</div> <div id="this_reverse" class="hidden">%(reverse)s</div> <div id="torrent_table"> <table id='torrent_list'> <tr id='torrent_list_headings'> <td class='heading' id="sortby_name" onclick="window.location='%(name)s';">Name <img alt="Sort By Name" src="../images/sort_%(namesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_size" onclick="window.location='%(size)s';">Size <img alt="Sort By Size" src="../images/sort_%(sizesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_ratio" onclick="window.location='%(ratio)s';">Ratio <img alt="Sort By Ratio" src="../images/sort_%(ratiosort)s.gif" class="control_button"></td> <td class='heading' id="sortby_uprate" onclick="window.location='%(uprate)s';">Upload speed <img alt="Sort By Upload Speed" src="../images/sort_%(upratesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_downrate" onclick="window.location='%(downrate)s';">Download speed <img alt="Sort By Download Speed" src="../images/sort_%(downratesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_status" onclick="window.location='%(status)s';">Status <img alt="Sort By Status" src="../images/sort_%(statussort)s.gif" class="control_button"></td> <td class='heading'></td> </tr> %(torrents_html)s <tr id='foot'> <td class='footing' colspan="7"></td> </tr> </table> </div> <div class="contextMenu" id="right_click_start"> <ul> <li id="start"><img alt="start" src="/images/start.png"> Start</li> <li id="stop"><img alt="stop" src="/images/stop.png"> Stop</li> <li id="remove"><img alt="remove" src="/images/remove.png"> Remove and <strong>keep</strong> files</li> <li id="delete"><img alt="delete" src="/images/delete.png"> Remove and <strong>delete</strong> files</li> <li id="rehash"><img alt="rehash" src="/images/hash.png"> Rehash</li> </ul> </div> <div class="contextMenu" id="right_click_pause"> <ul> <li id="pause"><img alt="pause" src="/images/pause.png"> Pause</li> <li id="stop"><img alt="stop" src="/images/stop.png"> Stop</li> <li id="remove"><img alt="remove" src="/images/remove.png"> Remove and <strong>keep</strong> files</li> <li id="delete"><img alt="delete" src="/images/delete.png"> Remove and <strong>delete</strong> files</li> <li id="rehash"><img alt="rehash" src="/images/hash.png"> Rehash</li> </ul> </div> </div> </div> </body> </html> """ % infoDict return HTML
def index(self, password=None, view=None, sortby=None, reverse=None): if not view or view not in ["main","started","stopped","complete","incomplete","hashing","seeding","active"]: view = "main" if not sortby: sortby = "none" Config = config.Config() RT = rtorrent.rtorrent(Config.get("rtorrent_socket")) handler = torrentHandler.Handler() torrentList = RT.getTorrentList2(view) html = handler.torrentHTML(torrentList, sortby, view, reverse) def genHTML(type, VIEW): if VIEW == type: return '<div class="topbar-tab selected" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % (type, type, type.capitalize()) else: return '<div class="topbar-tab" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % (type, type, type.capitalize()) ttmain = genHTML("main", view) ttstarted = genHTML("started",view) ttstopped = genHTML("stopped",view) ttcomplete = genHTML("complete",view) ttincomplete = genHTML("incomplete",view) tthashing = genHTML("hashing",view) ttseeding = genHTML("seeding",view) ttactive = genHTML("active",view) if not reverse: reverse = "none" else: reverse = "true" html_insert = """ <div id="header"> <div id="topbar"> %(main)s %(started)s %(stopped)s %(complete)s %(incomplete)s %(hashing)s %(seeding)s %(active)s <div id="tools-bar"> <div class="topbar-tab_options" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" onclick="navigate_options(this);" title="Options" id="tab_options">Options</div> </div> </div> <div id="actions-bar"> <a href="#" id="add-torrent-button">Add torrent</a> </div> </div> <div id="main_body"> <div id="wrapper"> <div id="add_torrent" style="display: none" title="Add a torrent"> <form id="add_torrent_form" action="upload_torrent" method="post" enctype="multipart/form-data"> <label>Select file:</label> <input id="add_torrent_input" accept="application/x-bittorrent" type="file" name="torrent"> <div class="add_torrent_start_text"> <input id="add_torrent_start" type="checkbox" name="start"> Start Immediately? </div> </form> </div> <div id="global_stats"> %(global_stats)s </div> <button class="hidden" onclick="refresh_content();">Click!</button> <div id="this_view" class="hidden">%(view)s</div> <div id="this_sort" class="hidden">%(sortby)s</div> <div id="this_reverse" class="hidden">%(reverse)s</div> """ % { "main" : ttmain, "started" : ttstarted, "stopped" : ttstopped, "complete" : ttcomplete, "incomplete" : ttincomplete, "hashing" : tthashing, "seeding" : ttseeding, "active" : ttactive, "global_stats" : system.generalHTML(), "view" : view, "sortby" : sortby, "reverse" : reverse, } return html.replace("<!-- BODY PLACEHOLDER -->",html_insert).replace("</body>","</div></div>\n\t</body>")
def torrentHTML(self, torrentList, sort, view, reverse=None): """ Sorts a list of torrent_ids with default information Arguments: torrentList = list : rtorrent.Torrent objects sort = str : value to sort on reverse = boolean : reverse or not Sort Options: name, size, ratio, uprate, uptotal, downrate, downtotal, leechs, leechs_connected, leechs_total, seeds, seeds_connected, seeds_total, peers, peers_connected, peers_total, priority, status, tracker, created leechs, seeds, and peers are shorthand for leechs_connected, seeds_connected and peers_connected respectively """ sorts = { "name": "", "namesort": "none", "size": "", "sizesort": "none", "ratio": "", "ratiosort": "none", "uprate": "", "upratesort": "none", "downrate": "", "downratesort": "none", "status": "", "statussort": "none", } for type in sorts.keys(): if type in self.SORT_METHODS: sorts[type] = "?view=%s&sortby=%s" % (view, type) if type == sort and not reverse: sorts[type] += "&reverse=1" if sort in sorts.keys(): if reverse: sorts[sort + "sort"] = "down" else: sorts[sort + "sort"] = "up" torrentList = self.sortTorrents(torrentList, sort, reverse) def _genHTML(type, VIEW): if VIEW == type: return '<div class="topbar-tab selected" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % ( type, type, type.capitalize()) else: return '<div class="topbar-tab" onclick="navigate_tab(this);" title="%s" id="tab_%s">%s</div>' % ( type, type, type.capitalize()) infoDict = { "main": _genHTML("main", view), "started": _genHTML("started", view), "stopped": _genHTML("stopped", view), "complete": _genHTML("complete", view), "incomplete": _genHTML("incomplete", view), "hashing": _genHTML("hashing", view), "seeding": _genHTML("seeding", view), "active": _genHTML("active", view), "global_stats": system.generalHTML(), "view": view, "sort": sort, "reverse": (lambda x: not x and 'none' or x)(reverse), "torrents_html": "\n".join([self.getTorrentRow(t) for t in torrentList]), } infoDict.update(sorts) HTML = """ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <!-- HEAD PLACEHOLDER --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> <title>rTorrent - webUI</title> <link rel="stylesheet" type="text/css" href="/css/main.css"> <link rel="stylesheet" type="text/css" href="/css/smoothness/jquery-ui-1.8.13.custom.css"> <script src="/javascript/jquery-1.6.1.min.js" type="text/javascript"></script> <script src="/javascript/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script> <script src="/javascript/jquery.contextmenu.r2.js" type="text/javascript"></script> <script src="/javascript/jquery-sliderow.js" type="text/javascript"></script> <script src="/javascript/main.js" type="text/javascript"></script> </head> <body> <div id="header"> <div id="topbar"> %(main)s %(started)s %(stopped)s %(complete)s %(incomplete)s %(hashing)s %(seeding)s %(active)s <div id="tools-bar"> <div class="topbar-tab_options" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" title="Options" id="tab_options">Options</div> <div class="topbar-tab_options" onmouseover="select_tab(this);" onmouseout="deselect_tab(this);" title="RSS" id="tab_rss">RSS</div> </div> </div> <div id="actions-bar"> <a href="#" id="add-torrent-button">Add torrent</a> </div> </div> <div id="main_body"> <div id="wrapper"> <div id="add_torrent" style="display: none" title="Add a torrent"> <form id="add_torrent_form" action="ajax" method="post" enctype="multipart/form-data"> <label>Select file:</label> <input type="hidden" name="request" value="upload_torrent"> <input id="add_torrent_input" accept="application/x-bittorrent" type="file" name="torrent"> <div class="add_torrent_start_text"> <input id="add_torrent_start" type="checkbox" name="start"> Start Immediately? </div> </form> </div> <div id="global_stats"> %(global_stats)s </div> <div id="this_view" class="hidden">%(view)s</div> <div id="this_sort" class="hidden">%(sort)s</div> <div id="this_reverse" class="hidden">%(reverse)s</div> <div id="torrent_table"> <table id='torrent_list'> <tr id='torrent_list_headings'> <td class='heading' id="sortby_name" onclick="window.location='%(name)s';">Name <img alt="Sort By Name" src="../images/sort_%(namesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_size" onclick="window.location='%(size)s';">Size <img alt="Sort By Size" src="../images/sort_%(sizesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_ratio" onclick="window.location='%(ratio)s';">Ratio <img alt="Sort By Ratio" src="../images/sort_%(ratiosort)s.gif" class="control_button"></td> <td class='heading' id="sortby_uprate" onclick="window.location='%(uprate)s';">Upload speed <img alt="Sort By Upload Speed" src="../images/sort_%(upratesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_downrate" onclick="window.location='%(downrate)s';">Download speed <img alt="Sort By Download Speed" src="../images/sort_%(downratesort)s.gif" class="control_button"></td> <td class='heading' id="sortby_status" onclick="window.location='%(status)s';">Status <img alt="Sort By Status" src="../images/sort_%(statussort)s.gif" class="control_button"></td> <td class='heading'></td> </tr> %(torrents_html)s <tr id='foot'> <td class='footing' colspan="7"></td> </tr> </table> </div> <div class="contextMenu" id="right_click_start"> <ul> <li id="start"><img alt="start" src="/images/start.png"> Start</li> <li id="stop"><img alt="stop" src="/images/stop.png"> Stop</li> <li id="remove"><img alt="remove" src="/images/remove.png"> Remove and <strong>keep</strong> files</li> <li id="delete"><img alt="delete" src="/images/delete.png"> Remove and <strong>delete</strong> files</li> <li id="rehash"><img alt="rehash" src="/images/hash.png"> Rehash</li> </ul> </div> <div class="contextMenu" id="right_click_pause"> <ul> <li id="pause"><img alt="pause" src="/images/pause.png"> Pause</li> <li id="stop"><img alt="stop" src="/images/stop.png"> Stop</li> <li id="remove"><img alt="remove" src="/images/remove.png"> Remove and <strong>keep</strong> files</li> <li id="delete"><img alt="delete" src="/images/delete.png"> Remove and <strong>delete</strong> files</li> <li id="rehash"><img alt="rehash" src="/images/hash.png"> Rehash</li> </ul> </div> </div> </div> </body> </html> """ % infoDict return HTML