mikf / gallery-dl

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

Option to postprocess images #334

Open w3bb opened 5 years ago

w3bb commented 5 years ago

I have been using gallery-dl for a while now and have been finding it super-duper useful. However, continuing to use it I find it fills up my hard drive quickly. It would be nice to be able to convert it to something like webp as it's downloading instead of going in later and converting then deleting every image. Or maybe someone who's downloading gifs would prefer having individual frames rather than it bundled in a gif file for AI.

I think this would be incredibly useful, especially for those of us who collect large amounts of images (like I do).

kattjevfel commented 3 years ago

Found this by accident, I've personally solved this by making a "selector" for filetypes, so when it finds X filetype, it does Y. To combat gallery-dl from no longer finding downloaded files (when converting png --> webp) I've enabled the database.

config.json:

{
    "extractor": {
        "archive": "/path/to/{category}.sqlite3",
        "postprocessors": [
            {
                "name": "exec",
                "command": [
                    "gallery-dl_postprocessing_selector.sh",
                    "{extension}",
                    "{_path}"
                ]
            }
        ]
    }
}

gallery-dl_postprocessing_selector.sh:

#!/bin/bash
IFS=$'\n'

if [ "$1" = png ]; then
    png2webp.sh "${*:2}" >/dev/null
elif [ "$1" = jpg ] || [ "$1" = jpeg ]; then
    jpegoptim -p --strip-com --strip-iptc --strip-icc --strip-xmp "${*:2}" >/dev/null
else
    exit 0
fi

Further, my png2webp.sh is this script I wrote: https://github.com/kattjevfel/scripts/blob/master/png2webp.sh

This is obviously unix only, maybe it can work with WSL or whatever, but I leave no guarantees.

Twi-Hard commented 2 years ago

Before I came across this issue I came up with a one line solution that doesn't require a script. I'm pasting it here in case it helps anybody.

{
  "extractor": {
    "postprocessors": [
      {
        "name": "exec",
        "command": "echo {} | grep '\\.png$' | xargs -I% oxipng -o max --strip safe %",
        "event": "after"
      },
      {
        "name": "exec",
        "command": "echo {} | grep -E '\\.jpe?g$' | xargs -I% jpegoptim %",
        "event": "after"
      }
    ]
  }
}