Skip to content

Commit

Permalink
[danbooru] add authentication support (closes #151)
Browse files Browse the repository at this point in the history
... via HTTP Basic Auth with username and "password".

The password value in this case is not the account password itself,
but the"api_key" found in your user profile.
  • Loading branch information
mikf committed Jan 9, 2019
1 parent 06cbf5f commit 1e4d351
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ Description The username and password to use when attempting to log in to

Specifying username and password is
required for the ``pixiv``, ``nijie`` and ``seiga`` modules and
optional (but strongly recommended) for ``exhentai``,
optional (but strongly recommended) for ``danbooru``, ``exhentai``,
``sankaku`` and ``idolcomplex``.

These values can also be set via the ``-u/--username`` and
``-p/--password`` command-line options or by using a |.netrc|_ file.
(see Authentication_)

Note: The password for ``danbooru`` is the API key found in your
user profile, not the password for your account.
=========== =====


Expand Down
10 changes: 10 additions & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
{
"external": false
},
"danbooru":
{
"username": null,
"password": null
},
"deviantart":
{
"refresh-token": null,
Expand Down Expand Up @@ -72,6 +77,11 @@
"password": null,
"ugoira": true
},
"reactor":
{
"wait-min": 3.0,
"wait-max": 6.0
},
"recursive":
{
"blacklist": ["directlink", "oauth", "recursive", "test"]
Expand Down
7 changes: 6 additions & 1 deletion gallery_dl/extractor/danbooru.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2014-2018 Mike Fährmann
# Copyright 2014-2019 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -29,6 +29,11 @@ def __init__(self, match):
self.api_url = "{scheme}://{subdomain}.donmai.us/posts.json".format(
scheme=self.scheme, subdomain=self.subdomain)

username, api_key = self._get_auth_info()
if username:
self.log.debug("Using HTTP Basic Auth for user '%s'", username)
self.session.auth = (username, api_key)


class DanbooruTagExtractor(booru.TagMixin, DanbooruExtractor):
"""Extractor for images from danbooru based on search-tags"""
Expand Down

0 comments on commit 1e4d351

Please sign in to comment.