Skip to content

Conversation

@L9Lenny
Copy link
Contributor

@L9Lenny L9Lenny commented Dec 14, 2025

PR: Add filter to download files by size

Description

This PR addresses issue #1119 by adding the ability to filter downloads based on file size. It introduces two new flags to the download command: --min-size and --max-size.

Changes

1. New Utility: ParseBinaryBytes

  • File: pkg/utils/byte.go
  • Description: Added a helper function to parse human-readable size strings (e.g., "10MB", "1.5GB") into bytes.
  • Tests: Added comprehensive unit tests in pkg/utils/byte_test.go.

2. Core Implementation

  • File: app/dl/dl.go
    • Added MinSize and MaxSize fields to the Options struct.
  • File: app/dl/iter.go
    • Integrated size filtering logic into the download iteration process.
    • Refactored filtering logic into a dedicated shouldSkip method for better readability and testability.
    • Added debug logging to trace skipped files.

3. CLI Updates

  • File: cmd/dl.go
    • Added --min-size and --max-size flags to the dl command.

Usage Example

# Download only files smaller than 50MB
tdl dl -u https://t.me/c/12345/678 --max-size 50MB

# Download only files larger than 1GB
tdl dl -u https://t.me/c/12345/678 --min-size 1GB

Verification

  • Unit Tests: verified ParseBinaryBytes with new tests in pkg/utils/byte_test.go.
  • Logic Tests: verified filtering logic with TestIterShouldSkip in app/dl/iter_test.go.
  • Manual Testing: Verified that the flags correctly filter files based on the specified size limits using sample downloads.
image

iyear and others added 6 commits December 7, 2025 01:58
- Added length check before accessing topics.Messages slice
- Prevents panic when topics.Messages is empty (length 0)
- Fixes 'index out of range [-1]' error in fetchTopics function

The bug occurred at line 286 where topics.Messages[len(topics.Messages)-1]
was accessed without checking if the slice was empty first.
When the slice is empty, len-1 equals -1, causing a panic.
Fixes iyear#1122
@L9Lenny L9Lenny requested a review from XMLHexagram as a code owner December 14, 2025 18:14
@L9Lenny L9Lenny marked this pull request as draft December 14, 2025 18:18
@L9Lenny
Copy link
Contributor Author

L9Lenny commented Dec 14, 2025

I think I need to update the documentation too but I don't know how to do it so let me know if you can do it or if I have to do it

@L9Lenny L9Lenny marked this pull request as ready for review December 14, 2025 18:34
@iyear
Copy link
Owner

iyear commented Dec 21, 2025

I prefer to use the --filter 'Media.Size > 10000' flag in chat export to perform filtering before passing it to the tdl dl command.

@L9Lenny
Copy link
Contributor Author

L9Lenny commented Dec 25, 2025

so the feature already exists?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants