gyng / save-in

WebExtension for saving media, links, or selections into user-defined directories
MIT License
204 stars 25 forks source link

Issues with Dynamic Downloads/Rename and Route rules with DeviantArt.com #189

Open LukasThyWalls opened 2 years ago

LukasThyWalls commented 2 years ago

Hello.

In DeviantArt.com, I have some issues with the filenames, seems related to some kind of filename rename made by the how the webpage when it downloads a file.

I'm going to use this image as example: https://www.deviantart.com/cryptid-creations/art/Daily-Paint-2181-Quillypad-772098538

At any image in DeviantArt (i think), you can download the image itself saving the image (Context Menu above the image -> Save Image or Save-In), but if you are logged in on DeviantArt, sometimes, there is a Download button (an icon below-left the image) that normally brings the Save dialog or shows the full size image.

Normally, in most images, if you download saving the image with the context menu, the filename is like _title_by_authorfilecode-fullview.ext (using the example it should be _daily_paint_2181_quillypad_by cryptid_creationsdcror1m-fullview.png but it's not as i will explain later), and if there is a download icon, that files download with a name like _title_by_authorfilecode.ext (_daily_paint_2181__quillypad_by_cryptid_creationsdcror1m.png in our test case).

However, with some specific images, It doesn't use those filenames, instead it downloads with filenames like xxxxxxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.ext (the first "word" is the "filecode"). Normally happens with some images with the download icon, with GIFs happens always with both, and sometimes with the saving in context menu, like in the example, that downloads an image with filename dcror1m-bd1fe78d-cf2b-4c0f-ab93-08eaadfc4e88.png. You don't know when is going to use the normal filenames or the weird ones, normally are the normal but the other ones are very common.

Using Save-In, it does the same as using the normal save: You can save using the Context Menu -> Save In above the image, or using Context-Menu -> Save In above the download icon, and they respect the filenames.

But to avoid those weird filenames, I learned about Dynamic Downloads/Rename and Route options in Save In, and I tried to catch those filenames with weird names and auto-rename them when they appear. So I added this to the Save In Rename and Route configuration:

filename: ([a-z0-9]{7})\-[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}\.[a-z0-9]{3}
pagedomain: www.deviantart.com
pagetitle: (.+) on DeviantArt
capture: filename,pagetitle
into: :$3:-:$1:.:fileext:

I did like that because I would like to maintain the same filenames that use DeviantArt, although i would like to change the spaces and other characters to underscores (I asked about that here https://github.com/gyng/save-in/issues/187).

Anyway, when I add that configuration something happens, and ALL downloads using the Download icon are renamed by Save In using that rename configuration, including the ones I didn't have issues with those weird names.

You can see that in the example image, without the renaming rules above, using Save In in the Download button, it downloads an image with filename _daily_paint_2181__quillypad_by_cryptid_creationsdcror1m.png, however, with the renaming rules, they are executed and i have a filename like Daily Paint 2181. Quillypad by Cryptid-Creations-dcror1m.png although it shouldn't because the filename is not something like dcror1m-bd1fe78d-cf2b-4c0f-ab93-08eaadfc4e88.png that is what triggers the renaming rules.

In reality, the image filename IS dcror1m-bd1fe78d-cf2b-4c0f-ab93-08eaadfc4e88.png, as you can see in the Download icon URL (https://www.deviantart.com/download/772098538/dcror1m-bd1fe78d-cf2b-4c0f-ab93-08eaadfc4e88.png?token=...), but when the file began to download (with Save In or not) is renamed by some kind of extra info provided by the DeviantArt webpage. But if you use any rename rules in Save In, it uses the original filename, and not that "renamed" filename, that will be the desired behaviour.

So the point is:

Thanks in advance!