Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/fertilizer/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,21 @@ def scan_torrent_directory(


def __collect_infohashes_from_files(files: list[str]) -> dict:
infohash_dict = {}

for filepath in files:
try:
torrent_data = get_bencoded_data(filepath)

if torrent_data:
infohash = calculate_infohash(torrent_data)
infohash_dict[infohash] = filepath
except Exception:
continue

return infohash_dict
print(f"\rStarting up. Collecting infohashes...")
print(f"\rFound {len(files)} files to process...")
Comment on lines +149 to +150
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my curiosity, what's the purpose of the carriage returns at the start of the lines? Since print includes a newline, shouldn't the carriage return be unneeded?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the only \r that is truly needed is the one in print(f"\r({processed}/{len(files)})…
because it is trying to overwrite the current output line.

infohash_dict = {}

for filepath in files:
try:
torrent_data = get_bencoded_data(filepath)
if torrent_data:
infohash = calculate_infohash(torrent_data)
infohash_dict[infohash] = filepath
except Exception:
continue
processed += 1
print(f"\r({processed}/{len(files)}) Analyzing torrent files...", end="", flush=True)

print() # New line after progress complete
print(f"\rDone collecting infohashes.")
return infohash_dict