You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fake-tracker.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /usr/bin/env python
  2. from __future__ import print_function
  3. import sys
  4. import time
  5. import glob
  6. import torrentfile
  7. import torrentmanager
  8. import config
  9. def warning(*objs):
  10. print("WARNING:", *objs, file=sys.stderr)
  11. if len(sys.argv) >= 2:
  12. config = config.Config(sys.argv[1])
  13. else:
  14. config = config.Config()
  15. maxRatio = config.getMaxRatio()
  16. maxRate = config.getMaxRate()
  17. torrentsPath = config.getTorrentsPath()
  18. print("Max ratio:", maxRatio)
  19. print("Max rate:", maxRate, "kb/s")
  20. print("Torrents path:", torrentsPath)
  21. manager = torrentmanager.TorrentManager(maxRatio, maxRate)
  22. run = True
  23. while run:
  24. for file in glob.glob(torrentsPath + "/*.torrent"):
  25. try:
  26. torrent = torrentfile.TorrentFile()
  27. torrent.readFile(file)
  28. if not any(x.getName() == torrent.getName()
  29. for x in manager.getTorrents()):
  30. print("Found", torrent.getName())
  31. torrent.getTracker().start()
  32. manager.appendTorrent(torrent)
  33. except:
  34. warning("could not load or start", file)
  35. count = len(manager.getTorrents())
  36. if count == 0:
  37. warning("could not find/load/start any torrent. Waiting 5 minutes")
  38. time.sleep(300)
  39. continue
  40. t = manager.getNextTime()
  41. torrent = t['torrent']
  42. secs = t['time']
  43. if secs > 0:
  44. print(torrent.getName() + ": Next update in " + str(secs) + " seconds")
  45. time.sleep(secs)
  46. print("Updating", torrent.getName(),
  47. "ratio =", (torrent.getTracker().getUploaded() / float(torrent.getSize())))
  48. try:
  49. manager.updateTorrent()
  50. except:
  51. warning("could not update")