Browse Source

changed uploaded, downloaded, left arguments

master
Robin Thoni 9 years ago
parent
commit
a53cabd599
1 changed files with 23 additions and 12 deletions
  1. 23
    12
      torrenttracker.py

+ 23
- 12
torrenttracker.py View File

12
     port = 0
12
     port = 0
13
     user_agent = ""
13
     user_agent = ""
14
     interval = 300
14
     interval = 300
15
+    uploaded = 0
16
+    downloaded = 0
17
+    left = 0
18
+
15
     def __init__(self, torrent, port=6882, user_agent="rtorrent/0.8.42/0.12.42"):
19
     def __init__(self, torrent, port=6882, user_agent="rtorrent/0.8.42/0.12.42"):
16
         self.torrent = torrent
20
         self.torrent = torrent
17
         self.session = requests.session()
21
         self.session = requests.session()
22
     def getInterval(self):
26
     def getInterval(self):
23
         return self.interval
27
         return self.interval
24
 
28
 
25
-    def request(self, uploaded, downloaded, left, event=""):
29
+    def request(self, event=""):
26
         params = {"info_hash": self.torrent.getHash().digest(),
30
         params = {"info_hash": self.torrent.getHash().digest(),
27
                 "peer_id": self.peer_id,
31
                 "peer_id": self.peer_id,
28
                 "port": self.port,
32
                 "port": self.port,
29
-                "uploaded": uploaded,
30
-                "downloaded": downloaded,
31
-                "left": left,
33
+                "uploaded": self.uploaded,
34
+                "downloaded": self.downloaded,
35
+                "left": self.left,
32
                 "event": event}
36
                 "event": event}
33
         headers = {"User-Agent": self.user_agent}
37
         headers = {"User-Agent": self.user_agent}
34
         r = self.session.get(self.torrent.getAnnounce(), headers=headers, params=params)
38
         r = self.session.get(self.torrent.getAnnounce(), headers=headers, params=params)
37
             self.interval = int(data['interval'])
41
             self.interval = int(data['interval'])
38
         return data;
42
         return data;
39
 
43
 
40
-    def start(self):
41
-        return self.request(0, 0, 0, "started")
44
+    def start(self, left = 0):
45
+        self.uploaded = 0
46
+        self.downloaded = 0
47
+        self.left = left
48
+        return self.request("started")
42
 
49
 
43
-    def stop(self, uploaded, downloaded, left):
44
-        return self.request(0, 0, 0, "stopped")
50
+    def stop(self):
51
+        return self.request("stopped")
45
 
52
 
46
-    def complete(self, uploaded):
47
-        return self.request(0, 0, 0, "completed")
53
+    def complete(self):
54
+        self.left = 0
55
+        return self.request("completed")
48
 
56
 
49
-    def interval(self, uploaded, downloaded, left):
50
-        return self.request(uploaded, downloaded, left)
57
+    def update(self, uploaded, downloaded = 0, left = 0):
58
+        self.uploaded += uploaded
59
+        self.downloaded += downloaded
60
+        self.left -= left
61
+        return self.request()
51
 
62
 

Loading…
Cancel
Save