From 5e8b351ee4cf36ef454f3048ad7299f8947b2f3c Mon Sep 17 00:00:00 2001 From: amtoaer Date: Sun, 31 Mar 2024 19:28:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20nfo=20=E7=9A=84=20c?= =?UTF-8?q?data=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/utils.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/core/utils.rs b/src/core/utils.rs index ae029c1..d4a50fb 100644 --- a/src/core/utils.rs +++ b/src/core/utils.rs @@ -2,9 +2,10 @@ use std::collections::HashSet; use std::path::Path; use entity::*; +use filenamify::filenamify; use migration::OnConflict; use once_cell::sync::Lazy; -use quick_xml::events::BytesText; +use quick_xml::events::{BytesCData, BytesText}; use quick_xml::writer::Writer; use quick_xml::Error; use sea_orm::entity::prelude::*; @@ -107,7 +108,7 @@ pub async fn create_videos( bvid: Set(v.bvid.clone()), name: Set(v.title.clone()), path: Set(Path::new(&favorite.path) - .join( + .join(filenamify( TEMPLATE .render( "video", @@ -119,7 +120,7 @@ pub async fn create_videos( }), ) .unwrap_or_else(|_| v.bvid.clone()), - ) + )) .to_str() .unwrap() .to_owned()), @@ -238,7 +239,7 @@ impl<'a> NFOSerializer<'a> { .write_inner_content_async::<_, _, Error>(|writer| async move { writer .create_element("plot") - .write_text_content_async(BytesText::new(&format!(r#"![CDATA[{}]]"#, &v.intro))) + .write_cdata_content_async(BytesCData::new(&v.intro)) .await .unwrap(); writer.create_element("outline").write_empty_async().await.unwrap(); @@ -266,7 +267,7 @@ impl<'a> NFOSerializer<'a> { .unwrap(); writer .create_element("year") - .write_text_content_async(BytesText::new(&v.pubtime.format("%Y").to_string())) + .write_text_content_async(BytesText::new(&v.favtime.format("%Y").to_string())) .await .unwrap(); if let Some(tags) = &v.tags { @@ -287,7 +288,7 @@ impl<'a> NFOSerializer<'a> { .unwrap(); writer .create_element("aired") - .write_text_content_async(BytesText::new(&v.pubtime.format("%Y-%m-%d").to_string())) + .write_text_content_async(BytesText::new(&v.favtime.format("%Y-%m-%d").to_string())) .await .unwrap(); Ok(writer) @@ -301,7 +302,7 @@ impl<'a> NFOSerializer<'a> { .write_inner_content_async::<_, _, Error>(|writer| async move { writer .create_element("plot") - .write_text_content_async(BytesText::new(&format!(r#"![CDATA[{}]]"#, &v.intro))) + .write_cdata_content_async(BytesCData::new(&v.intro)) .await .unwrap(); writer.create_element("outline").write_empty_async().await.unwrap(); @@ -329,7 +330,7 @@ impl<'a> NFOSerializer<'a> { .unwrap(); writer .create_element("year") - .write_text_content_async(BytesText::new(&v.pubtime.format("%Y").to_string())) + .write_text_content_async(BytesText::new(&v.favtime.format("%Y").to_string())) .await .unwrap(); if let Some(tags) = &v.tags { @@ -350,7 +351,7 @@ impl<'a> NFOSerializer<'a> { .unwrap(); writer .create_element("aired") - .write_text_content_async(BytesText::new(&v.pubtime.format("%Y-%m-%d").to_string())) + .write_text_content_async(BytesText::new(&v.favtime.format("%Y-%m-%d").to_string())) .await .unwrap(); Ok(writer) @@ -371,7 +372,9 @@ impl<'a> NFOSerializer<'a> { .unwrap(); writer .create_element("dateadded") - .write_text_content_async(BytesText::new(&v.pubtime.format("%Y-%m-%d").to_string())) + .write_text_content_async(BytesText::new( + &v.pubtime.format("%Y-%m-%d %H:%M:%S").to_string(), + )) .await .unwrap(); writer @@ -447,7 +450,7 @@ mod tests { .unwrap(), r#" - ![CDATA[intro]] + name @@ -468,7 +471,7 @@ mod tests { .unwrap(), r#" - ![CDATA[intro]] + name