Send embedded videos as video messages

This commit is contained in:
TheGeneralist 2026-02-16 15:06:18 +01:00
parent 16e938e756
commit 181c03915b
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -4077,6 +4077,9 @@ async fn send_embedded_media_for_view(
if is_image_path(&path) { if is_image_path(&path) {
let sent = bot.send_photo(chat_id, InputFile::file(path)).await?; let sent = bot.send_photo(chat_id, InputFile::file(path)).await?;
sent_message_ids.push(sent.id); sent_message_ids.push(sent.id);
} else if is_video_path(&path) {
let sent = bot.send_video(chat_id, InputFile::file(path)).await?;
sent_message_ids.push(sent.id);
} else { } else {
let sent = bot.send_document(chat_id, InputFile::file(path)).await?; let sent = bot.send_document(chat_id, InputFile::file(path)).await?;
sent_message_ids.push(sent.id); sent_message_ids.push(sent.id);
@ -4591,6 +4594,8 @@ fn format_embedded_references_for_lines(lines: &[String], config: &Config) -> Ve
}; };
if is_image_path(&path) { if is_image_path(&path) {
formatted.push_str(&format!("image #{}", label)); formatted.push_str(&format!("image #{}", label));
} else if is_video_path(&path) {
formatted.push_str(&format!("video #{}", label));
} else { } else {
formatted.push_str(&format!("file #{}", label)); formatted.push_str(&format!("file #{}", label));
} }
@ -4681,6 +4686,16 @@ fn is_image_path(path: &Path) -> bool {
} }
} }
fn is_video_path(path: &Path) -> bool {
match path.extension().and_then(|ext| ext.to_str()) {
Some(ext) => matches!(
ext.to_ascii_lowercase().as_str(),
"mp4" | "mov" | "mkv" | "webm" | "avi" | "m4v"
),
None => false,
}
}
fn parse_command(text: &str) -> Option<&str> { fn parse_command(text: &str) -> Option<&str> {
let first = text.split_whitespace().next()?; let first = text.split_whitespace().next()?;
if !first.starts_with('/') { if !first.starts_with('/') {
@ -4914,6 +4929,22 @@ mod tests {
assert_eq!(rendered[1], "repeat image #1"); assert_eq!(rendered[1], "repeat image #1");
} }
#[test]
fn format_embedded_references_labels_videos() {
let temp = TempDir::new().unwrap();
let media_dir = temp.path().join("media");
fs::create_dir_all(&media_dir).unwrap();
fs::write(media_dir.join("clip.mp4"), b"x").unwrap();
let mut config = test_config();
config.media_dir = media_dir;
let lines = vec!["Watch ![[clip.mp4]]".to_string()];
let rendered = format_embedded_references_for_lines(&lines, &config);
assert_eq!(rendered[0], "Watch video #1");
}
#[test] #[test]
fn embedded_lines_for_peek_use_preview_only() { fn embedded_lines_for_peek_use_preview_only() {
let entry = EntryBlock::from_text("first line\nsecond line\n![[image-2.jpg]]"); let entry = EntryBlock::from_text("first line\nsecond line\n![[image-2.jpg]]");