‹ jan0sch.de

Download your images from DeviantArt.

2024-07-26

Something that always bothered me on DeviantArt was the missing feature to just download a gallery (for example your favourites folder) to your hard drive. Together with the what seems to be a decline of the platform (being sold, questionable moves with so called A.I.) I found it time to part ways with it.

The decision is older but I stayed because I never found the time to store away image collections that I liked. This problem can be solved thanks to gallery-dl. :-)

So what do we need to do? Of course we need to install gallery-dl which I won’t cover here. In my case it was as simple as using pkg install gallery-dl and that was it. Thanks dear FreeBSD ports maintainers! =)

The next step is to create a user configuration which usually resides in the ~/.config/gallery-dl/config.json file. The quickest option to fill this in is to copy the default configuration into this file and edit it.

First remove all “extractors” except for the “deviantart” one. The file should then look somewhat like this:

{
  "extractor": {
    "base-directory": "./gallery-dl/",
    "parent-directory": false,
	... more base stuff
    },
    "deviantart": {
      "client-id": null,
      "client-secret": null,
      "refresh-token": null,
	... more deviantart settings
    }
  },
  "downloader": {
    "filesize-min": null,
  ... rest of the file

Now it is time to read and follow the documentation. However, here is the gist of it:

  1. Login to your DeviantArt account.
  2. Go to the “Applications & Keys” site which is located at: https://www.deviantart.com/developers/apps
  3. Create (register) a new application adding the URL “https://mikf.github.io/gallery-dl/oauth-redirect.html" under “OAuth2 Redirect URI Whitelist (Required)”.
  4. Click on the “Save” button.
  5. Copy the client-id and client-secret values from the DeviantArt page into your configuration file and add cache as value for refresh-token. All values must be put in double quotes.
...
    },
    "deviantart": {
      "client-id": "CLIENT_ID_FROM_DA",
      "client-secret": "CLIENT_SECRET_FROM_DA",
      "refresh-token": "cache",
...

Now clear your cache with either running gallery-dl --clear-cache deviantart or deleting the directory ~/.cache/gallery-dl. For me the latter option worked better but that might just have been some glitch.

After the cache has been cleared the command gallery-dl oauth:deviantart should open a page in a browser in which you can authorize the application. The refresh token will be cached automatically but it will stop working after 3 months and will need to be renewed then.

This should be it! You should now be able to issue a command and it should start downloading stuff:

gallery-dl https://www.deviantart.com/some-user/some-gallery

Last but not least it might be a good idea to set some options like sleep and sleep-request to sensible values to prevent spamming the API and getting “too many requests” errors or being blocked.

If you instantly get “429 too many requests” errors then check if you have cleared the cache properly and if your configuration file is named correctly. The global one is gallery-dl.conf and the per user one should be ~/.config/gallery-dl/config.json. Alternatively you can specify a configuration file via the -c command line parameter.

🏷