qBittorrent icon indicating copy to clipboard operation
qBittorrent copied to clipboard

Automatic Category Assignment

Open deskicio opened this issue 8 years ago • 16 comments

I've been searching for quite a bit and i couldnt find anything.

I would love a system that automatically picks the category according to key words associated with it.

Good'ol emule used to have this function: Automatic Category Assignment When starting new downloads, they can be assigned automatically to this category, if the filename matches a given pattern. | is used to separate different keywords and * can be used as a wildcard for an arbitrary string. Example: .avi|a.* This would assign new files with the extension 'avi', and filenames starting with an 'a' to this category. (http://www.emule-project.net/home/perl/help.cgi?l=1&rm=show_topic&topic_id=143)

I believe it would be a great addtion to qbit's current features.

Thanks for a great product.

deskicio avatar Sep 27 '16 14:09 deskicio

Users ask for this before, also with setting different file path to each of the categories but it's not like a priority. I don't even think they are considering implementing this in a near future.

Misiek304 avatar Sep 28 '16 16:09 Misiek304

I think this request is also covered in #5201.

tgregerson avatar Nov 26 '17 22:11 tgregerson

What is the point of automatic torrent management if you have to manually assign the category? All I want is to automatically separate my .mp4 files into my video directory.

CypherConjured avatar Jun 01 '19 16:06 CypherConjured

What is the point of automatic torrent management if you have to manually assign the category? All I want is to automatically separate my .mp4 files into my video directory.

I second that. A way to auto-assign the categories based on torrentname by regex or by tracker would be handy!

leo-carmo avatar Oct 07 '19 08:10 leo-carmo

For an example of this, you could take a look at the LabelPlus plugin for deluge, which has all of this functionality and makes it painless to auto-categorize torrents based on torrent/tracker name. Something like this would be immensely helpful!

sig-kill avatar May 28 '20 20:05 sig-kill

Here's a GUI example from another torrent client (Tixati):

tixati

All new torrents will automatically be added to the temp category, unless they contain trackers with either the fedora or ubuntu strings.

anewuser avatar Aug 19 '21 01:08 anewuser

This would definitely be a very useful feature.

guiltlab avatar Nov 26 '21 10:11 guiltlab

Wow this issue opened for 6 years already... 🤔

For example the old Shareaza has a "Download groups" with a similar functionality:

Download groups

The "Filters" field matches either any part of download file name or also matches any available metadata including for example tracker URL substring, by default it contains a file extensions according current schema ("File type").

"BitTorrent downloads" option effectively matches any file downloaded using torrent since Shareaza is a multi-protocol client, in qB case it can be for example "DHT-only" checkbox.

raspopov avatar Mar 08 '22 08:03 raspopov

Another rich example is a JDownloader 2 "Rule" dialog:

JDownloader 2

The right column of buttons toggles regular expression matches. The bottom input box is for testing purposes.

raspopov avatar Mar 08 '22 08:03 raspopov

It's a little amazing that there's a widely used torrent client without this feature. I'd live to switch away from Deluge since it's so incredibly buggy but this really is a deal breaker. It's so much more difficult to categorise hundreds or thousands of torrents manually.

Serene-Arc avatar Sep 07 '22 02:09 Serene-Arc

Good'ol emule used to have this function: Automatic Category Assignment When starting new downloads, they can be assigned automatically to this category, if the filename matches a given pattern

Doesn't emule download single file per task? Note that torrents are often multifile so what file exactly is to apply the pattern?

glassez avatar Sep 07 '22 03:09 glassez

@glassez Deluge's labelplus applies the regex to all files, and if any of them match then the label applies.

Serene-Arc avatar Sep 07 '22 08:09 Serene-Arc

@glassez Deluge's labelplus applies the regex to all files, and if any of them match then the label applies.

Then it is possible that different files will match the different categories so only first match will win. (Although it is also possible that single-file torrent could match several categories.)

glassez avatar Sep 07 '22 10:09 glassez

Yes, Deluge orders the categories from top to bottom, with the first match dictating the label. Not saying it's the best solution, but it is a solution. I had to add a negative regex match to make it easier but it does work if you only use file matches as the last level of possible resort.

Serene-Arc avatar Sep 07 '22 23:09 Serene-Arc

Hilarious that this is still open, does qBittorent have a plugins interface?

KingPsychopath avatar Feb 03 '24 00:02 KingPsychopath

Any volunteers to draw up a proposal ?

luzpaz avatar Feb 14 '24 13:02 luzpaz

God, this is 8 years old! Almost all other torrent clients and download managers have a similar feature, but the good qBittorrent doesn't?

leo-carmo avatar Feb 19 '24 21:02 leo-carmo

I spent some timing scoping out the backend portion of the implementation.

When making rules based off the torrent descriptor or when using a torrent file with built-in metadata, it is reasonably straightforward. Most of the complexity comes when torrent metadata needs to be downloaded, since this happens asynchronously. Seems doable though.

tgregerson avatar Feb 19 '24 23:02 tgregerson

I have a basic prototype working.

  • A configurable list of Rules are applied when adding a new torrent
  • A Rule consists of a Condition and a Modifier. If the Condition is met based on torrent metadata, the Modifier is applied
  • Conditions and Modifiers can each be compounded
  • Rules are applied in order. If multiple Rules match, the Modifiers are applied in order.
  • I've only implemented Conditions for file paths and tracker URLs and have only implemented Modifiers for setting the category and adding tags, but the code is designed to be modular so others could be added later.
  • Currently there is no GUI for adding / editing rules. You have to edit a JSON file that is loaded at startup.

Example Rules JSON:

{
    "rules": [
        {
            "condition": {
                "regex_pattern": ".*",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "category": "DefaultCategory",
                "type": "SetCategory"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*(jpg|webm)",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "category": "Media",
                "type": "SetCategory"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*",
                "type": "AnyTrackerUrlRegex"
            },
            "modifier": {
                "tag": "AnyTracker",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*jpg",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "tag": "JPEG",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*webm",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "tag": "WEBM",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "conditions": [
                    {
                        "regex_pattern": ".*mp3",
                        "type": "AnyFilePathRegex"
                    },
                    {
                        "regex_pattern": ".*webm",
                        "type": "AnyFilePathRegex"
                    },
                    {
                        "regex_pattern": ".*jpg",
                        "type": "AnyFilePathRegex"
                    }
                ],
                "type": "AnyOfConditions"
            },
            "modifier": {
                "tag": "Media",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "conditions": [
                    {
                        "regex_pattern": ".*webm",
                        "type": "AnyFilePathRegex"
                    },
                    {
                        "regex_pattern": ".*poster.*(jpg|png)",
                        "type": "AnyFilePathRegex"
                    }
                ],
                "type": "AllOfConditions"
            },
            "modifier": {
                "modifiers": [
                    {
                        "tag": "VideoWithPoster",
                        "type": "AddTag"
                    },
                    {
                        "tag": "MixedMedia",
                        "type": "AddTag"
                    }
                 ],
                "type": "Compound"
            }
        }
    ]
}

Example applied to a test torrent from https://webtorrent.io/torrents/tears-of-steel.torrent

Screenshot-from-2024-02-25-10-05-41

tgregerson avatar Feb 25 '24 16:02 tgregerson

  • Currently there is no GUI for adding / editing rules. You have to edit a JSON file that is loaded at startup.

I suspect that providing an UI for editing such rules will require an order of magnitude (or even several orders of magnitude) more effort.

glassez avatar Feb 26 '24 12:02 glassez

@tgregerson There are several different cases of processing added torrents that should be taken into account.

glassez avatar Feb 26 '24 12:02 glassez

I suspect that providing an UI for editing such rules will require an order of magnitude (or even several orders of magnitude) more effort.

I was thinking the same thing. My plan for tackling this was to try to submit the non-GUI version first, assuming that is OK with the maintainers.

This way the GUI could be tackled as a separate PR, and not block progress on the core functionality.

There are several different cases of processing added torrents that should be taken into account.

So far the two important factors I've run into are whether full metadata is initially available (e.g. torrent file vs magnet link) and whether the user has enabled the add torrent GUI from my earlier screenshot.

  • If all metadata is initially available, it's the simplest case. We can apply the rules before adding the torrent and before showing the GUI (if enabled).
  • If the GUI is enabled and metadata is not available, the torrent is added in hidden mode and asynchronously downloads metadata while the GUI is being displayed. If the metadata download finishes before the user has clicked OK, then we need to apply the rules and update the GUI to reflect them.
  • If the GUI is disabled and metadata is not available (or GUI is enabled and the user clicked OK before metadata download finished), then we add the torrent, wait for the metadata downloaded alert from libtorrent, then apply the rules, then update the GUI for the torrent list, etc.

tgregerson avatar Feb 26 '24 23:02 tgregerson

So far the two important factors I've run into are whether full metadata is initially available (e.g. torrent file vs magnet link) and whether the user has enabled the add torrent GUI from my earlier screenshot.

  • If all metadata is initially available, it's the simplest case. We can apply the rules before adding the torrent and before showing the GUI (if enabled).
  • If the GUI is enabled and metadata is not available, the torrent is added in hidden mode and asynchronously downloads metadata while the GUI is being displayed. If the metadata download finishes before the user has clicked OK, then we need to apply the rules and update the GUI to reflect them.
  • If the GUI is disabled and metadata is not available (or GUI is enabled and the user clicked OK before metadata download finished), then we add the torrent, wait for the metadata downloaded alert from libtorrent, then apply the rules, then update the GUI for the torrent list, etc.

In general, I agree. Although there may be difficulties in correctly implementing it (from the perspective of the application architecture). But we will be able to talk about this in detail only when you provide the PR.

glassez avatar Feb 29 '24 13:02 glassez

@tgregerson thanks for your work.

I've read through the thread but I haven't yet understood fully how this would work. My use case would be to put torrents in one watch folder and let the rule json determine the categorie that is attached. I have an Unraid server with QB in a docker. For now I've setup five or so watch folders with different download paths to get downloads in the right folder, but I was used from TransmissionBT that I could just drop everything in one folder and let the rules sort it out. My questions are:

  • How to make this json file process the torrent, where do I place it and how does QB know what to do with it?
  • I'm also wondering (since you have the screnshot under "Example applied to a test torrent" if this json can be used without user interaction.

I would love to test this and see if I can get QB to automatically attach categories. Thanks again.

j-peeters avatar Mar 11 '24 21:03 j-peeters

The PR has not been approved yet, so these answers are subject to change.

How to make this json file process the torrent, where do I place it and how does QB know what to do with it?

The file will be stored in the preferences directory.

https://github.com/qbittorrent/qBittorrent/wiki/Frequently-Asked-Questions#where-does-qbittorrent-save-its-settings

qBt will automatically check for the file on startup. If the file exists, then any rules you have defined will be applied automatically every time you add a new torrent.

I'm also wondering (since you have the screnshot under "Example applied to a test torrent" if this json can be used without user interaction.

No interaction required.

tgregerson avatar Mar 11 '24 22:03 tgregerson

@tgregerson terrific, I hope it gets approved soon. Thanks again!

j-peeters avatar Mar 12 '24 08:03 j-peeters

I'd love to see automatic category assignment not only by keywords, but by other possible criteria, such as total torrent size or tracker.

leo-carmo avatar Mar 18 '24 06:03 leo-carmo

I'd love to see automatic category assignment not only by keywords, but by other possible criteria, such as total torrent size or tracker.

The initial PR supports using trackers as a condition.

I'm open to adding other options such as torrent size in subsequent PRs, provided the initial one is accepted.

tgregerson avatar Mar 18 '24 22:03 tgregerson

I'd love to see automatic category assignment not only by keywords, but by other possible criteria, such as total torrent size or tracker.

Bit outside of the scope of this current issue, but we've come a long way.

Can't wait for the PR pull.

I have a basic prototype working.

  • A configurable list of Rules are applied when adding a new torrent
  • A Rule consists of a Condition and a Modifier. If the Condition is met based on torrent metadata, the Modifier is applied
  • Conditions and Modifiers can each be compounded
  • Rules are applied in order. If multiple Rules match, the Modifiers are applied in order.
  • I've only implemented Conditions for file paths and tracker URLs and have only implemented Modifiers for setting the category and adding tags, but the code is designed to be modular so others could be added later.
  • Currently there is no GUI for adding / editing rules. You have to edit a JSON file that is loaded at startup.

Example Rules JSON:

{
    "rules": [
        {
            "condition": {
                "regex_pattern": ".*",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "category": "DefaultCategory",
                "type": "SetCategory"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*(jpg|webm)",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "category": "Media",
                "type": "SetCategory"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*",
                "type": "AnyTrackerUrlRegex"
            },
            "modifier": {
                "tag": "AnyTracker",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*jpg",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "tag": "JPEG",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "regex_pattern": ".*webm",
                "type": "AnyFilePathRegex"
            },
            "modifier": {
                "tag": "WEBM",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "conditions": [
                    {
                        "regex_pattern": ".*mp3",
                        "type": "AnyFilePathRegex"
                    },
                    {
                        "regex_pattern": ".*webm",
                        "type": "AnyFilePathRegex"
                    },
                    {
                        "regex_pattern": ".*jpg",
                        "type": "AnyFilePathRegex"
                    }
                ],
                "type": "AnyOfConditions"
            },
            "modifier": {
                "tag": "Media",
                "type": "AddTag"
            }
        },
        {
            "condition": {
                "conditions": [
                    {
                        "regex_pattern": ".*webm",
                        "type": "AnyFilePathRegex"
                    },
                    {
                        "regex_pattern": ".*poster.*(jpg|png)",
                        "type": "AnyFilePathRegex"
                    }
                ],
                "type": "AllOfConditions"
            },
            "modifier": {
                "modifiers": [
                    {
                        "tag": "VideoWithPoster",
                        "type": "AddTag"
                    },
                    {
                        "tag": "MixedMedia",
                        "type": "AddTag"
                    }
                 ],
                "type": "Compound"
            }
        }
    ]
}

Example applied to a test torrent from https://webtorrent.io/torrents/tears-of-steel.torrent

Screenshot-from-2024-02-25-10-05-41

I had something similar except it was just a daemon script running agnostic of qBit since I'm not well versed in C++ Thank you for your work!

KingPsychopath avatar Mar 21 '24 00:03 KingPsychopath