pysaucenao


Namepysaucenao JSON
Version 1.3.3 PyPI version JSON
download
home_pagehttps://github.com/FujiMakoto/pysaucenao
SummaryPySauceNao is an unofficial asynchronous library for the SauceNao API. It supports lookups via URL or from the local filesystem.
upload_time2020-07-30 12:16:09
maintainer
docs_urlNone
authorMakoto
requires_python
licensegpl-3.0
keywords saucenao anime artwork
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PySauceNao
[![GitHub](https://img.shields.io/github/license/FujiMakoto/pysaucenao)](https://github.com/FujiMakoto/pysaucenao/blob/master/LICENSE) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pysaucenao)](https://pypi.org/project/pysaucenao/) [![PyPI](https://img.shields.io/pypi/v/pysaucenao)](https://pypi.org/project/pysaucenao/) [![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/fujimakoto/pysaucenao/latest)](https://github.com/FujiMakoto/pysaucenao/releases)

PySauceNao is an unofficial asynchronous library for the [SauceNao](https://saucenao.com/) API. It supports lookups via URL or from the local filesystem.

# Installation
This library requires [Python 3.6](https://www.python.org) or above.

You can install the library through pip as follows,
```shell script
pip install pysaucenao
```

## Usage
```python
from pysaucenao import SauceNao
sauce = SauceNao(self, *, api_key: Optional[str] = None,
                 db_mask: Optional[int] = None,
                 db_mask_disable: Optional[int] = None,
                 db: int = 999,
                 results_limit: int = 6,
                 min_similarity: float = 50.0,
                 test_mode: int = 0,
                 strict_mode: bool = True,
                 loop: Optional[asyncio.AbstractEventLoop] = None)

# results = await sauce.from_file('/path/to/image.png')
results = await sauce.from_url('https://i.imgur.com/QaKpV3s.png')
repr(results)
```
```
<SauceNaoResults(count=2, short_avail=3, long_avail=87, results=[<GenericSourc... Nico Seiga')>, <GenericSourc...e='Danbooru')>])>
```

The library attempts to provide a developer friendly container format for all results. Meaning, no matter if SauceNao returns a Pixiv source result or a more obscure source, you'll be able to easily pull the title, author URL and other useful information.

```python
from pysaucenao import SauceNao, PixivSource
sauce = SauceNao()
results = await sauce.from_url('https://i.imgur.com/oVPWy7f.png')

len(results)  # 4

# Find out how many API request limits you have remaining after a search query
results.short_remaining  # 3 (per 30 seconds limit)
results.long_remaining   # 86 (per day limit)

# You can determine whether the search result is a Pixiv, Booru, Video or Other/Generic result by the type property or type checking
results[0].type  # pixiv
isinstance(results[0], PixivSource)  # True

results[0].similarity     # 96.07
results[0].thumbnail      # Returns a temporary signed URL; not suitable for permanent hotlinking
results[0].title          # なでなでするにゃ
results[0].author_name    # おーじ茶@3日目I-03b
results[0].author_url     # https://www.pixiv.net/member.php?id=122233
results[0].url            # https://www.pixiv.net/member_illust.php?mode=medium&illust_id=66106354
results[0].source_url     # Same as url for Pixiv results, but returns the linked original source URL for Booru entries
results[0].index          # Pixiv
```

Video search results provide three additional properties containing the episode number, estimated timestamp, and release year
```python
from pysaucenao import SauceNao, VideoSource
sauce = SauceNao()
results = await sauce.from_url('https://i.imgur.com/1M8MhB0.png')

if isinstance(results[0], VideoSource):
    results[0].episode    # '1'
    results[0].year       # '2017'
    results[0].timestamp  # '00:07:53 / 00:23:40'
```

MangaSource search results, similarly, provide an additional `chapter` property.

### Advanced usage

#### Additional source URL's
Thanks to [yuna.moe](https://github.com/BeeeQueue/arm-server), pysaucenao is no longer limited to just AniDB source URL's for anime results as of v1.3

To utilize this new feature, you should first verify you are working with an Anime source.

Once you have done that, you will need to preload the ID map by running the **load_ids** method.

If you attempt to access any of the additional AnimeSource properties without first doing this, you will get an IndexError.
```python
from pysaucenao import SauceNao, AnimeSource
sauce = SauceNao()
results = await sauce.from_url('https://i.imgur.com/poAmgY0.png')

if isinstance(results[0], AnimeSource):
    await results[0].load_ids()
```
This will map the AniDB ID SauceNao returns with several other anime databases,
```python
results[0].title        # Made in Abyss
results[0].anilist_id   # 97986
results[0].anilist_url  # https://anilist.co/anime/97986
results[0].mal_url      # https://myanimelist.net/anime/34599
results[0].kitsu_url    # https://kitsu.io/anime/13273
```

#### Priority
If you want to prioritize certain types of results, you can do so using the `priority` setting as of v1.2

The most useful case for this is to prioritize anime results, preventing anime screencaps hosted on DeviantArt and other indexes some taking priority.

To use this in your own code, just initialize SauceNao like so,
```python
sauce = SauceNao(priority=[21, 22])
```
As long as the anime search results are reasonably close to the next best match SauceNao returns, this will make sure the library always returns the anime result first, and ideally never a reposted screen-grab.

If you need to prioritize other indexes, you can find a list of ID's here:
https://github.com/FujiMakoto/pysaucenao/blob/master/pysaucenao/containers.py#L16-L50

## Registering for an API key
If you are performing lots of API queries, you will eventually need to sign up and register for an API key (and possibly upgrade your account for very large request volumes)

You can register for an account on [SauceNAO's website](https://saucenao.com/user.php)

## Error handling
The SauceNao class will throw an exception if any of the following occur:
* You have exceeded your 30-second search query limit (ShortLimitReachedException)
* You have exceeded your 24-hour search query limit (DailyLimitReachedException)
* You attempted to upload a file larger than SauceNAO allows (FileSizeLimitException)
* You provided an invalid API key (InvalidOrWrongApiKeyException)
* The image was too small for use (ImageSizeException)
* Either the URL or file provided was not a valid image (InvalidImageException)
* Too many failed requests made; try again later (TooManyFailedRequestsException)
* Your account does not have API access; contact SauceNao support (BannedException)
* Any other unknown error occurred / service may be down (UnknownStatusCodeException)

All of these exceptions extend a base SauceNaoException class for easy catching and handling.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/FujiMakoto/pysaucenao",
    "name": "pysaucenao",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "saucenao,anime,artwork",
    "author": "Makoto",
    "author_email": "makoto+github@taiga.sh",
    "download_url": "https://files.pythonhosted.org/packages/4a/74/a82642eee1c12cb369de4a0aeef43a8cc1e7eb13290d66a1e6214d039fe8/pysaucenao-1.3.3.tar.gz",
    "platform": "",
    "description": "# PySauceNao\n[![GitHub](https://img.shields.io/github/license/FujiMakoto/pysaucenao)](https://github.com/FujiMakoto/pysaucenao/blob/master/LICENSE) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pysaucenao)](https://pypi.org/project/pysaucenao/) [![PyPI](https://img.shields.io/pypi/v/pysaucenao)](https://pypi.org/project/pysaucenao/) [![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/fujimakoto/pysaucenao/latest)](https://github.com/FujiMakoto/pysaucenao/releases)\n\nPySauceNao is an unofficial asynchronous library for the [SauceNao](https://saucenao.com/) API. It supports lookups via URL or from the local filesystem.\n\n# Installation\nThis library requires [Python 3.6](https://www.python.org) or above.\n\nYou can install the library through pip as follows,\n```shell script\npip install pysaucenao\n```\n\n## Usage\n```python\nfrom pysaucenao import SauceNao\nsauce = SauceNao(self, *, api_key: Optional[str] = None,\n                 db_mask: Optional[int] = None,\n                 db_mask_disable: Optional[int] = None,\n                 db: int = 999,\n                 results_limit: int = 6,\n                 min_similarity: float = 50.0,\n                 test_mode: int = 0,\n                 strict_mode: bool = True,\n                 loop: Optional[asyncio.AbstractEventLoop] = None)\n\n# results = await sauce.from_file('/path/to/image.png')\nresults = await sauce.from_url('https://i.imgur.com/QaKpV3s.png')\nrepr(results)\n```\n```\n<SauceNaoResults(count=2, short_avail=3, long_avail=87, results=[<GenericSourc... Nico Seiga')>, <GenericSourc...e='Danbooru')>])>\n```\n\nThe library attempts to provide a developer friendly container format for all results. Meaning, no matter if SauceNao returns a Pixiv source result or a more obscure source, you'll be able to easily pull the title, author URL and other useful information.\n\n```python\nfrom pysaucenao import SauceNao, PixivSource\nsauce = SauceNao()\nresults = await sauce.from_url('https://i.imgur.com/oVPWy7f.png')\n\nlen(results)  # 4\n\n# Find out how many API request limits you have remaining after a search query\nresults.short_remaining  # 3 (per 30 seconds limit)\nresults.long_remaining   # 86 (per day limit)\n\n# You can determine whether the search result is a Pixiv, Booru, Video or Other/Generic result by the type property or type checking\nresults[0].type  # pixiv\nisinstance(results[0], PixivSource)  # True\n\nresults[0].similarity     # 96.07\nresults[0].thumbnail      # Returns a temporary signed URL; not suitable for permanent hotlinking\nresults[0].title          # \u306a\u3067\u306a\u3067\u3059\u308b\u306b\u3083\nresults[0].author_name    # \u304a\u30fc\u3058\u8336\uff203\u65e5\u76eeI-03b\nresults[0].author_url     # https://www.pixiv.net/member.php?id=122233\nresults[0].url            # https://www.pixiv.net/member_illust.php?mode=medium&illust_id=66106354\nresults[0].source_url     # Same as url for Pixiv results, but returns the linked original source URL for Booru entries\nresults[0].index          # Pixiv\n```\n\nVideo search results provide three additional properties containing the episode number, estimated timestamp, and release year\n```python\nfrom pysaucenao import SauceNao, VideoSource\nsauce = SauceNao()\nresults = await sauce.from_url('https://i.imgur.com/1M8MhB0.png')\n\nif isinstance(results[0], VideoSource):\n    results[0].episode    # '1'\n    results[0].year       # '2017'\n    results[0].timestamp  # '00:07:53 / 00:23:40'\n```\n\nMangaSource search results, similarly, provide an additional `chapter` property.\n\n### Advanced usage\n\n#### Additional source URL's\nThanks to [yuna.moe](https://github.com/BeeeQueue/arm-server), pysaucenao is no longer limited to just AniDB source URL's for anime results as of v1.3\n\nTo utilize this new feature, you should first verify you are working with an Anime source.\n\nOnce you have done that, you will need to preload the ID map by running the **load_ids** method.\n\nIf you attempt to access any of the additional AnimeSource properties without first doing this, you will get an IndexError.\n```python\nfrom pysaucenao import SauceNao, AnimeSource\nsauce = SauceNao()\nresults = await sauce.from_url('https://i.imgur.com/poAmgY0.png')\n\nif isinstance(results[0], AnimeSource):\n    await results[0].load_ids()\n```\nThis will map the AniDB ID SauceNao returns with several other anime databases,\n```python\nresults[0].title        # Made in Abyss\nresults[0].anilist_id   # 97986\nresults[0].anilist_url  # https://anilist.co/anime/97986\nresults[0].mal_url      # https://myanimelist.net/anime/34599\nresults[0].kitsu_url    # https://kitsu.io/anime/13273\n```\n\n#### Priority\nIf you want to prioritize certain types of results, you can do so using the `priority` setting as of v1.2\n\nThe most useful case for this is to prioritize anime results, preventing anime screencaps hosted on DeviantArt and other indexes some taking priority.\n\nTo use this in your own code, just initialize SauceNao like so,\n```python\nsauce = SauceNao(priority=[21, 22])\n```\nAs long as the anime search results are reasonably close to the next best match SauceNao returns, this will make sure the library always returns the anime result first, and ideally never a reposted screen-grab.\n\nIf you need to prioritize other indexes, you can find a list of ID's here:\nhttps://github.com/FujiMakoto/pysaucenao/blob/master/pysaucenao/containers.py#L16-L50\n\n## Registering for an API key\nIf you are performing lots of API queries, you will eventually need to sign up and register for an API key (and possibly upgrade your account for very large request volumes)\n\nYou can register for an account on [SauceNAO's website](https://saucenao.com/user.php)\n\n## Error handling\nThe SauceNao class will throw an exception if any of the following occur:\n* You have exceeded your 30-second search query limit (ShortLimitReachedException)\n* You have exceeded your 24-hour search query limit (DailyLimitReachedException)\n* You attempted to upload a file larger than SauceNAO allows (FileSizeLimitException)\n* You provided an invalid API key (InvalidOrWrongApiKeyException)\n* The image was too small for use (ImageSizeException)\n* Either the URL or file provided was not a valid image (InvalidImageException)\n* Too many failed requests made; try again later (TooManyFailedRequestsException)\n* Your account does not have API access; contact SauceNao support (BannedException)\n* Any other unknown error occurred / service may be down (UnknownStatusCodeException)\n\nAll of these exceptions extend a base SauceNaoException class for easy catching and handling.\n\n\n",
    "bugtrack_url": null,
    "license": "gpl-3.0",
    "summary": "PySauceNao is an unofficial asynchronous library for the SauceNao API. It supports lookups via URL or from the local filesystem.",
    "version": "1.3.3",
    "split_keywords": [
        "saucenao",
        "anime",
        "artwork"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "5726cb2857c83cc5499e596f71a6d456",
                "sha256": "a3ee727b4fc481e37d3517448eb117d7e137a6317e90a25ceab70823b46ddbdf"
            },
            "downloads": -1,
            "filename": "pysaucenao-1.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5726cb2857c83cc5499e596f71a6d456",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 23718,
            "upload_time": "2020-07-30T12:16:06",
            "upload_time_iso_8601": "2020-07-30T12:16:06.910830Z",
            "url": "https://files.pythonhosted.org/packages/37/5e/e2fe8f273c2095b0fdc0d3bf29b589086cf7bef59d47670dc9d0c4a12e41/pysaucenao-1.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "2e2878418b070858215bc894f98729b8",
                "sha256": "b98e2668898ae9ed3c6318aef7017f3b0375075c5f9d5f84b282127d1ce67a0f"
            },
            "downloads": -1,
            "filename": "pysaucenao-1.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2e2878418b070858215bc894f98729b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13431,
            "upload_time": "2020-07-30T12:16:09",
            "upload_time_iso_8601": "2020-07-30T12:16:09.226780Z",
            "url": "https://files.pythonhosted.org/packages/4a/74/a82642eee1c12cb369de4a0aeef43a8cc1e7eb13290d66a1e6214d039fe8/pysaucenao-1.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-07-30 12:16:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "FujiMakoto",
    "error": "Could not fetch GitHub repository",
    "lcname": "pysaucenao"
}
        
Elapsed time: 0.14237s