mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2024-09-20 07:16:04 +08:00
use logging in torrent_hash_generator
This commit is contained in:
parent
9684bf3e38
commit
99a7984693
|
@ -2,6 +2,11 @@ import hashlib
|
||||||
|
|
||||||
import bencodepy
|
import bencodepy
|
||||||
|
|
||||||
|
from modules import util
|
||||||
|
from modules.util import Failed
|
||||||
|
|
||||||
|
logger = util.logger
|
||||||
|
|
||||||
|
|
||||||
class TorrentHashGenerator:
|
class TorrentHashGenerator:
|
||||||
def __init__(self, torrent_file_path):
|
def __init__(self, torrent_file_path):
|
||||||
|
@ -11,15 +16,15 @@ class TorrentHashGenerator:
|
||||||
try:
|
try:
|
||||||
with open(self.torrent_file_path, "rb") as torrent_file:
|
with open(self.torrent_file_path, "rb") as torrent_file:
|
||||||
torrent_data = torrent_file.read()
|
torrent_data = torrent_file.read()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
torrent_info = bencodepy.decode(torrent_data)
|
torrent_info = bencodepy.decode(torrent_data)
|
||||||
info_data = bencodepy.encode(torrent_info[b"info"])
|
info_data = bencodepy.encode(torrent_info[b"info"])
|
||||||
info_hash = hashlib.sha1(info_data).hexdigest()
|
info_hash = hashlib.sha1(info_data).hexdigest()
|
||||||
|
logger.trace(f"info_hash: {info_hash}")
|
||||||
return info_hash
|
return info_hash
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("Invalid .torrent file format. 'info' key not found.")
|
logger.error("Invalid .torrent file format. 'info' key not found.")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise FileNotFoundError(f"Torrent file '{self.torrent_file_path}' not found.")
|
logger.error(f"Torrent file '{self.torrent_file_path}' not found.")
|
||||||
except Exception as e:
|
except Failed as err:
|
||||||
raise Exception(f"Error: {e}")
|
logger.error(f"TorrentHashGenerator Error: {err}")
|
||||||
|
|
Loading…
Reference in a new issue