Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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)