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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. manager = torrentmanager.TorrentManager(maxRatio, maxRate)
  19. run = True
  20. while run:
  21. for file in glob.glob(torrentsPath + "/*.torrent"):
  22. try:
  23. torrent = torrentfile.TorrentFile()
  24. torrent.readFile(file)
  25. if not any(x.getName() == torrent.getName()
  26. for x in manager.getTorrents()):
  27. print("Found", torrent.getName())
  28. torrent.getTracker().start()
  29. manager.appendTorrent(torrent)
  30. except:
  31. warning("could not load or start", file)
  32. count = len(manager.getTorrents())
  33. if count == 0:
  34. warning("could not find/load/start any torrent. Waiting 5 minutes")
  35. time.sleep(300)
  36. continue
  37. t = manager.getNextTime()
  38. torrent = t['torrent']
  39. secs = t['time']
  40. if secs > 0:
  41. print(torrent.getName() + ": Next update in " + str(secs) + " seconds")
  42. time.sleep(secs)
  43. print("Updating", torrent.getName())
  44. try:
  45. manager.updateTorrent(torrent)
  46. except:
  47. warning("could not update")