Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-set a torrent's parameters based on metadata #20502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tgregerson
Copy link
Contributor

Add a system for configuring a set of rules that modify torrent parameters based on the torrent's metadata. Closes #5779.

Each Rule consists of a Condition and a Modifier. The Condition acts as a predicate applied to the metadata (e.g., trackers or files in the torrent). The Modifer performs some mutation on the torrent, such as setting its category or adding a tag. A given torrent may match multiple Rules, and Modifications are applied in the same order as the Rule definitions.

Rules are specified in a torrent_param_rules.json file placed in the config directory. If you can't access the attached file, a copy is available at https://pastebin.com/aMsE5ght. If this PR is accepted, further documentation can be added to the Wiki.

Rules are only applied to newly added torrents on initially receiving their metadata. Updates to an existing torrent's metadata, such as merging trackers, do not cause the Rules to be re-applied.

The following Conditions are included in this PR:

  • Logical AND of subconditions
  • Logical OR of subconditions
  • Logical NOT of a subcondition
  • Regex match of any file in the torrent
  • Regex match of any tracker URL attached to the torrent

The following Modifiers are included in this PR:

  • Set the category
  • Add a tag
  • Set the save path

The system is designed to be modular, so it should be possible to add more Conditions and Modifiers in later PRs without significant effort. I tried to limit this PR to some of the more commonly requested ones to keep it from getting too large.


Implementation notes:

The primary complicating factor for this feature is that some portions of metadata (e.g. file paths) are not guaranteed to be immediately available. For example, when using a magnet link, they are asynchronously downloaded. The download may not complete until after the add torrent GUI has been displayed or after the torrent has been added to the session. This requires handling three scenarios:

  • The metadata is immediately available or is downloaded prior to showing the add torrent dialog (if enabled). This is the simplest case, as all parameters are updated prior to displaying any related GUI elements.
  • The user has enabled the add torrent dialog, and the metadata is downloaded while the dialog is still active. In this case the modifications need to be applied and the add torrent dialog must be updated to reflect the modifications.
  • The metadata arrives after the torrent has been added, either because the add torrent dialog was disabled or the download finished after the user accepted the dialog. In this case the modifications are applied to the Torrent object, which in turn triggers update of the main UI (torrent list, categories, etc.)

@glassez glassez self-assigned this Mar 4, 2024
@glassez glassez added the Core label Mar 4, 2024
Copy link
Member

@glassez glassez left a comment

Choose a reason for hiding this comment

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

Very preliminary comments. I haven't reviewed it completely.

src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/torrentparamrules.cpp Outdated Show resolved Hide resolved
@glassez
Copy link
Member

glassez commented Mar 4, 2024

Rules are specified in a torrent_param_rules.json file placed in the config directory.

The preliminary comment about the file format concerns the naming style of "predefined" entities, such as parameter names and values. Could you change them so that they use the same style, either snake_case or CamelCase? (I would prefer CamelCase.)

@tgregerson tgregerson force-pushed the master branch 2 times, most recently from 6b54657 to 9ed0866 Compare March 4, 2024 23:30
@tgregerson
Copy link
Contributor Author

I updated the sample rules config at https://pastebin.com/aMsE5ght to use CamelCase style for JSON keys.

@tgregerson tgregerson force-pushed the master branch 2 times, most recently from 2241c4a to a3b6b96 Compare March 5, 2024 23:27
Adds a system for configuring a set of rules that modify torrent
parameters based on the torrent's metadata. Rules are specified
via a JSON file loaded on startup.

Closes qbittorrent#5779.
@tgregerson
Copy link
Contributor Author

Any further comments @glassez ?

@glassez
Copy link
Member

glassez commented Mar 30, 2024

Any further comments @glassez ?

I need more time to think about it in detail, but right now I have other tasks as a priority.

@trim21
Copy link
Contributor

trim21 commented Apr 23, 2024

Rules are specified in a torrent_param_rules.json file placed in the config directory.

The preliminary comment about the file format concerns the naming style of "predefined" entities, such as parameter names and values. Could you change them so that they use the same style, either snake_case or CamelCase? (I would prefer CamelCase.)

but our API is in snake_case, would be better to use same case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic Category Assignment
3 participants