refactor: do not download torrent file to identify contents

This commit is contained in:
2025-07-04 16:17:17 +02:00
parent a6ffbd59f8
commit df256f5be2

View File

@@ -7,6 +7,7 @@ import regex
from typing import Optional
import loguru
import sys
import requests
log = loguru.logger
log.remove()
@@ -66,10 +67,11 @@ class Torrent:
@property
def get_contents(self):
os.system(f"wget {self.download_url}> /dev/null 2>&1")
with open(f"{self.download_url.split('/')[-1]}", "rb") as f:
data = bencodepy.decode(f.read())
resp = requests.get(self.download_url, timeout=15)
resp.raise_for_status() # raises for HTTP 4xx/5xx
# 2. Decode directly from bytes
data = bencodepy.decode(resp.content)
info = data[b"info"]
filetypes: list[str] = []
@@ -120,7 +122,6 @@ class Torrent:
else:
self.volumes = [0]
# log.debug("Filetypes: {}, Volumes: {}".format(self.filetypes, self.volumes)) #! enable for debug
os.remove(f"{self.download_url.split('/')[-1]}")
class TorrentSite(Enum):