Fix single image download
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
sclement 2023-10-30 15:35:26 +01:00
parent e78d40f0b8
commit 7f8949271f
2 changed files with 20 additions and 9 deletions

10
main.py
View File

@ -40,7 +40,7 @@ async def on_message(message: discord.Message):
) is not None:
with TemporaryDirectory() as tmp_dir:
async with message.channel.typing():
pixiv.dowload_pixiv_images(
title = pixiv.dowload_pixiv_images(
int(match.group("id")), tmp_dir, REFRESH_TOKEN
)
files = os.listdir(tmp_dir)
@ -62,7 +62,7 @@ async def on_message(message: discord.Message):
splited_embed = to_send_embed[:4]
to_send_embed = to_send_embed[4:]
for embed in splited_embed:
embed.title = f"Part {i}/{parts}"
embed.title = f"{title} - Part {i}/{parts}"
if i == 1:
await message.reply(
files=splited_file, embeds=splited_embed
@ -74,10 +74,14 @@ async def on_message(message: discord.Message):
i = i + 1
for embed in to_send_embed:
embed.title = f"Part {i}/{parts}"
embed.title = f"{title} - Part {i}/{parts}"
await message.channel.send(
files=to_send_files, embeds=to_send_embed
)
else:
for embed in to_send_embed:
embed.title = title
await message.reply(files=to_send_files, embeds=to_send_embed)
client.run(DISCORD_TOKEN)

View File

@ -12,9 +12,16 @@ def dowload_pixiv_images(
json_result = api.illust_detail(illust_id)
illust = json_result.illust
pages = illust["meta_pages"]
print(f"Dowloading image to {dest_folder}")
if len(pages) > 0:
print(f"Dowloading mutiple images to {dest_folder}")
for page in pages:
url = page["image_urls"]["original"]
print(url)
api.download(url=url, path=dest_folder)
print("Dowload finished !")
else:
print(f"Dowloading single image to {dest_folder}")
api.download(
url=illust["meta_single_page"]["original_image_url"], path=dest_folder
)
print("Down4load finished !")
return illust["title"]