f09d94e34b
Bridge between qBittorrent and Stash that polls for completed torrents, deduplicates via SHA256 hashing and SQLite, and imports new media files. Supports daemon mode (continuous polling) and scan mode (bulk operations). Configuration via environment variables for Docker Swarm compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
20 lines
516 B
Python
20 lines
516 B
Python
import hashlib
|
|
|
|
|
|
def hash_file(path, algorithm="sha256"):
|
|
"""Hash a file by streaming in 64KB chunks. Returns hex digest."""
|
|
if algorithm == "blake3":
|
|
try:
|
|
import blake3
|
|
h = blake3.blake3()
|
|
except ImportError:
|
|
raise ImportError("blake3 requested but not installed; pip install blake3")
|
|
else:
|
|
h = hashlib.new(algorithm)
|
|
|
|
with open(path, "rb") as f:
|
|
while chunk := f.read(65536):
|
|
h.update(chunk)
|
|
|
|
return h.hexdigest()
|