-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import hashlib | ||
|
||
import bencodepy | ||
|
||
|
||
class TorrentHashGenerator: | ||
def __init__(self, torrent_file_path): | ||
self.torrent_file_path = torrent_file_path | ||
|
||
def generate_torrent_hash(self): | ||
try: | ||
with open(self.torrent_file_path, "rb") as torrent_file: | ||
torrent_data = torrent_file.read() | ||
|
||
try: | ||
torrent_info = bencodepy.decode(torrent_data) | ||
info_data = bencodepy.encode(torrent_info[b"info"]) | ||
info_hash = hashlib.sha1(info_data).hexdigest() | ||
return info_hash | ||
except KeyError: | ||
raise ValueError("Invalid .torrent file format. 'info' key not found.") | ||
except FileNotFoundError: | ||
raise FileNotFoundError(f"Torrent file '{self.torrent_file_path}' not found.") | ||
except Exception as e: | ||
raise Exception(f"Error: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bencodepy==0.9.5 | ||
flake8==6.0.0 | ||
pre-commit==3.3.2 | ||
qbittorrent-api==2023.4.47 | ||
|