12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #! /usr/bin/env python
-
- from __future__ import print_function
- import sys
- import time
- import glob
- import torrentfile
- import torrentmanager
- import config
-
- def warning(*objs):
- print(time.strftime("%d/%m/%Y %H:%M:%S"), "WARNING:", *objs, file=sys.stderr)
-
- def debug(*objs):
- print(time.strftime("%d/%m/%Y %H:%M:%S"), *objs)
-
- if len(sys.argv) >= 2:
- config = config.Config(sys.argv[1])
- else:
- config = config.Config()
-
- maxRatio = config.getMaxRatio()
- maxRate = config.getMaxRate()
- torrentsPath = config.getTorrentsPath()
-
- print("Max ratio:", maxRatio)
- print("Max rate:", maxRate, "kb/s")
- print("Torrents path:", torrentsPath)
-
- manager = torrentmanager.TorrentManager(maxRatio, maxRate)
- run = True
- while run:
- for file in glob.glob(torrentsPath + "/*.torrent"):
- try:
- torrent = torrentfile.TorrentFile()
- torrent.readFile(file)
- if not any(x.getName() == torrent.getName()
- for x in manager.getTorrents()):
- debug("Found", torrent.getName())
- torrent.getTracker().start()
- manager.appendTorrent(torrent)
- except:
- warning("could not load or start", file)
-
- count = len(manager.getTorrents())
-
- if count == 0:
- warning("could not find/load/start any torrent. Waiting 5 minutes")
- time.sleep(300)
- continue
-
- t = manager.getNextTime()
- torrent = t['torrent']
- secs = t['time']
- if secs > 0:
- debug(torrent.getName() + ": Next update in " + str(secs) + " seconds")
- time.sleep(secs)
- debug("Updating", torrent.getName(),
- "ratio =", (torrent.getTracker().getUploaded() / float(torrent.getSize())))
- try:
- manager.updateTorrent()
- except:
- warning("could not update")
|