mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
12.04k stars 979 forks source link

[Feature Request] Ability to make a chain of multiple conditions and sub-conditions for filters #5639

Open KonoVitoDa opened 6 months ago

KonoVitoDa commented 6 months ago

E.g.: If I'm on Pixiv and want to use a different directory structure just for ugoira, or if I want a new folder to be created if a given tag is present, it'd be really awesome if this could be achieved with something like this:

"directory":
            {
                "type=='ugoira'":
                {
                    "0<=total_bookmarks<=1000": ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "ugoira", "{rating}", "0-1000 Bookmarks"],
                    "1000<=total_bookmarks": ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "ugoira", "{rating}", "1000+ Bookmarks"]
                },
                "":
                {
                    "0<=total_bookmarks<=1000": ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "{rating}", "0-1000 Bookmarks"],
                    "1000<=total_bookmarks": ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "{rating}", "1000+ Bookmarks"],
                    "'コイカツ' in tags":
                    {
                        "0<=total_bookmarks<=1000": ["Pixiv", "Koikatsu", "{rating}", "0-1000 Bookmarks"],
                        "1000<=total_bookmarks": ["Pixiv", "Koikatsu", "{rating}", "1000+ Bookmarks"]
                    }
                }
            }
mikf commented 6 months ago

It is possible to combine conditions with and and or, and have them all in one big list:

"directory":
{
    "type=='ugoira' and 0<=total_bookmarks<=1000":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "ugoira", "{rating}", "0-1000 Bookmarks"],
    "type=='ugoira' and 1000<=total_bookmarks":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "ugoira", "{rating}", "1000+ Bookmarks"],
    "'コイカツ' in tags and 0<=total_bookmarks<=1000":
        ["Pixiv", "Koikatsu", "{rating}", "0-1000 Bookmarks"],
    "'コイカツ' in tags and 1000<=total_bookmarks":
        ["Pixiv", "Koikatsu", "{rating}", "1000+ Bookmarks"],
    "0<=total_bookmarks<=1000":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "{rating}", "0-1000 Bookmarks"],
    "1000<=total_bookmarks":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "{rating}", "1000+ Bookmarks"]
}
KonoVitoDa commented 6 months ago

It is possible to combine conditions with and and or, and have them all in one big list:

"directory":
{
    "type=='ugoira' and 0<=total_bookmarks<=1000":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "ugoira", "{rating}", "0-1000 Bookmarks"],
    "type=='ugoira' and 1000<=total_bookmarks":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "ugoira", "{rating}", "1000+ Bookmarks"],
    "'コイカツ' in tags and 0<=total_bookmarks<=1000":
        ["Pixiv", "Koikatsu", "{rating}", "0-1000 Bookmarks"],
    "'コイカツ' in tags and 1000<=total_bookmarks":
        ["Pixiv", "Koikatsu", "{rating}", "1000+ Bookmarks"],
    "0<=total_bookmarks<=1000":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "{rating}", "0-1000 Bookmarks"],
    "1000<=total_bookmarks":
        ["Pixiv", "{illust_ai_type!s:?##R2#AI#R1##R0##}", "{rating}", "1000+ Bookmarks"]
}

Oh, true, this is a good workaround. But I think it would still be better, cleaner and didactic if it worked the way I mentioned, mainly considering that in my case I actually use ten different total_bookmarks ranges.

biggestsonicfan commented 2 weeks ago

Does the above work for base-directory?

mikf commented 2 weeks ago

No, conditions are currently only supported by filename and directory.

biggestsonicfan commented 2 weeks ago

Ah, dang... I suppose I could symlink mount within the existing base directory 🤔

@mikf How would I define the directory that doesn't meet any of the above criteria? The catch-all directory that differs from the extractor's default.

mikf commented 2 weeks ago

With an empty string "" or an expression that always evaluates to true, like true, 1, 'any_string', etc.

        "directory": {
            "cond": ["conditional", "directory"],
            ""    : ["default", "directory"]
        }