从pixiv链接图像时,该机器人应链接后续图像,但会产生以下响应:
<ClientResponse(https://i.pximg.net/c/600x1200_90/img-master/img/2019/04/16/00/19/54/74223722_p0_master1200.jpg) [200 OK]>
<CIMultiDictProxy('Server': 'nginx', 'Date': 'Fri, 19 Apr 2019 02:45:02 GMT', 'Content-Type': 'image/jpeg', 'Content-Length': '120412', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=31536000', 'Expires': 'Tue, 14 Apr 2020 15:19:56 GMT', 'Last-Modified': 'Mon, 15 Apr 2019 15:19:54 GMT', 'Via': 'http/1.1 f010 (second), http/1.1 f005 (second)', 'X-Content-Type-Options': 'nosniff', 'Age': '300304', 'Accept-Ranges': 'bytes')>
# Refresh oauth before using API
if (pixiv_links) :
pixivapi.auth()
# Process each pixiv link
for (pixiv_id) in pixiv_links:
# Request submission info
pixiv_result = pixivapi.illust_detail(pixiv_id)
# Check for success from API
if not 'illust' in pixiv_result:
continue
# Check for multi-image set
if len(pixiv_result.illust.meta_pages) > 0:
await message.channel.send('This is part of a {} image set.'.format(len(pixiv_result.illust.meta_pages)))
pixiv_image_link = pixiv_result.illust.image_urls.large
print(message.author.name + '#' + message.author.discriminator + '@' + message.guild.name + ':' + message.channel.name + ': ' + pixiv_image_link)
async with aiohttp.ClientSession() as session:
async with session.get(pixiv_image_link, headers={'Referer': 'https://app-api.pixiv.net/'}) as pixiv_image_rsp:
# Add file name to stream
pixiv_image_rsp.name = pixiv_image_link.rsplit('/', 1)[-1]
await message.channel.send(pixiv_image_rsp)