Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

torrentmanager.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /usr/bin/env python
  2. import copy
  3. import time
  4. import torrenttracker
  5. class TorrentManager:
  6. torrents = []
  7. next_torrents = []
  8. last_time = 0
  9. def __init__(self, torrents):
  10. self.torrents = torrents
  11. def start(self):
  12. for torrent in self.torrents:
  13. torrent.getTracker().start()
  14. def resetNextTorrents(self):
  15. self.last_time = int(time.time())
  16. self.next_torrents = copy.copy(self.torrents)
  17. def getNextTorrent(self):
  18. if not any(self.next_torrents):
  19. self.resetNextTorrents()
  20. minTorrent = self.next_torrents[0]
  21. for torrent in self.next_torrents:
  22. if (torrent.getTracker().getInterval()
  23. < minTorrent.getTracker().getInterval()):
  24. minTorrent = torrent
  25. return minTorrent
  26. def getNextTime(self):
  27. torrent = self.getNextTorrent()
  28. t = max(torrent.getTracker().getInterval() - (int(time.time()) - self.last_time), 0)
  29. return {'time': t, 'torrent': torrent}
  30. def updateTorrent(self, torrent = None):
  31. if torrent == None:
  32. torrent = self.getNextTorrent()
  33. torrent.getTracker().interval(0, 0, 0)
  34. self.next_torrents.remove(torrent)