Skip to content

Commit

Permalink
feat: /holodex clip_and_upload現在在上傳完成後,可以繼續製作縮圖並上傳
Browse files Browse the repository at this point in the history
Signed-off-by: Allen95Wei <[email protected]>
  • Loading branch information
Alllen95Wei committed Nov 18, 2024
1 parent 9007bcd commit 40d3d33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions cogs/holodex.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,14 @@ def thumbnail_selection(
menu.options = choices

async def callback(interaction: Interaction):
await interaction.response.defer()
if interaction.user.id == author.id:
selected_file = menu.values[0]
try:
result = await Basics.run_blocking(
self.bot, uploader_obj.upload_thumbnail, selected_file
)
hq_thumbnail = result["items"]["maxres"]["url"]
hq_thumbnail = result["items"][0]["maxres"]["url"]
embed = Embed(
title="縮圖已上傳", description="已更新影片的縮圖。", color=default_color
)
Expand All @@ -365,7 +366,7 @@ async def callback(interaction: Interaction):
value="https://youtu.be/" + uploader_obj.video_id,
inline=False,
)
embed.set_thumbnail(url=hq_thumbnail)
embed.set_image(url=hq_thumbnail)
except Exception as e:
if "Refresh token has expired or invalid." in str(e):
embed = Embed(
Expand All @@ -384,6 +385,9 @@ async def callback(interaction: Interaction):
value="```" + selected_file + "```",
inline=False,
)
finally:
for f in files:
os.remove(f)
await interaction.edit_original_response(embed=embed, view=None)
else:
embed = Embed(
Expand Down Expand Up @@ -449,6 +453,8 @@ async def callback(self, interaction: discord.Interaction):
thumb_gen.write_title(title, color)
thumb_gen.write_subtitle(subtitle, color)
output_images = thumb_gen.save_canvases()
# 移除影片
os.remove(self.video_path)
embed = Embed(
title="選擇縮圖", description="請透過下拉式選單選擇縮圖。", color=default_color
)
Expand Down
2 changes: 1 addition & 1 deletion thumbnail_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def extract_random_frames(self, count: int) -> list[str]:
video.set(cv2.CAP_PROP_POS_FRAMES, frame_no)
success, image = video.read()
if success:
file_path = os.path.join(base_dir, f"{self.uuid.split('-')[-1]}_{frame_no}.jpg")
file_path = os.path.join(base_dir, "thumbnails", f"{self.uuid.split('-')[-1]}_{frame_no}.jpg")
cv2.imwrite(file_path, image)
generated_frames.append(file_path)
self.image_sources += generated_frames
Expand Down

0 comments on commit 40d3d33

Please sign in to comment.