GithubHelp home page GithubHelp logo

azuline / pixiv-api Goto Github PK

View Code? Open in Web Editor NEW
123.0 8.0 13.0 624 KB

A documented, idiomatic, and tested wrapper library around Pixiv's App API.

Home Page: https://pixiv-api.readthedocs.io/

License: Apache License 2.0

Python 99.95% Makefile 0.05%
pixiv-api pixiv python

pixiv-api's Introduction

pixiv-api

CI Codecov Docs PyPI

A documented, idiomatic, and tested wrapper library around Pixiv's App API.

Supports Python versions 3.6+.

Install with:

$ pip install pixiv-api

Quickstart

To start making requests to the Pixiv API, instantiate a client object.

from pixivapi import Client

client = Client()

The client can be authenticated to Pixiv's API in multiple ways. One is by logging in with a username and password:

client.login("username", "password")

And another is with a refresh token.

client.authenticate("refresh_token")

Once authenticated, a refresh token can be saved for future authorizations.

refresh_token = client.refresh_token

After authenticating, the client can begin making requests to all of the Pixiv endpoints. For example, the following code block downloads an image from Pixiv.

from pathlib import Path
from pixivapi import Size

illustration = client.fetch_illustration(75523989)

illustration.download(
    directory=Path.home() / "my_pixiv_images",
    size=Size.ORIGINAL,
)

And the next code block downloads all illustrations of an artist.

from pathlib import Path
from pixivapi import Size

artist_id = 2188232
directory = Path.home() / "wlop"

response = client.fetch_user_illustrations(artist_id)

while True:
    for illust in response["illustrations"]:
        illust.download(directory=directory, size=Size.ORIGINAL)

    if not response["next"]:
        break

    response = client.fetch_user_illustrations(
        artist_id,
        offset=response["next"],
    )

Read the full documentation at https://pixiv-api.readthedocs.io.

License

Copyright 2021 blissful

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

pixiv-api's People

Contributors

andre-v avatar azuline avatar dreipixel avatar orbitalperiod avatar sentouki 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  avatar  avatar  avatar  avatar

pixiv-api's Issues

Discussion: login

Hey there, I am working on a similar project on Pixiv called Pikax. my api could not login into Pixiv from about 1 weeks ago. I see alot of people are using https://oauth.secure.pixiv.net/auth/token, however, I do not quiet understand how it works, do you mind make a little explaination to me? Thanks

If you're still working on this project, I added Novel and Ugoira download support

After using this lib to make a pixiv downloader, I needed Novel and Ugoira support, so I added a Ugoira class, with download and create_gif method, and added a download method to the Novel class

I also added some methods to Client:
fetch_novel (returns a Novel class)
fetch_user_novels (returns a dict: {'novels': List[Novel], 'next': int | None}
fetch_ugoira (returns a Ugoira class)
fetch_novel_text (returns a dict)

I also made it, when an Illustration is of content-type "UGOIRA", it fetches the Ugoira metadata and downloads that

I intend to add Fanbox support as well

Offset issue with fetch_illustrations_following?

Tried to retrieve illustrations from followers but am only able to retrieve 30 illustrations and when I tried

response = client.fetch_illustrations_following(Visibility.PUBLIC, offset=response['next']),

I only get the same 30 illustrations (the first 30) instead of the next 30 illustrations.

Could be an issue in the GET response where offset isn't passed as the params? Not sure or am I just using this fetch_illustrations_following wrongly?

CloudflareChallengeError

I've just started a new project using the python API. I have gotten a new refresh token using this link. I've tried writing a simple program to test and see if the login works. But the below exception is thrown. How do I solve this?

Exception has occurred: CloudflareChallengeError
Detected a Cloudflare version 2 Captcha challenge, This feature is not available in the opensource (free) version.

Help about client id and secret

You use client_id='KzEZED7aC0vird8jWyHM38mXjNTY' and client_secret='W9JZoJe00qPvJsiyCGT3CCtC6ZUtdpKpzMbNlUGP'. Could you help me how to create my own pair?

Auth issue

hey there, pixiv update its validation on the android. There is a discussion here and it has been fixed by this commit. The reason is pixiv now checks x-client-time and x-client-hash according to the discussion so we need to add them in the headers like:
'X-Client-Time': local_time,
'X-Client-Hash': hashlib.md5((local_time+self.hash_secret).encode('utf-8')).hexdigest(),
where self.hash_secret is a constant: '28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c'.
I have no idea where he found these so I can't provide more details ._.

Model outdated

Client.fetch_user fails, because FullUser doesn't expect the is_user_access_blocked argument. I assume there are likely other incompatibilities, but I haven't yet had the time to experiment with it.

Updating the api is the obvious solution, but it would probably also help to add some tolerance for unrecognized fields.

If any more info is needed from me, I'll be glad to provide it.

AttributeError with python 3.6.9 on Ubuntu 18.04

When I tried to run example code in https://pixiv-api.readthedocs.io/en/latest/, I got an AttributeError as follow:

Traceback (most recent call last):
File "pixiv_works_download.py", line 9, in
illustration = client.fetch_illustration(75523989)
File "/home/void/.local/lib/python3.6/site-packages/pixivapi/common.py", line 25, in wrapper
return func(self, *args, **kwargs)
File "/home/void/.local/lib/python3.6/site-packages/pixivapi/client.py", line 251, in fetch_illustration
client=self,
File "/home/void/.local/lib/python3.6/site-packages/pixivapi/models.py", line 240, in init
self.create_date = datetime.fromisoformat(create_date)
AttributeError: type object 'datetime.datetime' has no attribute 'fromisoformat'

My code:

from pixivapi import Client
from pathlib import Path
from pixivapi import Size

client = Client()

client.login('<my_username>', '<my_password>')

illustration = client.fetch_illustration(75523989)
illustration.download(
    directory=Path.home() / 'my_pixiv_images',
    size=Size.ORIGINAL,
)

Code block in the documentation

Hello! Sorry in advance if I'm wrong, but this code block in the documentation doesn't seem to work with profiles with small amount of illustrations, for example this profile
Here is the code i've used, copypasted everything from man except id, login and a folder
Also tried the same code with different id, worked perfectly

from pathlib import Path
from pixivapi import Size
from pixivapi import Client

client = Client()
client.login("****","*****")

artist_id = 14080533
directory = Path.home() / 'Boo'

response = client.fetch_user_illustrations(artist_id)
while response['next']:
    for illust in response['illustrations']:
        illust.download(directory=directory, size=Size.ORIGINAL)

    if response['next']:
        response = client.fetch_user_illustrations(
            artist_id,
            offset=response['next'],
        )

Login Not Working

login not working, might be related to the website's recent update to accommodate apple login.

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.