From 1fd60f9207f6d7c6e8c61508bebfa991a102a423 Mon Sep 17 00:00:00 2001 From: SebClem Date: Thu, 2 Nov 2023 16:29:28 +0100 Subject: [PATCH] Add artist name --- src/discord_tools/message.py | 3 ++- src/main.py | 17 ++++++++++------- src/pixiv/pixiv_api.py | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/discord_tools/message.py b/src/discord_tools/message.py index 92f0088..a5ebe61 100644 --- a/src/discord_tools/message.py +++ b/src/discord_tools/message.py @@ -48,6 +48,7 @@ async def send_command_reply( tmp_dir: str, muted: bool, title: str, + art_author: str, url: str, author: discord.User | discord.Member, ): @@ -77,7 +78,7 @@ async def send_command_reply( elif first: await interaction.followup.send( files=splited_file, - content=f"{title} - Submited by {author.mention} - <{url}> {chr(10) + TIPS_MESSAGE if not muted else ''}", + content=f"{title} by {art_author} - <{url}> - Submited by {author.mention} {chr(10) + TIPS_MESSAGE if not muted else ''}", ) first = False else: diff --git a/src/main.py b/src/main.py index 07d11f4..2e5b090 100644 --- a/src/main.py +++ b/src/main.py @@ -55,15 +55,15 @@ async def pixivprev(interaction: discord.Interaction, url: str): if result and match is not None: await interaction.response.defer() with TemporaryDirectory() as tmp_dir: - title = pixiv_api.dowload_pixiv_images( + data = pixiv_api.dowload_pixiv_images( int(match.group("id")), tmp_dir, REFRESH_TOKEN ) - if title is None: + if data is None: await interaction.response.send_message( "Fail to extract pixiv image", ephemeral=True ) return - + (title, author) = data files = os.listdir(tmp_dir) files.sort() await discord_tools.message.send_command_reply( @@ -72,6 +72,7 @@ async def pixivprev(interaction: discord.Interaction, url: str): tmp_dir, True, title=title, + art_author=author, url=url, author=interaction.user, ) @@ -85,22 +86,24 @@ async def pixiv_preview(interaction: discord.Interaction, message: discord.Messa if result and match is not None: await interaction.response.defer() with TemporaryDirectory() as tmp_dir: - title = pixiv_api.dowload_pixiv_images( + data = pixiv_api.dowload_pixiv_images( int(match.group("id")), tmp_dir, REFRESH_TOKEN ) - if title is None: + if data is None: await interaction.response.send_message( "Fail to extract pixiv image", ephemeral=True ) return files = os.listdir(tmp_dir) files.sort() + (title, author) = data await discord_tools.message.send_command_reply( interaction=interaction, files=files, tmp_dir=tmp_dir, muted=muted, title=title, + art_author=author, url=match.group("url"), author=interaction.user, ) @@ -123,10 +126,10 @@ async def on_message(message: discord.Message): if result and match is not None: with TemporaryDirectory() as tmp_dir: async with message.channel.typing(): - title = pixiv_api.dowload_pixiv_images( + data = pixiv_api.dowload_pixiv_images( int(match.group("id")), tmp_dir, REFRESH_TOKEN ) - if title is None: + if data is None: return files = os.listdir(tmp_dir) files.sort() diff --git a/src/pixiv/pixiv_api.py b/src/pixiv/pixiv_api.py index 0a507e7..84dc6d2 100644 --- a/src/pixiv/pixiv_api.py +++ b/src/pixiv/pixiv_api.py @@ -59,7 +59,7 @@ def dowload_pixiv_images( url=illust["meta_single_page"]["original_image_url"], path=dest_folder ) logging.info("Download finished !") - return illust["title"] + return (illust["title"], f"{illust['user']['name']}({illust['user']['account']})") def download_thread(q: Queue[Union[Tuple[str, str, pixivpy3.AppPixivAPI], None]]):