Compare commits
No commits in common. "703feb8ca3ba59bfc3ef1e0c5b7ded5b6aaa3599" and "f4e4c5dda47c537df85a12750b6e5970c521e5ba" have entirely different histories.
703feb8ca3
...
f4e4c5dda4
28
src/main.py
28
src/main.py
@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from shlex import join
|
from shlex import join
|
||||||
@ -56,13 +55,8 @@ async def pixivprev(interaction: discord.Interaction, url: str):
|
|||||||
if result and match is not None:
|
if result and match is not None:
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
with TemporaryDirectory() as tmp_dir:
|
with TemporaryDirectory() as tmp_dir:
|
||||||
loop = asyncio.get_running_loop()
|
data = pixiv_api.dowload_pixiv_images(
|
||||||
data = await loop.run_in_executor(
|
int(match.group("id")), tmp_dir, REFRESH_TOKEN
|
||||||
None,
|
|
||||||
pixiv_api.dowload_pixiv_images,
|
|
||||||
int(match.group("id")),
|
|
||||||
tmp_dir,
|
|
||||||
REFRESH_TOKEN,
|
|
||||||
)
|
)
|
||||||
if data is None:
|
if data is None:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@ -92,13 +86,8 @@ async def pixiv_preview(interaction: discord.Interaction, message: discord.Messa
|
|||||||
if result and match is not None:
|
if result and match is not None:
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
with TemporaryDirectory() as tmp_dir:
|
with TemporaryDirectory() as tmp_dir:
|
||||||
loop = asyncio.get_running_loop()
|
data = pixiv_api.dowload_pixiv_images(
|
||||||
data = await loop.run_in_executor(
|
int(match.group("id")), tmp_dir, REFRESH_TOKEN
|
||||||
None,
|
|
||||||
pixiv_api.dowload_pixiv_images,
|
|
||||||
int(match.group("id")),
|
|
||||||
tmp_dir,
|
|
||||||
REFRESH_TOKEN,
|
|
||||||
)
|
)
|
||||||
if data is None:
|
if data is None:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@ -137,13 +126,8 @@ async def on_message(message: discord.Message):
|
|||||||
if result and match is not None:
|
if result and match is not None:
|
||||||
with TemporaryDirectory() as tmp_dir:
|
with TemporaryDirectory() as tmp_dir:
|
||||||
async with message.channel.typing():
|
async with message.channel.typing():
|
||||||
loop = asyncio.get_running_loop()
|
data = pixiv_api.dowload_pixiv_images(
|
||||||
data = await loop.run_in_executor(
|
int(match.group("id")), tmp_dir, REFRESH_TOKEN
|
||||||
None,
|
|
||||||
pixiv_api.dowload_pixiv_images,
|
|
||||||
int(match.group("id")),
|
|
||||||
tmp_dir,
|
|
||||||
REFRESH_TOKEN,
|
|
||||||
)
|
)
|
||||||
if data is None:
|
if data is None:
|
||||||
return
|
return
|
||||||
|
@ -9,8 +9,6 @@ import pixivpy3
|
|||||||
|
|
||||||
cpu_count = os.cpu_count()
|
cpu_count = os.cpu_count()
|
||||||
max_thread_num = cpu_count * 2 if cpu_count is not None else 4
|
max_thread_num = cpu_count * 2 if cpu_count is not None else 4
|
||||||
if max_thread_num > 10:
|
|
||||||
max_thread_num = 10
|
|
||||||
|
|
||||||
|
|
||||||
def dowload_pixiv_images(
|
def dowload_pixiv_images(
|
||||||
@ -24,7 +22,6 @@ def dowload_pixiv_images(
|
|||||||
json_result = api.illust_detail(illust_id)
|
json_result = api.illust_detail(illust_id)
|
||||||
illust = json_result.illust
|
illust = json_result.illust
|
||||||
if not illust["visible"]:
|
if not illust["visible"]:
|
||||||
logging.info("Can't be viewed, return None")
|
|
||||||
return None
|
return None
|
||||||
pages = illust["meta_pages"]
|
pages = illust["meta_pages"]
|
||||||
if len(pages) > 0:
|
if len(pages) > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user