summaryrefslogtreecommitdiffstats
path: root/travnik.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--travnik.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/travnik.py b/travnik.py
index 672ed00..5b273f8 100644
--- a/travnik.py
+++ b/travnik.py
@@ -14,6 +14,7 @@ class Torrent():
self.files = {}
self.type = Type.UNDEF
self.cache = None
+ self.hadpieces = False
def file(self, f):
self.parse(open(f, "rb").read())
def parse(self, b):
@@ -23,6 +24,7 @@ class Torrent():
self.dict = decode(b)
if b'pieces' in self.dict.get(b'info'):
self.dict.get(b'info').pop(b'pieces')
+ self.hadpieces = True
if b'files' in self.dict.get(b'info').keys():
self.type = Type.V1
for file in self.dict.get(b'info').get(b'files'):
@@ -43,6 +45,7 @@ class Torrent():
if self.type is Type.V1:
self.type = Type.HYBRID
else:
+ self.type = Type.V2
def filetree(names):
r = {}
for key in names.keys():
@@ -56,6 +59,8 @@ class Torrent():
self.type = Type.V1
self.files[self.dict.get(b'info').get(b'name')] = self.dict.get(b'info').get(b'length')
first_filename = [i for i in self.files.keys()][0]
+ if self.type == Type.V2 and self.hadpieces:
+ self.type = Type.HYBRID;
if len(self.files) == 1 and self.files[first_filename] == {}:
print("fixed bad single file torrent", self.sha1.hex())
self.files[first_filename] = self.dict.get(b'info').get(b'length')