Skip to content

Developer Instructions

SpiffyChatterbox edited this page Sep 22, 2024 · 4 revisions

Developer Instructions

Building

Most users do not need to build gallery-dl and can download the builds or install them normally.

Running

To run gallery_dl as a developer, you don't need to build anything either. Simply execute

python -m gallery_dl <url>

Testing

To run a test, simply invoke your favorite test runner, or execute a test file directly; any of the following work:

  • python test_results.py YOUR_CATEGORY
  • make test

Embedding

From another Python script, you can call gallery-dl as a module (or library).

from gallery_dl import config, job

config.load()  # load default config files
config.set(("extractor",), "base-directory", "/tmp/")
config.set(("extractor", "imgur"), "filename", "{id}{title:?_//}.{extension}")

for url in urls:
    job.DownloadJob(url).run()

Of course, you'll want to configure your various options available in the Configuration options. Here are some examples of settings that you can configure using config.set:

config.set(('extractor',), "archive", '~/.gallery-dl/archive.sql')
config.set(('extractor',), "base-directory", '~/downloads')
config.set(('extractor', 'deviantart'), "image-range", '1-10')
config.set(('extractor', 'deviantart'), "flat", False)
config.set(('extractor', 'deviantart'), "metadata", True)
config.set(
    ('extractor',),
    'postprocessors',
    [
        {
            "name": "metadata",
            "mode": "json",
        }
    ]
)

You may want to add some logging to your script. Here is an example of how to do that:

import logging
from gallery_dl import output

# initialze logging and setup logging handler to stderr
output.initialize_logging(logging.INFO)
# apply config options to stderr handler and create file handler
output.configure_logging(logging.INFO)
# create unsupported-file handler
output.setup_logging_handler("unsupportedfile", fmt="{message}")

Previous discussions on this topic:

https://github.com/mikf/gallery-dl/issues/5521  
https://github.com/mikf/gallery-dl/issues/642