#!/usr/bin/env python # The contents of this file are subject to the BitTorrent Open Source License # Version 1.0 (the License). You may not copy or use this file, in either # source code or executable form, except in compliance with the License. You # may obtain a copy of the License at http://www.bittorrent.com/license/. # # Software distributed under the License is distributed on an AS IS basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the # License. # Derived from original btlaunchmany.py, written by John Hoffman # btlaunchmanyrss.py written by Davin Potts # This file is meant to supplement the functionality already present in # Bram Cohen's BitTorrent package. To install and use, place this file # in the same directory where the original btlaunchmany.py has been # installed. Also, obtain RSS.py from http://www.python.org/moin/RssLibraries # and place it in a directory in your PYTHONPATH (please note RSS.py's # dependency on PyXML being installed as well). To run, invoke # btlaunchmanyrss.py in the same way that you invoke its predecessors. What # you do with the RSS feed this code produces is up to you but some # suggestions include importing as a Live Bookmark into Firefox, importing # into your favourite RSS newsfeed reader, or coupling it to the # XMLHttpRequest-RSS-BitTorrent Demo developed for use with this code # (see http://discontinuity.net/projects/xmlhttprequest_rss_bittorrent). import sys import os # Depends upon RSS.py available as part of the RssLibraries tools. import RSS # Depends upon helpful formatting routines from btlaunchmanycurses.py. from btlaunchmanycurses import fmtsize, fmttime, rjust from BitTorrent.launchmanycore import LaunchMany from BitTorrent.defaultargs import get_defaults from BitTorrent.parseargs import parseargs, printHelp from BitTorrent import configfile from BitTorrent import version from BitTorrent import BTFailure exceptions = [] class RSSDisplayer: rdf_filename = "bt.rdf" # Would be more interesting if this pointed to something meaningful, # but for the moment this merely provides a unique link for purposes # of cross-reference in the RSS produced below. rdf_urlbase = 'http://discontinuity.net/projects/bt_status' rdf_urltail = '.html' def display(self, data): print '' tc = RSS.TrackingChannel() tc.setMD( (RSS.ns.rss10, "channel"), {(RSS.ns.rss10, "link"): self.rdf_filename, (RSS.ns.rss10, "title"): "Local BitTorrent Files"} ) if not data: self.message('no torrents') index = 0 for x in data: ( name, status, progress, peers, seeds, seedsmsg, dist, uprate, dnrate, upamt, dnamt, size, t, msg ) = x t = fmttime(t) if not t: t = status size = rjust(fmtsize(size),8) uprate = rjust('%s/s' % fmtsize(uprate),10) dnrate = rjust('%s/s' % fmtsize(dnrate),10) tc.addItem( { (RSS.ns.dc, "date"): '2005-01-01', (RSS.ns.rss10, "title"): '%s (%s) %sP%s%s%.3fD up%s-dn%s up%dK-dn%dK "%s" : "%s"' % ( status, progress, peers, seeds, seedsmsg, dist, uprate, dnrate, upamt/1024, dnamt/1024, msg, name ), (RSS.ns.rss10, "link"): '%s.%d%s' % ( self.rdf_urlbase, index, self.rdf_urltail), (RSS.ns.rss10, "description"): "%s %s (%s) %s - %s peers %s seeds %s dist copies - %s up %s dn" % ( name, size, progress, t, peers, seeds, dist, fmtsize(upamt), fmtsize(dnamt)) } ) index += 1 try: outfile = open( self.rdf_filename, 'w' ) itemlist = tc.listItems() outfile.write( tc.output(itemlist) ) outfile.close() except: self.message('attempt failed to write out rss feed') return False def message(self, s): print "### "+s def exception(self, s): exceptions.append(s) self.message('SYSTEM ERROR - EXCEPTION GENERATED') if __name__ == '__main__': uiname = 'btlaunchmany' defaults = get_defaults(uiname) try: if len(sys.argv) < 2: printHelp(uiname, defaults) sys.exit(1) config, args = configfile.parse_configuration_and_args(defaults, uiname, sys.argv[1:], 0, 1) if args: config['torrent_dir'] = args[0] if not os.path.isdir(config['torrent_dir']): raise BTFailure("Warning: "+args[0]+" is not a directory") except BTFailure, e: print 'error: ' + str(e) + '\nrun with no args for parameter explanations' sys.exit(1) LaunchMany(config, RSSDisplayer(), 'btlaunchmanyrss') if exceptions: print '\nEXCEPTION:' print exceptions[0]