Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support getting multiple illusts under same pid #373

Open
isaswa opened this issue Dec 7, 2024 · 1 comment
Open

support getting multiple illusts under same pid #373

isaswa opened this issue Dec 7, 2024 · 1 comment
Labels

Comments

@isaswa
Copy link

isaswa commented Dec 7, 2024

An artwork page for a pid could have multiple illusts under it.

But the following only return the first image url everytime:

json_result = pixiv_api.illust_detail(pid)
illust = json_result.illust
print(illust.image_urls["large"])

One can fix this by checking if json_result.illust contains meta_single_page or meta_pages fields.
If the pid correspond to an one-artwork entity, it would have data in meta_single_page but meta_pages=[].
On the other side, a multi-artwork entity would have meta_pages but no meta_single_page field at all.

here's an example:

def get_all_image_urls(pid: int) -> List[str]:
    json_result = pixiv_api.illust_detail(pid)
    multi = json_result.illust.meta_pages
    if len(multi) == 0:
        single = json_result.illust.meta_single_page
        return [single.original_image_url]
    else:
        urls = [page.image_urls.original for page in multi]
        return urls
@isaswa isaswa changed the title how to get all illusts under same pid? illust_detail() cannot get multiple illusts under same pid Dec 7, 2024
@isaswa isaswa changed the title illust_detail() cannot get multiple illusts under same pid support getting multiple illusts under same pid Dec 7, 2024
@Xdynix
Copy link
Collaborator

Xdynix commented Dec 7, 2024

pixivpy is simply returning what Pixiv server gave us, so we have nothing to do with the response shape.

My snippet of downloading illustrations is very similar to yours:

if illust.type == "ugoira":
    ...
elif illust.page_count == 1:
    img_urls = [illust.meta_single_page.original_image_url]
else:
    img_urls = [
        page.image_urls.original
        for page in illust.meta_pages
    ]

@upbit upbit added the question label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants