How to Batch Download Images Using gallery-dl

Let's say you're a fan of a celebrity, or simply infatuated with a certain female idol on Twitter, or a sports fan who endlessly loops Jordan videos, or simply want to learn and enrich your extracurricular life. Then you'll definitely have a need to batch download images (including videos). Don't tell me you click them one by one.

I didn't have this need very strongly before, until one day I discovered that someone I liked had quit the internet—maybe they were banned, maybe they sold their account, or maybe they simply stopped using it.

At this point, it always makes you regret downloading and saving more things beforehand.

gallery-dl is a pretty good image downloader.

See the tutorial below:

1. Installation

I'm using Arch Linux, so I installed it directly using Paru.

1paru -S gallery-dl

This is very simple and straightforward. For other distributions or operating systems, please refer to the official repository https://github.com/mikf/gallery-dl for instructions.

2. Configuration Example

Take Twitter as an example

 1➜  ~ cat .config/gallery-dl/config.json
 2{
 3  "extractor": {
 4    "base-directory": "~/Pictures/",
 5    "twitter": {
 6      "videos": true,
 7      "retries": 5,
 8      "sleep": "2.0-3.5",
 9      "sleep-429": 2,
10      "image-filter": "user is author",
11      "filename": "{author[name]}-{tweet_id}-{date:%Y%m%d_%H%M%S}-img{num}.{extension}"
12    }
13  }
14}
  • base-directory: The directory where downloaded videos will be stored.
  • videos: Download example; change to false if only downloading images.
  • retries: Number of retries (5)
  • sleep: Download interval (2.0s to...) 3.5s, too fast, be careful of getting your IP blocked, better to be conservative.
  • sleep-429: Wait 2 seconds after encountering a 429 error.
  • image-filter is the image attribute filtering rule for gallery-dl, using Python expressions to filter images to be downloaded; it can be quite complex. user is author only downloads images created by the target user; untested and unverified.
  • filename: The filename format is crucial; nobody wants downloaded images with messy names!

The above includes the core configuration; this is how I wrote it.

As for other platforms, such as Instagram, you need to refer to the official configuration documentation. Platform anti-scraping strategies vary greatly, so different configurations are understandable.

3. Download Test

Test like this : gallery-dl -vv --cookies-from-browser firefox "https://x.com/zoe2496/media

Actually, the above configuration omits the cookies part. Its core function is to provide gallery-dl with valid X account login credentials, allowing gallery-dl to "disguise" itself as your logged-in browser and download authorized images, videos, and other content.

The --cookies-from-browser firefox parameter means that gallery-dl automatically extracts saved X account login cookies from your Firefox browser, eliminating the need for you to manually export and configure the cookies file.

For example, if you are using Linux, it will filter for cookies belonging to the x.com domain from paths like /home/mephisto/.mozilla/firefox/5esrorfn.default-release/cookies.sqlite. As long as the browser has previously been logged into the X account, the cookies will be valid (usually for a few days to a few weeks), which is quite convenient.

I opened Firefox, found the account I wanted to download, and then ran the following command to download it:

 1➜  twitter gallery-dl -vv --cookies-from-browser firefox  "https://x.com/zoe2496/media"
 2[gallery-dl][debug] Version 1.31.1
 3[gallery-dl][debug] Python 3.13.11 - Linux-6.18.2-arch2-1-x86_64-with-glibc2.42
 4[gallery-dl][debug] requests 2.32.5 - urllib3 2.6.2
 5[gallery-dl][debug] Configuration Files ['${HOME}/.config/gallery-dl/config.json']
 6[gallery-dl][debug] Starting DownloadJob for 'https://x.com/zoe2496/media'
 7[twitter][debug] Using TwitterMediaExtractor for 'https://x.com/zoe2496/media'
 8[cookies][debug] Extracting cookies from /home/mephisto/.mozilla/firefox/5esrorfn.default-release/cookies.sqlite
 9[cookies][debug] Only loading cookies not belonging to any container
10[cookies][info] Extracted 1793 cookies from Firefox
11[urllib3.connectionpool][debug] Starting new HTTPS connection (1): x.com:443
12......此处省略......
13[twitter][debug] Sleeping 3.39 seconds (download)
14b[urllib3.connectionpool][debug] Starting new HTTPS connection (1): pbs.twimg.com:443
15[urllib3.connectionpool][debug] https://pbs.twimg.com:443 "GET /media/G9cQxetaYAIlyhR?format=jpg&name=orig HTTP/1.1" 200 921878
16/home/mephisto/Pictures/twitter/zoe2496/zoe2496-2006090615453544936-20251230_195048-img1.jpg
17[twitter][debug] Sleeping 3.26 seconds (download)
18[urllib3.connectionpool][debug] Starting new HTTPS connection (1): video.twimg.com:443
19[urllib3.connectionpool][debug] https://video.twimg.com:443 "GET /amplify_video/2006085163848269824/vid/avc1/1280x720/m-ShyiwCyNr8TJGh.mp4?tag=21 HTTP/1.1" 200 1299406
20/home/mephisto/Pictures/twitter/zoe2496/zoe2496-2006085231040946664-20251230_192924-img1.mp4
21[twitter][debug] Sleeping 2.32 seconds (download)
22[urllib3.connectionpool][debug] https://pbs.twimg.com:443 "GET /media/G9cJXkHawAASbGl?format=jpg&name=orig HTTP/1.1" 200 176456
23/home/mephisto/Pictures/twitter/zoe2496/zoe2496-2006082468605247944-20251230_191826-img1.jpg

Looking at the output above, the images are downloaded randomly at intervals of 2.0-3.5 seconds, and the filenames are also very standardized. I'm so happy! 😄

4. Other

The above will download all images from the user's media account. You can also write your own filter:

  • "image-filter": ["user is author", "width >= 1200", "height >= 800"] // Combined use: Original + High Definition

I'm rather lazy and have limited energy. There are countless experts on the internet, so I'll just take a look and download them all.

Ambitious young people should spend more time and money to learn real skills. Friendly reminder: This article is purely for technical sharing. The internet is not a lawless place. Please be discreet and cherish what you have.

Lastmod: Wednesday, December 31, 2025

See Also:

Translations: