Change output folder to media

This commit is contained in:
roaming97 2025-04-16 16:17:17 -06:00
parent 9e619c004a
commit 4b8cccf29f
4 changed files with 11 additions and 13 deletions

8
.gitignore vendored
View File

@ -1,9 +1,7 @@
/target /target
*.db*
.env .env
almond.toml
# almond media folders # almond
*.db*
almond.toml
/media /media
/channels
/videos

View File

@ -44,7 +44,7 @@ impl Channel {
"--skip-download", "--skip-download",
"-v", "-v",
"-o", "-o",
"channels/tmp/tmp.%(ext)s", "media/channels/tmp/tmp.%(ext)s",
url, url,
]) ])
.spawn()?; .spawn()?;
@ -65,10 +65,9 @@ impl Channel {
return Err(ChannelError::InvalidUrl); return Err(ChannelError::InvalidUrl);
} }
// This task is light enough so it can run on its entirety
Self::yt_dlp_task(url.as_str()).await?; Self::yt_dlp_task(url.as_str()).await?;
let info: Value = let info: Value =
serde_json::from_str(&fs::read_to_string("channels/tmp/tmp.info.json").await?)?; serde_json::from_str(&fs::read_to_string("media/channels/tmp/tmp.info.json").await?)?;
let get_info_value = |key: &str| { let get_info_value = |key: &str| {
info.get(key) info.get(key)
@ -77,9 +76,10 @@ impl Channel {
}; };
let youtube_id = get_info_value("channel_id").to_unquoted_string(); let youtube_id = get_info_value("channel_id").to_unquoted_string();
let dir = format!("channels/{youtube_id}"); let dir = format!("media/channels/{youtube_id}");
let file_stem = format!("{dir}/{youtube_id}"); let file_stem = format!("{dir}/{youtube_id}");
// TODO: Detect if ID exists without running yt-dlp task
if Path::new(&dir).exists() { if Path::new(&dir).exists() {
warn!("Channel already exists, skipping"); warn!("Channel already exists, skipping");
return Err(ChannelError::AlreadyExists); return Err(ChannelError::AlreadyExists);
@ -126,7 +126,7 @@ impl Channel {
.unwrap_or_default(); .unwrap_or_default();
fs::rename( fs::rename(
"channels/tmp/tmp.info.json", "media/channels/tmp/tmp.info.json",
format!("{file_stem}.info.json"), format!("{file_stem}.info.json"),
) )
.await?; .await?;

View File

@ -38,7 +38,7 @@ pub struct Comment {
} }
pub async fn get_comments_from_video(id: &str) -> Result<Vec<Comment>, CommentsError> { pub async fn get_comments_from_video(id: &str) -> Result<Vec<Comment>, CommentsError> {
let info_json = format!("videos/{id}/{id}.info.json"); let info_json = format!("media/videos/{id}/{id}.info.json");
let info_json = Path::new(&info_json); let info_json = Path::new(&info_json);
if !info_json.exists() { if !info_json.exists() {

View File

@ -60,7 +60,7 @@ impl Video {
"-v", "-v",
url, url,
"-o", "-o",
"videos/%(id)s/%(id)s.%(ext)s", "media/videos/%(id)s/%(id)s.%(ext)s",
"-f", "-f",
"bestvideo[ext=mkv]+bestaudio[ext=m4a]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo*+bestaudio/best", "bestvideo[ext=mkv]+bestaudio[ext=m4a]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo*+bestaudio/best",
]; ];
@ -82,7 +82,7 @@ impl Video {
let youtube_id = query_v.1.to_string(); let youtube_id = query_v.1.to_string();
info!("URL is valid YouTube video, got ID '{youtube_id}'"); info!("URL is valid YouTube video, got ID '{youtube_id}'");
let dir = format!("videos/{youtube_id}"); let dir = format!("media/videos/{youtube_id}");
let file_stem = format!("{dir}/{youtube_id}"); let file_stem = format!("{dir}/{youtube_id}");
// ? Uploading a video doesn't mean updating it, make a PUT route for that later // ? Uploading a video doesn't mean updating it, make a PUT route for that later