summaryrefslogtreecommitdiffstats
path: root/travnik.py
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-03-15 20:26:21 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-03-15 20:26:21 +0100
commit5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f (patch)
tree3d1b3be214f43b57763eda2149b5cc9bea7dbe5e /travnik.py
parentinfloop fix 2 (diff)
downloadtravnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar
travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.gz
travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.bz2
travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.lz
travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.xz
travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.tar.zst
travnik-5aed85d8cdc3301c9f9a68d89d21ae7b1bf1658f.zip
Diffstat (limited to 'travnik.py')
-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')