mikf / gallery-dl

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

Rename file if exist #306

Closed rEnr3n closed 5 years ago

rEnr3n commented 5 years ago

Please add option to rename file if it already exists.

iamleot commented 5 years ago

Hello rEnr3n,

rEnr3n writes:

Please add option to rename file if it already exists.

Can you please elaborate further?

I.e. most files fetched by gallery-dl should be unique and that's often used as a way to avoid refetching them. :)

rEnr3n commented 5 years ago

I usually download using gallery-dl -i SOMETEXT

SOMETEXT contains URLs from varying sources. Sometimes it contains URLs like these:

https://example.lan/1.jpg
https://another.lan/1.jpg
Hrxn commented 5 years ago

Ah, so you're using gallery-dl like some kind of download manager, like wget?

It's certainly possible, although a bit pointless, maybe. We can't rely on any unique IDs in this case, yes.

Eventually the directlink-extractor could be extended to generate randomized unique-y names here. The archive functionality would be useless in such a case, though.

github-userx commented 5 years ago

Doesn’t gallery-dl add a _1 to duplicates?

wankio commented 5 years ago

i'm usually using it with this config, so it more like wget

"directlink": { "filename": "{path[:120]}+{filename[:80]}.{extension}", "archive": "~/gallery-dl/archive-directlink.sqlite3" }

mikf commented 5 years ago

extractor.skip now has an enumerate option that adds .1, .2, etc to filenames if they already exist, like Wget does.

Hrxn commented 5 years ago

Nice, thanks.

Small suggestion: how about adding the numeric suffix between the filename and the file extension, i.e. something like..

standardfilename-1.jpg
standardfilename-2.jpg

instead of

standardfilename.jpg.1
standardfilename.jpg.2

That's what wget does, correct, but in my opinion that wget behaviour is a bit stupid 😄

mikf commented 5 years ago

Yeah, you're right. Having files with .jpg.1 as filename extension is probably not very useful on Windows systems.

At first I actually wanted to implement it like you're suggesting by modifying a file's extension, but there were some complications for certain edge cases and I decided to rather go the easier and "already established" way ... I'll see what I can do in that regard.