Compare commits

..

2 Commits

Author SHA1 Message Date
25f9159155 sd update 2024-03-01 09:21:29 -07:00
803acf514b switched to using pytubefix 2024-03-01 09:20:44 -07:00
3 changed files with 34 additions and 26 deletions

View File

@ -24,7 +24,7 @@ async def handle_command(room, message, bot, prefix, config):
prompt = message.body[len(prefix) + len("sd"):].strip() # Extract prompt from message body prompt = message.body[len(prefix) + len("sd"):].strip() # Extract prompt from message body
payload = { payload = {
"prompt": prompt, "prompt": prompt,
"steps": 32 "steps": 16
} }
url = "http://127.0.0.1:7860/sdapi/v1/txt2img" url = "http://127.0.0.1:7860/sdapi/v1/txt2img"
try: try:

View File

@ -6,25 +6,31 @@ This plugin provides a command to fetch YouTube video information from links.
import re import re
import logging import logging
from pytube import YouTube from pytubefix import YouTube
import simplematrixbotlib as botlib import simplematrixbotlib as botlib
import asyncio
def seconds_to_minutes_seconds(seconds): def seconds_to_minutes_seconds(seconds):
minutes = seconds // 60 minutes = seconds // 60
seconds %= 60 seconds %= 60
return f"{minutes:02d}:{seconds:02d}" return f"{minutes:02d}:{seconds:02d}"
async def fetch_youtube_info(youtube_url):
try:
video = YouTube(youtube_url)
title = video.title
description = video.description
length = seconds_to_minutes_seconds(video.length)
views = video.views
author = video.author
description_with_breaks = description.replace('\n', '<br>')
info_message = f"""<strong>🎬🎝 Title:</strong> {title} | <strong>Length</strong>: {length} minutes | <strong>Views</strong>: {views}\n<details><summary><strong>⤵Click Here For Description⤵</strong></summary>{description_with_breaks}</details>"""
return info_message
except Exception as e:
logging.error(f"Error fetching YouTube video information: {str(e)}")
return None
async def handle_command(room, message, bot, prefix, config): async def handle_command(room, message, bot, prefix, config):
"""
Function to handle YouTube video information from links.
Args:
room (Room): The Matrix room where the command was invoked.
message (RoomMessage): The message object containing the command.
Returns:
None
"""
match = botlib.MessageMatch(room, message, bot, prefix) match = botlib.MessageMatch(room, message, bot, prefix)
if match.is_not_from_this_bot() and re.search(r'youtube\.com/watch\?v=', message.body): if match.is_not_from_this_bot() and re.search(r'youtube\.com/watch\?v=', message.body):
logging.info("YouTube link detected") logging.info("YouTube link detected")
@ -33,16 +39,18 @@ async def handle_command(room, message, bot, prefix, config):
video_id = video_id_match.group(1) video_id = video_id_match.group(1)
youtube_url = f"https://www.youtube.com/watch?v={video_id}" youtube_url = f"https://www.youtube.com/watch?v={video_id}"
logging.info(f"Fetching information for YouTube video: {youtube_url}") logging.info(f"Fetching information for YouTube video: {youtube_url}")
try: retry_count = 3
video = YouTube(youtube_url) while retry_count > 0:
title = video.title info_message = await fetch_youtube_info(youtube_url)
description = video.description if info_message:
length = seconds_to_minutes_seconds(video.length) await bot.api.send_markdown_message(room.room_id, info_message)
views = video.views logging.info("Sent YouTube video information to the room")
author = video.author break
info_message = f"""**🎬🎝 Title:** {title} | **Length**: {length} minutes| **Views:** {views} | **Description:** {description}""" else:
await bot.api.send_markdown_message(room.room_id, info_message) logging.info("Retrying...")
logging.info("Sent YouTube video information to the room") retry_count -= 1
except Exception as e: await asyncio.sleep(1) # wait for 1 second before retrying
logging.error(f"Error fetching YouTube video information: {str(e)}") else:
# await bot.api.send__message(room.room_id, "Error fetching YouTube video information.") logging.error("Failed to fetch YouTube video information after retries")

View File

@ -1,6 +1,6 @@
python-dotenv python-dotenv
requests requests
pytube pytubefix
duckduckgo_search duckduckgo_search
nio nio
markdown2 markdown2