parent
780669b958
commit
c551adebae
|
|
@ -41,7 +41,7 @@ if not YOUTUBE_TRANSCRIPT_API_TOKEN:
|
|||
TRANSCRIPT_LANGUAGES = ['pl', 'en'] # Priorytet języków transkrypcji
|
||||
SUMMARY_PROMPT = """Streść poniższy transkrypt filmu z YouTube w zwięzły sposób w języku polskim.
|
||||
Skup się na głównych tematach i wnioskach.
|
||||
prosiłbym o dokonanie tego streszczenia w formacie markdown.
|
||||
prosiłbym o dokonanie tego streszczenia w formacie Markdown.
|
||||
|
||||
Transkrypt:
|
||||
{transcript}"""
|
||||
|
|
@ -77,8 +77,8 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
await safe_send_message(
|
||||
context.bot,
|
||||
chat_id=chat_id,
|
||||
text=f"*Rozpoczynam przetwarzanie filmu:*\n{escape_markdown_v2(title)}\n\n*Link:* {escape_markdown_v2(url)}",
|
||||
parse_mode=ParseMode.MARKDOWN_V2,
|
||||
text=f"*Rozpoczynam przetwarzanie filmu:*\n{title}\n\n*Link:* {url}",
|
||||
parse_mode="Markdown",
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
|
||||
|
|
@ -115,13 +115,13 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
# Jeśli mamy więcej niż jeden fragment, wysyłaj postęp na bieżąco
|
||||
if len(chunks) > 1:
|
||||
part_header = f"*Streszczenie - część {i+1}/{len(chunks)}:*\n\n"
|
||||
response_text = f"{part_header}{escape_markdown_v2(partial_summary)}"
|
||||
response_text = f"{part_header}{partial_summary}"
|
||||
|
||||
await send_long_message(
|
||||
context.bot,
|
||||
chat_id=chat_id,
|
||||
text=response_text,
|
||||
parse_mode=ParseMode.MARKDOWN_V2,
|
||||
parse_mode="Markdown",
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
@ -169,12 +169,12 @@ async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||
|
||||
# Wyślij końcowe streszczenie, jeśli były więcej niż 3 fragmenty
|
||||
if len(chunks) > 3:
|
||||
final_text = f"*Ostateczne streszczenie filmu:*\n*{escape_markdown_v2(title)}*\n\n{escape_markdown_v2(combined_summary)}"
|
||||
final_text = f"*Ostateczne streszczenie filmu:*\n*{title}*\n\n{combined_summary}"
|
||||
await send_long_message(
|
||||
context.bot,
|
||||
chat_id=chat_id,
|
||||
text=final_text,
|
||||
parse_mode=ParseMode.MARKDOWN_V2,
|
||||
parse_mode="Markdown",
|
||||
disable_web_page_preview=True
|
||||
)
|
||||
|
||||
|
|
@ -206,10 +206,10 @@ def escape_markdown_v2(text: str) -> str:
|
|||
return ""
|
||||
|
||||
# Pełna lista znaków specjalnych w Telegram MarkdownV2
|
||||
escape_chars = r'-'
|
||||
escape_chars = r'_*[]()~`>#+-=|{}.!'
|
||||
|
||||
# Zamieniamy każdy znak specjalny na jego wersję z dwoma backslashami przed nim
|
||||
return re.sub(f'([{re.escape(escape_chars)}])', r'\1', text)
|
||||
return re.sub(f'([{re.escape(escape_chars)}])', r'\\\1', text)
|
||||
|
||||
# Ulepszona funkcja do bezpiecznego wysyłania wiadomości
|
||||
async def safe_send_message(bot, chat_id, text, parse_mode=None, disable_web_page_preview=False, max_retries=3):
|
||||
|
|
@ -290,7 +290,12 @@ async def send_long_message(bot, chat_id, text, parse_mode=None, disable_web_pag
|
|||
|
||||
# Wyślij części wiadomości
|
||||
for i, part in enumerate(parts):
|
||||
part_header = f"*Część {i+1}/{len(parts)}*\n\n" if parse_mode == ParseMode.MARKDOWN_V2 else f"Część {i+1}/{len(parts)}\n\n"
|
||||
# Użyj odpowiedniego formatu nagłówka w zależności od parse_mode
|
||||
if parse_mode == ParseMode.MARKDOWN_V2 or parse_mode == "Markdown":
|
||||
part_header = f"*Część {i+1}/{len(parts)}*\n\n"
|
||||
else:
|
||||
part_header = f"Część {i+1}/{len(parts)}\n\n"
|
||||
|
||||
await safe_send_message(
|
||||
bot,
|
||||
chat_id=chat_id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue