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

Can logfile support dynamic paths? #6184

Open
maplestory03 opened this issue Sep 15, 2024 · 4 comments
Open

Can logfile support dynamic paths? #6184

maplestory03 opened this issue Sep 15, 2024 · 4 comments

Comments

@maplestory03
Copy link

maplestory03 commented Sep 15, 2024

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
Copy link
Contributor

Hrxn commented Sep 15, 2024

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
Copy link
Author

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
Copy link
Owner

mikf commented Sep 16, 2024

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.

@mikf mikf changed the title Can logfile support dynamic content? Can logfile support dynamic paths? Sep 16, 2024
@Twi-Hard
Copy link

Twi-Hard commented Sep 16, 2024

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.

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

No branches or pull requests

4 participants