-
-
Notifications
You must be signed in to change notification settings - Fork 938
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
[Twitter] Replace filenames on already downloaded images? #5846
Comments
There is no builtin way to rename files, but it is possible to run a custom Python function that does it. config.json {
"filename": "{author[name]}-{tweet_id}_{num}.{extension}",
"metadata-path": "_path",
"postprocessors": [
{
"name": "python",
"event": "prepare",
"function": "/tmp/rename.py:rename"
}
]
} rename.py import os
def rename(metadata):
pathfmt = metadata["_path"]
old = "{tweet_id}_{num}.{extension}".format_map(metadata)
new = "{author[name]}-{tweet_id}_{num}.{extension}".format_map(metadata)
path_old = pathfmt.realdirectory + old
path_new = pathfmt.realdirectory + new
if os.path.exists(path_old):
os.replace(path_old, path_new) |
But on already downloaded files? Does this really work with |
Yes, this works on already downloaded files. At least for me it did when I tested this on a smaller example before posting it here.
|
I should mention: All this does is adding |
Where are you placing the py file? In a new folder within site-packages\gallery-dl? I get "The syntax of the command is incorrect." which makes me think I didn't put it in the right spot gallery-dl --cookies cookies.txt --exec "rename {}" https://x.com/myaccount/likes |
Put the .py file in a folder called tmp. The tmp folder is in the same folder with gallery-dl.exe. |
You can put the I had mine at
???
??? |
What command are you running it with? Are you just running it with --exec "rename"? Whatever I try ends up having an error and just redownloading the images normally.. |
Everything you need is in #5846 (comment), nothing else is necessary. Add these config settings to your |
Ah I had to get the path literal working properly in the config, now it works good I don't know that there's a way to do this without pestering twitter's server a bunch, but if it's worth anything the folder I'm doing this in has over 30k downloads and I haven't been hit yet. |
Technically this could apply to any website but I specifically need to do it with twitter
Is there a way to get gallery-dl to rename the default filenames of already downloaded files to "{author[name]}-{tweet_id}_{num}.{extension}" instead? Or write something else to do it using gallery-dl code?
The text was updated successfully, but these errors were encountered: