Commit 4063ab2
Changed files (6)
src
others
preview
subtitles
ytdlp
src/asr/voice_recognition.py
@@ -168,7 +168,7 @@ async def voice_to_text(
caption = asr_msg_info["html"]
if to_telegraph:
html = "\n".join([f"<p>{s}</p>" for s in texts.split("\n")])
- if telegraph_url := await publish_telegraph(title=asr_msg_info["text"] or "语音识别结果", html=html, author=asr_msg_info["full_name"], url=asr_msg_info["message_url"]):
+ if telegraph_url := await publish_telegraph(title=asr_msg_info["text"] or "语音识别结果", html=html, author=asr_msg_info["full_name"], url=asr_msg_info["message_url"], **kwargs):
caption += f"\n<a href={telegraph_url}>⚡️即时预览</a>"
with io.BytesIO(texts.encode("utf-8")) as f:
await client.send_document(
src/others/download_external.py
@@ -83,7 +83,7 @@ async def download_url_in_message(client: Client, message: Message, extra_prefix
markdown = convert_md(path)
markdown_path = path.with_suffix(".md")
markdown_path.write_text(markdown)
- if telegraph_url := await publish_telegraph(title="全文内容", texts=markdown, author=info["full_name"], url=url):
+ if telegraph_url := await publish_telegraph(title="全文内容", texts=markdown, author=info["full_name"], url=url, **kwargs):
caption += f"\n⚡️[即时预览]({telegraph_url})"
success = await client.send_document(target_chat, path.as_posix(), caption=caption, reply_parameters=reply_parameters)
else:
src/preview/wechat.py
@@ -50,7 +50,7 @@ async def preview_wechat(client: Client, message: Message, url: str = "", db_key
sent_messages.extend(await send2tg(client, message, texts=texts, **kwargs))
else: # 无图片长文
texts = f"{post_info['header']}"
- telegraph_url = await publish_telegraph(title=post_info["title"], html=post_info["html"], author=post_info["author"], url=url)
+ telegraph_url = await publish_telegraph(title=post_info["title"], html=post_info["html"], author=post_info["author"], url=url, **kwargs)
if telegraph_url:
texts += f"\n⚡️[即时预览]({telegraph_url})"
sent_messages.extend(await send2tg(client, message, texts=texts, media=[{"document": post_info["html_path"]}], **kwargs))
@@ -59,7 +59,7 @@ async def preview_wechat(client: Client, message: Message, url: str = "", db_key
sent_messages.extend(await send2tg(client, message, texts=texts, media=post_info["media"], **kwargs))
else: # 有图片长文
texts = f"{post_info['header']}"
- telegraph_url = await publish_telegraph(title=post_info["title"], html=post_info["html"], author=post_info["author"], url=url)
+ telegraph_url = await publish_telegraph(title=post_info["title"], html=post_info["html"], author=post_info["author"], url=url, **kwargs)
if telegraph_url:
texts += f"\n⚡️[即时预览]({telegraph_url})"
sent_messages.extend(await send2tg(client, message, texts=texts, media=[{"document": post_info["path"]}], **kwargs))
src/subtitles/subtitle.py
@@ -125,7 +125,7 @@ async def get_subtitle(
if send_subtitle_as == "file":
if to_telegraph:
html = "\n".join([f"<p>{s}</p>" for s in subtitles.split("\n")])
- if telegraph_url := await publish_telegraph(title=vinfo["title"], html=html, author=vinfo["author"], url=url):
+ if telegraph_url := await publish_telegraph(title=vinfo["title"], html=html, author=vinfo["author"], url=url, **kwargs):
caption += f"\n⚡️[即时预览]({telegraph_url})"
with BytesIO(subtitles.encode("utf-8")) as f:
subtitle_msg = await client.send_document(to_int(target_chat), f, file_name=f"{vinfo['title']}.txt", caption=caption)
src/ytdlp/main.py
@@ -157,7 +157,7 @@ async def preview_ytdlp(
caption += f"#️⃣字符数: {count_subtitles(summary_with_subtitle)}\n"
caption += f"⏳阅读时长: {readable_time(60 * count_subtitles(summary_with_subtitle) / READING_SPEED)}"
html = "\n".join([f"<p>{s}</p>" for s in summary_with_subtitle.split("\n")]).replace("<p></p>", "")
- if true(to_telegraph) and (telegraph_url := await publish_telegraph(title=info["title"], html=html, author=info["author"], url=url)):
+ if true(to_telegraph) and (telegraph_url := await publish_telegraph(title=info["title"], html=html, author=info["author"], url=url, **kwargs)):
caption += f"\n⚡️[即时预览]({telegraph_url})"
sent_messages = await append_subtitle(f'<a href="{telegraph_url}">{telegraph_name}</a>', sent_messages)
else:
src/publish.py
@@ -25,6 +25,7 @@ async def publish_telegraph(
author: str | None = None,
url: str | None = None,
ttl: str = "forever", # 12h, 7d, 1M, ...
+ **kwargs, # noqa: ARG001
) -> str:
"""Publish to Telegraph."""
@@ -40,7 +41,6 @@ async def publish_telegraph(
if texts and not html:
html = markdown.markdown(texts)
telegraph = Telegraph(access_token=TOKEN.TELEGRAPH)
- account_info = {}
if not (author and url):
with contextlib.suppress(Exception):
account_info = await telegraph.get_account_info()