Coder Social home page Coder Social logo

asadahimeka / booru-search Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 1.68 MB

Searches boorus for images using some js magic. Booru 站点图片搜索 API

Home Page: https://cocomi.eu.org/booru-search/

License: MIT License

JavaScript 11.88% TypeScript 88.12%
booru typescript booru-browser booru-client booru-gallery danbooru gelbooru gelbooru-client konachan konachan-api

booru-search's Introduction

booru

npm GitHub Typescript typings

English | 中文

A node package to search boorus

Forked from AtoraSuunva/booru

Features

  • Search 20 different boorus (check sites.json)
  • Normalizes all received data into Post objects that are consistent no matter which booru you use
  • Access to the raw data received from the booru as well (transformed from XML to JSON, if applicable)
  • Alias support for boorus (sb for safebooru.org)
  • Promises
  • Types (using Typescript)
  • Choose the amount of images to get
  • Random support for all sites, using order:random on sites that support it and using custom code on those that don't
  • Both browser(without cross-domain) and Node.js support
  • Coming soon(-ish): Support for more than just searching

Installation

npm i @himeka/booru
# or
yarn add @himeka/booru

Usage

const Booru = require('@himeka/booru')

Booru.search('safebooru', ['glaceon'], { limit: 3, random: true }).then(
  posts => {
    for (let post of posts) console.log(post.fileUrl, post.postView)
  },
)

// or (using alias support and creating boorus)
const sb = Booru.forSite('sb')

sb.search(['cat', 'dog'], { limit: 2 })

See example.js for more examples


Docs

Available here: docs

Web support

booru was built for Node.js, and is only officially supported for Node.js. Issues relating to web are fine, although support might be limited.

It's possible to use booru on the web using webpack (or similar), although your experience may vary. Some websites don't have the proper CORS headers, meaning that API requests to those sites from a browser will fail! This is not an issue I can fix in the package, and requires either that booru to add proper support themselves or for you to find a workaround for CORS.

For sites that do not support CORS, you can hack the code as follows, noting that this code should be placed before importing @himeka/booru.

The CORS proxy needs to support calls of the form https://cors.example.com/https://konachan.net/post.json.

const _fetch = window.fetch
const proxy = 'https://cors.example.com/' // Replace with your own CORS proxy
window.fetch = (input, init) => {
  let url = input.toString()
  if (url.startsWith('https')) {
    url = proxy + url
  }
  return _fetch(url, init)
}

FAQ

What are the properties of a Post?

The basic structure of a Post object looks like:

Post {
  _data: {/*...*/},                       // The raw data from the booru
  fileUrl: 'https://aaaa.com/img.jpg',    // The direct link to the image, ready to post
  id: '124125',                           // The image ID, as a string
  tags: ['cat', 'cute'],                  // The tags, split into an Array
  score: 5,                               // The score as a Number
  source: 'https://ex.com/aaa.png',       // Source of the image, if supplied
  rating: 's',                            // Rating of the image
  createdAt: Date,                        // The `Date` this image was created at
  postView: 'https://booru.ex/show/12345' // A URL to the post
}

s: 'Safe' q: 'Questionable' e: 'Explicit' u: 'Unrated'

Derpibooru has Safe, Suggestive, Questionable, Explicit, although Suggestive will be shown as q in <Post>.rating

Can I contribute?

Sure! Just fork this repo, push your changes, and then make a PR.

I'll accept PR based on what they do and code style (Not super strict about it, but it's best if it roughly follows the rest of the code)

Why?

Why not?

License?

It's MIT


Contributors

BobbyWibowo

Change from request-promise-native to snek-fetch

rubikscraft

Add 2 new boorus (furry.booru.org/realbooru.com) Various Derpibooru fixes

Favna

Add TypeScript declarations Improve TypeScript port Various other small fixes

negezor

Add missing type information


booru-search's People

Contributors

asadahimeka avatar atorasuunva avatar bobbywibowo avatar favna avatar negezor avatar slayerduck avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lorenzxz

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.