]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/pages/torrent/__init__.py
3 TRACKER_URL
="http://tracker.ipfire.org:6969/stats?format=txt&mode=tpbs"
4 TORRENT_BASE
="/srv/pakfire/data/torrent"
10 from client
.bencode
import bencode
, bdecode
15 def __init__(self
, url
):
18 f
= urllib2
.urlopen(url
)
19 for line
in f
.readlines():
20 (hash, seeds
, peers
,) = line
.split(":")
21 self
.info
[hash] = (seeds
, peers
.rstrip("\n"),)
29 return self
.info
[hash]
35 def __init__(self
, file):
36 self
.name
= os
.path
.basename(file)
38 self
.info
= bdecode(f
.read())
42 print "File : %s" % self
.get_file()
43 print "Hash : %s" % self
.get_hash()
46 return sha
.sha(bencode(self
.info
["info"])).hexdigest().upper()
53 for file in os
.listdir(TORRENT_BASE
):
54 if not file.endswith(".torrent"):
56 file = os
.path
.join(TORRENT_BASE
, file)
57 torrent_files
.insert(0, TorrentObject(file))
60 tracker
= TrackerInfo(TRACKER_URL
)
62 class TorrentBox(web
.elements
.Box
):
63 def __init__(self
, file):
64 web
.elements
.Box
.__init
__(self
, file.name
, file.get_hash())
67 <strong>Seeders:</strong> %s<br />
68 <strong>Leechers:</strong> %s
69 </p>""" % tracker
.get(file.get_hash()))
71 <p style="text-align: right;">
72 <a href="http://download.ipfire.org/torrent/%s">Download</a>
73 </p>""" % (file.name
,))
76 class Content(web
.Content
):
78 web
.Content
.__init
__(self
)
81 self
.w("<h3>IPFire Torrent Tracker</h3>")
82 for t
in torrent_files
:
87 page
.content
= Content()
88 page
.sidebar
= web
.elements
.Sidebar()