GithubHelp home page GithubHelp logo

sinkaroid / booru Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 3.0 214 KB

Python bindings for booru imageboards

Home Page: https://sinkaroid.github.io/booru

License: MIT License

Python 100.00%
booru danbooru gelbooru rule34

booru's Introduction

Sinkaroid here

Skills - Portfolio - Twitter - LinkedIn - MyAnimeList - Steam

I am a part time software developer mostly open-source also by the trade. I have no degree alias never go to formal college education, so keep in mind that if you want to hire me, I might not remember the complexity of interpolation search algorithm, but I'm good and patient in experimenting for it.

On my profile, PyPi, npm, and Docker You'll see some of the repositories I've made for various projects.
I don't have much to say as I'm not a talkative person right now

booru's People

Contributors

sinkaroid 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

Watchers

 avatar  avatar

booru's Issues

List index out of range

I cant seem to figure out the exact reason it occurs but some search terms result in a "list index out of range".
im using this with a discord bot and so far everything is working except for a few random searches like searching safebooru for "rem" or rule34 for "princess_rosalina". (Both of these searches work on the actual site itself.
exact error:
`[2022-10-08 20:08:46] [ERROR ] discord.client: Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\booru\client\safebooru.py", line 139, in search
return better_object(self.not_random[randint(0, len(self.not_random))])
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 409, in _run_event
await coro(*args, **kwargs)
File "C:\Users\xxxxx\Downloads\Python programs\waifu.py", line 109, in on_message
res = await imgs.search(query=content, random=True, gacha=True)
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\booru\client\safebooru.py", line 148, in search
raise ValueError(f"Failed to get data: {e}")
ValueError: Failed to get data: list index out of range`

  • OS: windows 11
  • Python: 3.10.7

String slices must be integers.

Describe the bug
try:
images = [i["file_url"] for i in data]

except:
images = [i["file"]["url"] for i in data]

Gives the error. This is yours interpreter.

To Reproduce
Steps to reproduce the behavior:

  1. Use parse_image(result) on:
    result = await r34.search_image("neko", limit=2) # test

Expected behavior
Give me only the url.

Desktop (please complete the following information):

  • OS: Arch Linux
  • Python version: 3.10.10 and 3.11.3

Additional context
No.

Issue with rasberry pi

Describe the bug
I used the lib on a discord bot to send picture ,it work perfectly on my pc but when i put my code on my rasberry pi i have a timed out error

Desktop (please complete the following information):

  • OS: rasbian
  • Python version 3.9.2

Resolve : i don't know why but the site is blocked by my country only on my rasberry

[Bug] "got an unexpected keyword argument 'encoding'" from json.loads deserialization

Describe the bug
When running the gelbooru example:

gel = booru.Gelbooru()
res = await gel.search(query="cat_girl", limit=50)

I get an error:

parser.py", line 145, in deserialize
return json.loads(better_object(data), encoding="utf-8")
File "/usr/lib/python3.9/json/init.py", line 359, in loads
return cls(**kw).decode(s)
TypeError: init() got an unexpected keyword argument 'encoding'

To Reproduce
Steps to reproduce the behavior:
Run the gelbooru example from the pip install page.

Expected behavior
Retrieves an image from gelbooru.

Desktop (please complete the following information):

  • OS: Debian
  • Python version: 3.9

Danbooru Api Key Login throws Key 0

Describe the bug
Using the Api key and the user_id to log into danbooru will not work
the error:
Traceback (most recent call last):
File "test.py", line 10, in
asyncio.run(main())
File "C:\anaconda\envs\bot\lib\asyncio\runners.py", line 43, in run
return loop.run_until_complete(main)
File "C:\anaconda\envs\bot\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "test.py", line 6, in main
res = await dan.search(query="cat_girl", limit=1)
File "C:\anaconda\envs\bot\lib\site-packages\booru\client\danbooru.py", line 130, in search
self.not_random = Danbooru.append_obj(self.final)
File "C:\anaconda\envs\bot\lib\site-packages\booru\client\danbooru.py", line 38, in append_obj
if "id" in raw_object[i]:
KeyError: 0

To Reproduce
Intitialize Danbooru exactly like the documentation instructs.
using the username or number only user ID will not work
Gelbooru works however

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: Windows with Anaconda
  • 3.8.5

Additional context

get_images sometimes fails with danbooru

Describe the bug
Fails to fetch images with get_images from danbooru in case the result contains a taken down image (flagges by is_banned). It throws "ValueError: Failed to get data"

To Reproduce
Ask for enough images with get_images from danbooru

Expected behavior
Just skip over the post and return the images

Desktop (please complete the following information):

  • OS: Debian Bullseye
  • Python 3.10

Additional context
I fixed the bug by modifying the parser code and will propose a pull request referencing the issue. Also, I'd suggest removing try except block from danbooru where it says "ValueError(f"Failed to get data") as it is not descriptive and I had to remove it to track down the issue myself. I will do it in the pull request.

Library is not ready for async usage

At the moment, the documentation of booru says

This lib should be run in async context, and it's recommended to use asyncio

However, the library depends on requests, a very good HTTP library that is blocking, which means that calls to boorus will also block, which is not aligned with the asyncio model.

Because of that, the following piece of code, inspired by the README:

import asyncio
import booru

async def main():
    gel = booru.Gelbooru()
    # search for 1000 random cat_girls, in parallel batches of 100 at once to the Gelbooru API
    results = await asyncio.gather(*[
        gel.search("cat_girl sort:random")
        for _ in range(10)
    ])
    results = [booru.resolve(res) for res in results]
    print(results)

asyncio.run(main())

Will run each booru search sequentially, because requests.get blocks every other coroutine from doing any work. So, if gelbooru takes 1 second per request, that script would take a total of 10 seconds, where it would be expected for it to take around 1-3 seconds depending on network conditions and whatnot.

On my use-case, I create hundreds of tasks that are forced to operate sequentially, even though I want to have say, 10 of them running in parallel.

The library should either

  • Consider an async HTTP library for its internals, like aiohttp, or
  • Don't recommend itself as being used in an async context, as that is misleading.

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.