Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

fake-tracker.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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(time.strftime("%d/%m/%Y %H:%M:%S"), "WARNING:", *objs, file=sys.stderr)
  11. def debug(*objs):
  12. print(time.strftime("%d/%m/%Y %H:%M:%S"), *objs)
  13. if len(sys.argv) >= 2:
  14. config = config.Config(sys.argv[1])
  15. else:
  16. config = config.Config()
  17. maxRatio = config.getMaxRatio()
  18. maxRate = config.getMaxRate()
  19. torrentsPath = config.getTorrentsPath()
  20. print("Max ratio:", maxRatio)
  21. print("Max rate:", maxRate, "kb/s")
  22. print("Torrents path:", torrentsPath)
  23. manager = torrentmanager.TorrentManager(maxRatio, maxRate)
  24. run = True
  25. while run:
  26. for file in glob.glob(torrentsPath + "/*.torrent"):
  27. try:
  28. torrent = torrentfile.TorrentFile()
  29. torrent.readFile(file)
  30. if not any(x.getName() == torrent.getName()
  31. for x in manager.getTorrents()):
  32. debug("Found", torrent.getName())
  33. torrent.getTracker().start()
  34. manager.appendTorrent(torrent)
  35. except:
  36. warning("could not load or start", file)
  37. count = len(manager.getTorrents())
  38. if count == 0:
  39. warning("could not find/load/start any torrent. Waiting 5 minutes")
  40. time.sleep(300)
  41. continue
  42. t = manager.getNextTime()
  43. torrent = t['torrent']
  44. secs = t['time']
  45. if secs > 0:
  46. debug(torrent.getName() + ": Next update in " + str(secs) + " seconds")
  47. time.sleep(secs)
  48. debug("Updating", torrent.getName(),
  49. "ratio =", (torrent.getTracker().getUploaded() / float(torrent.getSize())))
  50. try:
  51. manager.updateTorrent()
  52. except:
  53. warning("could not update")