Git Product home page Git Product logo

pybooru's Introduction

Pybooru - Package for Danbooru/Moebooru API

PyPI PyPI GitHub license Documentation Status

Pybooru is a Python package to access to the API of Danbooru/Moebooru based sites.

  • Version: 4.2.2
  • Licensed under: MIT License

Dependencies

  • Python: >= 2.7 or Python: >= 3.3
  • requests

Installation

from Python Package Index (Pypi)

Pybooru on Pypi.

pip install --user Pybooru

Manual installation

git clone git://github.com/luquedaniel/pybooru.git
cd pybooru
pip install --user -r requirements.txt
sudo python setup.py build
python setup.py install

Examples of use

See More examples.

Danbooru

from pybooru import Danbooru

client = Danbooru('danbooru')
artists = client.artist_list('ma')

for artist in artists:
    print("Name: {0}".format(artist['name']))

Login example

from pybooru import Danbooru

client = Danbooru('danbooru', username='your-username', api_key='your-apikey')
client.comment_create(post_id=id, body='Comment content')

Moebooru

from pybooru import Moebooru

client = Moebooru('konachan')
artists = client.artist_list(name='neko')

for artist in artists:
    print("Name: {0}".format(artist['name']))

Login example

Default sites
from pybooru import Moebooru

client = Moebooru('konachan', username='your-username', password='your-password')
client.comment_create(post_id=id, comment_body='Comment content')
Not default sites
from pybooru import Moebooru

client = Moebooru('konachan.com', username='your-username', password='your-password',
                  hash_string='So-I-Heard-You-Like-Mupkids-?--{0}--')
client.comment_create(post_id=id, comment_body='Comment content')

Documentation

You can consult the documentation on Read the Docs

Status

Platform Master Develop
Linux & OSX (Travis CI) Travis CI Travis CI
Windows (AppVeyor) AppVeyor AppVeyor

Contributing

Feel free to contribute, take a look at CONTRIBUTING.

License

pybooru's People

Contributors

ev3rest avatar foolbar avatar hansbug avatar luquedaniel avatar mirukana avatar mpetrole avatar nachtalb avatar narugo1992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pybooru's Issues

Danbooru CSFR problem

Thank you for your work on the development of this very useful code! I have recently encountered an error (it was working fine before, I think that Danbooru changed something in their API)

When using two tags to access random picture:

danbo_client = Danbooru('danbooru')
picture = danbo_client.post_list(tags=_tags, limit=1, random=True)

The following error occurs:
In _request: 422 - Locked, The resource is locked and cannot be modified - URL

After checking what is happening with the link it provides, it actually contains the requested list with a JSON object. But when fetched with python results in the following error:

{
    "backtrace": [],
    "message": "Can't verify CSRF token authenticity.",
    "success": false
}

Expected Behavior

Return of list containing JSON object

Actual Behavior

Proper behavior for 1 tag and 1 tag with rating tag. Error when inputting more than one tag.

Steps to Reproduce

  1. Input more than 2 tags into post_list().

Context

The issue prevents from using more than one tag, excluding rating tag.

Environment

Pybooru Version: 4.2.2
Python Version: 3.8
Operating system: Windows 10
Link to your project: https://github.com/Magos-Errant/Shinsha

Danbooru client.favorite_remove(post_id) bug

I am having an issue with the favorite_remove() function. It will remove the favorite as expected, but it throws an error while doing it. When I refresh my favorites the post is no longer there, but it'd be nice to not see the error.

from pybooru import Danbooru

client = Danbooru('danbooru', username=$USERNAME, api_key=$API_KEY')
post_id = $POST  # as an int
client.favorite_remove(post_id)

I get the following error:

Traceback (most recent call last):
  File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/pybooru.py", line 179, in _request
    return response.json()
  File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/home/ryan/.pyenv/versions/3.8.0/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/home/ryan/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/ryan/.pyenv/versions/3.8.0/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-102-8ebb0139f2f3>", line 1, in <module>
    client.favorite_remove(3694909)
  File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/api_danbooru.py", line 437, in favorite_remove
    return self._get('favorites/{0}.json'.format(post_id), method='DELETE',
  File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/danbooru.py", line 86, in _get
    return self._request(url, api_call, request_args, method)
  File "/home/ryan/.local/share/virtualenvs/img-scraper-CPlRbv_X/lib/python3.8/site-packages/pybooru/pybooru.py", line 185, in _request
    raise PybooruError("JSON Error: {0} in line {1} column {2}".format(
pybooru.exceptions.PybooruError: JSON Error: Expecting value in line 1 column 1

My Environment

  • Pybooru Version: 4.2.0
  • Python Version: 3.8.0
  • Danbooru / Moebooru site: Danbooru
  • Operating System and version: Ubuntu 18.04 LTS

JSON request error

Cannot parse data from Yande.re
<telegram.utils.promise.Promise object at 0x7fa70014ebe0>
'In _json_request: 404, Not Found - Not found -- URL: https://yande.re/post.json'

I cant add more then 1 tag

Ive been trying to add multiple tags for danbooru and I figured it was one of the following:
tags='tag1 tag2'
tags='tag1', 'tag2'
tags=["tag1", "tag2"]
Which it was none of, im greatly confused on this issue and any information would help.

Along with that this one is more simple, but I have no clue on how to declare the site name for moebooru.

Actually, nvm it was just the tag I was using but why doesnt it work?

feature_add(post_id) not working

I am running a function similar to the below after obtaining a post from client.post_list().
I've made sure that the post_id being passed is valid, and the login auth appears to be fine since other functions like favorites_list() work as expected

client = Danbooru('danbooru', username=API_USER, api_key=API_KEY)
def favoriteId(post_id):
    client.favorite_add(post_id)

However, nothing appears to happen and the post is not added to favorites.

Can not upload files to danbooru anymore

It seems that in a recent update the way file uploads are handled is changed in Danbooru? There is some support for bulk uploading, and there are some other changes surrounding this.

Description

I tried the following code:

from pybooru import Danbooru


client = Danbooru(site_url='---my-selfhosted-danboory-url---', username='--my-username---', api_key='---api-key---')

client.upload_create('some tags here', 's', file_='C:/images/76a88b52a8f5c825c2ade9486127b953.jpg')

Expected Behavior

File is uploaded and posted with the given tags

Actual Behavior

Fails.

I printed the response:

{'_content': b'{"success":false,"error":"ActionController::UnpermittedParameters","message":"found unpermitted parameters: :rating, :tag_string, :file","backtrace":["app/controllers/uploads_controller.rb:13:in `create\'"]}

The api key has all access rights and I am "owner" on the board. I can perform all these tasks through the website; but not through the api. I should mention that other scripts and online sources for uploading also fail. I really think danbooru changed something recently.

If needed I can provide my danbooru installation (i can share details in private) for testing. Since it is early in it's hosting cycle you don't have to worry about posting a mess; I will just clean it up.

Support Danbooru "Common Search Parameters" ; at least 'page' and 'limit'

Detailed Description

The Danbooru API docs mention that all searches support a common set of parameters.

None of these common parameters are supported in api_danbooru.py.

I'm specifically interested in the "page" parameter.

Context

I am attempting to use pybooru to fetch notes for all posts [see my project Danbooru2019]. This because qwern doesn't include notes in his dataset.

Anywho, I found the note API will only return 20 notes for a given post. I.e. I'm using pybooru as follows:

nl = client.note_list(post_id=77, is_active=True)

And this only returns 20 notes, whereas post id 77 actually has 21 notes.

So I need to be able to request pages to get all notes, e.g.:

nl = client.note_list(post_id=77, is_active=True, page=1)
if (len(nl) == 20):
  nl = client.note_list(post_id=77, is_active=True, page=2)

Possible Implementation

Reworking api_danbooru.py, note_list as follows appears to do the trick [documentation removed for conciseness]:

    def note_list(self, body_matches=None, post_id=None, post_tags_match=None,
                  creator_name=None, creator_id=None, is_active=None, page=1):

        params = {
            'search[body_matches]': body_matches,
            'search[post_id]': post_id,
            'search[post_tags_match]': post_tags_match,
            'search[creator_name]': creator_name,
            'search[creator_id]': creator_id,
            'search[is_active]': is_active,
            'page' : page
            }
        return self._get('notes.json', params)

Your Environment

  • Pybooru Version: 4.2.2
  • Python Version: 3.8.10
  • Danbooru / Moebooru site: danbooru
  • Operating System and version: Linux Mint 20.1
  • Link to your project: Danbooru2019

danbooru hot page support

i can't seem to find danbooru's hot page support here but it be amazing if you add it very helpful

Move to asyncio & aiohttp?

I was wondering if you had any plans on moving the library to asyncio and aiohttp, and in general putting effort into making the library asynchronous? Thank you, Daniel!

[TypeError]: list indices must be integers or slices, not str

Well, i'm getting the next error:

[TypeError]: list indices must be integers or slices, not str

While using the Moebooru client. This is my code:

@commands.command(pass_context = True)
    async def booru(self, ctx, *args):
        """Obtiene una imagen aleatoria de cualquier Booru"""
        mention = '<@{}>'.format(ctx.author.id)
        try:
            if funcs.noMention(ctx.message):
                try:
                    booru = args[0]
                    tags = list(args)
                    tags.pop(0)
                    tags = ' '.join(map(str, args))
                    client = Moebooru(booru, username = self.Bot.danbooru_username)
                    post = client.post_list(tags = tags, page = randint(1, 1000), limit = 1)
                    try:
                        image_url = post[0]['file_url']
                    except:
                        image_url = 'https://danbooru.donmai.us{}'.format(post['source'])
                    async with ctx.channel.typing():
                        embed = discord.Embed(title = 'There you go!')
                        embed.set_image(url = image_url)
                        async with ctx.channel.typing():
                            await ctx.channel.send('{}'.format(mention), embed = embed)
                except Exception as e:
                    async with ctx.channel.typing():
                        print('Comando booru: [{}]: {}'.format(type(e).__name__, e))
                        await ctx.channel.send('{}, me temo que no pude conseguir una imagen.'.format(mention))
                    
            else:
                await ctx.channel.send('{}, evita las menciones al utilizar este comando.'.format(mention))

        except Exception as e:
            print('Comando booru: [{}]: {}'.format(type(e).__name__, e))

I'm using discord.py (rewrite) and I can't find where the error is, any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.