Add picture of grzeg

This commit is contained in:
Oystein Kristoffer Tveit 2024-10-20 00:05:30 +02:00
parent 5e3df86a2a
commit 6bb8d28eff
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 22 additions and 2 deletions

BIN
assets/the_man.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

View File

@ -1,7 +1,7 @@
use anyhow::Context;
use axum::{Router, Server};
use clap::Parser;
use mpv_setup::{connect_to_mpv, create_mpv_config_file};
use mpv_setup::{connect_to_mpv, create_mpv_config_file, show_grzegorz_image};
use std::net::{IpAddr, SocketAddr};
use tempfile::NamedTempFile;
@ -66,6 +66,8 @@ async fn main() -> anyhow::Result<()> {
})
.await?;
show_grzegorz_image(mpv.clone()).await?;
let addr = SocketAddr::new(resolve(&args.host).await?, args.port);
log::info!("Starting API on {}", addr);

View File

@ -1,7 +1,7 @@
use std::{fs::create_dir_all, io::Write, path::Path};
use anyhow::Context;
use mpvipc_async::Mpv;
use mpvipc_async::{Mpv, MpvExt};
use tempfile::NamedTempFile;
use tokio::process::{Child, Command};
@ -9,6 +9,8 @@ use crate::MpvConnectionArgs;
const DEFAULT_MPV_CONFIG_CONTENT: &str = include_str!("../assets/default-mpv.conf");
const THE_MAN_PNG: &[u8] = include_bytes!("../assets/the_man.png");
pub fn create_mpv_config_file(args_config_file: Option<String>) -> anyhow::Result<NamedTempFile> {
let file_content = if let Some(path) = args_config_file {
if !Path::new(&path).exists() {
@ -115,3 +117,19 @@ pub async fn connect_to_mpv<'a>(
))
}
pub async fn show_grzegorz_image(mpv: Mpv) -> anyhow::Result<()> {
let path = std::env::temp_dir().join("the_man.png");
std::fs::write(path.as_path(), THE_MAN_PNG)?;
mpv.playlist_clear().await?;
mpv.playlist_add(
path.to_string_lossy().as_ref(),
mpvipc_async::PlaylistAddTypeOptions::File,
mpvipc_async::PlaylistAddOptions::Append,
)
.await?;
mpv.next().await?;
Ok(())
}