feat: include duration in YouTube entry metadata
This commit is contained in:
+19
@@ -3019,6 +3019,25 @@ impl App {
|
||||
.as_deref()
|
||||
.unwrap_or("Unknown")
|
||||
.into(),
|
||||
" · ".into(),
|
||||
video
|
||||
.duration
|
||||
.filter(|seconds| seconds.is_finite() && *seconds >= 0.0)
|
||||
.map(|seconds| {
|
||||
let seconds = seconds as u64;
|
||||
if seconds >= 3600 {
|
||||
format!(
|
||||
"{}:{:02}:{:02}",
|
||||
seconds / 3600,
|
||||
seconds / 60 % 60,
|
||||
seconds % 60
|
||||
)
|
||||
} else {
|
||||
format!("{}:{:02}", seconds / 60, seconds % 60)
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| "Unknown duration".into())
|
||||
.into(),
|
||||
])
|
||||
.dim(),
|
||||
])),
|
||||
|
||||
@@ -199,6 +199,7 @@ fn video(id: String, title: String, date: Option<String>) -> Video {
|
||||
channel_id: None,
|
||||
uploader_id: None,
|
||||
timestamp: None,
|
||||
duration: None,
|
||||
publication_date: date,
|
||||
availability: None,
|
||||
}
|
||||
|
||||
@@ -716,6 +716,12 @@ fn load_videos(
|
||||
item.as_integer()
|
||||
.ok_or_else(|| invalid("Video timestamp must be an integer"))?,
|
||||
),
|
||||
"duration" => serde_json::Value::from(
|
||||
item.as_float()
|
||||
.or_else(|| item.as_integer().map(|n| n as f64))
|
||||
.filter(|n| n.is_finite() && *n >= 0.0)
|
||||
.ok_or_else(|| invalid("Video duration must be a nonnegative number"))?,
|
||||
),
|
||||
_ => return Err(invalid(format!("Unknown saved video field {key:?}"))),
|
||||
};
|
||||
fields.insert(key.into(), field);
|
||||
@@ -774,6 +780,9 @@ fn video_document<'a>(videos: impl Iterator<Item = &'a Video>) -> DocumentMut {
|
||||
if let Some(timestamp) = video.timestamp {
|
||||
table["timestamp"] = value(timestamp);
|
||||
}
|
||||
if let Some(duration) = video.duration {
|
||||
table["duration"] = value(duration);
|
||||
}
|
||||
tables.push(table);
|
||||
}
|
||||
document["videos"] = if tables.is_empty() {
|
||||
|
||||
@@ -137,6 +137,7 @@ pub struct Video {
|
||||
pub channel_id: Option<String>,
|
||||
pub uploader_id: Option<String>,
|
||||
pub timestamp: Option<i64>,
|
||||
pub duration: Option<f64>,
|
||||
/// Cached YYYY-MM-DD label; a leading ~ marks an estimated UTC date.
|
||||
#[serde(default, rename = "upload_date")]
|
||||
pub publication_date: Option<String>,
|
||||
|
||||
Reference in New Issue
Block a user