Open carter-yagemann opened 4 years ago
Hi, yes this sounds great. Feel free to issue a pull request.
Digging into the problem deeper, it turns out the pixiv library also uses requests
under the hood in the same way this project does, so the problem is more interesting than I initially realized.
It turns out that depending on which API you use, the pixiv library will return a different set of image URLs, even for the same illustration:
>>> api = pixivpy3.AppPixivAPI() # what sauncebot uses
>>> api.illust_detail(77756873).illust.image_urls
{'square_medium': 'https://i.pximg.net/c/540x540_10_webp/img-master/img/2019/11/11/01/21/28/77756873_p0_square1200.jpg', 'medium': 'https://i.pximg.net/c/540x540_70/img-master/img/2019/11/11/01/21/28/77756873_p0_master1200.jpg', 'large': 'https://i.pximg.net/c/600x1200_90_webp/img-master/img/2019/11/11/01/21/28/77756873_p0_master1200.jpg'}
>>> api = pixivpy3.PixivAPI() # an alternative "public" API in the same library
>>> api.works(77756873).response[0].image_urls
{'px_128x128': 'https://i.pximg.net/c/128x128/img-master/img/2019/11/11/01/21/28/77756873_p0_square1200.jpg', 'small': 'https://i.pximg.net/c/150x150/img-master/img/2019/11/11/01/21/28/77756873_p0_master1200.jpg', 'medium': 'https://i.pximg.net/c/600x600/img-master/img/2019/11/11/01/21/28/77756873_p0_master1200.jpg', 'large': 'https://i.pximg.net/img-original/img/2019/11/11/01/21/28/77756873_p0.png', 'px_480mw': 'https://i.pximg.net/c/480x960/img-master/img/2019/11/11/01/21/28/77756873_p0_master1200.jpg'}
When the App API is used, some of the image URLs contain the _webp
suffix, which are the problematic ones for iOS. For some reason, I've never encountered a webp encoded image URL using the public API.
I guess the best solution for this project is to switch APIs, which shouldn't be too painful.
Summary
The bot is currently downloading Pixiv images in an encoding that is not supported by some versions of iOS, causing images to not display in the Discord app and browsers.
Details
In two locations, the bot uses the
requests
module to fetch Pixiv images:https://github.com/JeremyRuhland/saucebot-discord/blob/c7a348a57e1ced49abffcfad5cb9fe0c5e10c488/saucebot-discord.py3#L259
https://github.com/JeremyRuhland/saucebot-discord/blob/c7a348a57e1ced49abffcfad5cb9fe0c5e10c488/saucebot-discord.py3#L275
The Pixiv CDN responds with a webp/VP8 encoded JPEG:
which cannot be decoded in at least some versions of iOS:
Same problem occurs if the image URL is opened in iOS browsers (tested: safari, chrome).
Proposed Solution
The
download()
method inpixivpy3
retrieves images in a more widely compatible encoding:Thus, I propose using this in place of
requests
.If this sounds good, I can open a pull request, thanks.