1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #! /usr/bin/env python
-
- from __future__ import print_function
- import sys
- import time
- import glob
- import torrentfile
- import torrentmanager
- import config
-
- def warning(*objs):
- print("WARNING:", *objs, file=sys.stderr)
-
- if len(sys.argv) >= 2:
- config = config.Config(sys.argv[1])
- else:
- config = config.Config()
-
- maxRatio = config.getMaxRatio()
- maxRate = config.getMaxRate()
- torrentsPath = config.getTorrentsPath()
-
- manager = torrentmanager.TorrentManager(maxRatio, maxRate)
- run = True
- while run:
- for file in glob.glob(torrentsPath + "/*.torrent"):
- try:
- torrent = torrentfile.TorrentFile()
- torrent.readFile(file)
- if not any(x.getName() == torrent.getName()
- for x in manager.getTorrents()):
- print("Found", torrent.getName())
- torrent.getTracker().start()
- manager.appendTorrent(torrent)
- except:
- warning("could not load or start", file)
-
- count = len(manager.getTorrents())
-
- if count == 0:
- warning("could not find/load/start any torrent. Waiting 5 minutes")
- time.sleep(300)
- continue
-
- t = manager.getNextTime()
- torrent = t['torrent']
- secs = t['time']
- if secs > 0:
- print(torrent.getName() + ": Next update in " + str(secs) + " seconds")
- time.sleep(secs)
- print("Updating", torrent.getName())
- try:
- manager.updateTorrent(torrent)
- except:
- warning("could not update")
|