mikf / gallery-dl

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

Can logfile support dynamic paths? #6184

Open maplestory03 opened 1 month ago

maplestory03 commented 1 month ago

e.g. "logfile": {"path": "./log/{user['name']}.log"} "logfile": {"path": "./log/{search}.log"} "logfile": {"path": "./log/{tag}.log"} Download multiple author links/search links (tag/search) and write log with different file names through the configuration file according to the author or tag/search, instead of using the command -- write-log every time

Hrxn commented 1 month ago

Not sure if I really understand what you are trying to achieve here, actually.

The options for logfile are part of the "output" config section, so, no, they don't work in the same way as subcategory specific options that you can define for every extractor entry in its own way, if that was your question.

But you can change the format option for your logging output, e.g.

{
    "format"     : "{asctime} {name}: {message}",
    "format-date": "%H:%M:%S",
    "path"       : "~/log.txt",
    "encoding"   : "ascii"
}

And you can access information about the currently used extractor with {extractor.url}, for example, and {extractor.subcategory} should show you the correct extractor type like tag, search, etc.

maplestory03 commented 1 month ago

I hope that each time I download a different link, a separate log will be generated according to the corresponding link, rather than all of them being downloaded into one file such as x.com/author1 x.com/author2 x.com/author3 Do not use -- write-log separately Download 3 times and generate author1.log author2.log author1.log3 at the specified path. @Hrxn

mikf commented 1 month ago

Log files get initialized at the very start before any input URLs get processed. Having a dynamic log file path based on metadata values, which are not available when log files are initialized, would currently not make much sense.

Twi-Hard commented 1 month ago

I don't know if saying this will help you or not but some of this is possible if you run gallery-dl through a different script. In my bash script I extract the usernames from website URLs like this:

handle=$(echo "$1" | grep -oE "deviantart\.com/[-A-Za-z0-9_]{1,25}" | sed "s/\///g" | sed "s%deviantart.com%%" | tr '[:upper:]' '[:lower:]')

And I build the gallery-dl command like this (where $1 is the input url):

cmd="gallery-dl --config \"$ENV/config/gdl_general.conf\""

if [[ "$1" =~ ([a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,})($|\/) ]]; then
    domain="${BASH_REMATCH[1]}"
fi

cmd+=" -o \"output.logfile.path=$HOME/tools/gallery-dl/logs/${domain}/${domain}-${handle}.log\""

eval "$cmd"

Edit: I didn't mean to send this yet. I accidently pressed shift-enter. Anyways, there's a lot of code you'd have to fill in, but I just wanted to point out it's possible if you know how to code or know enough to get something like chatgpt to make it.