aboutsummaryrefslogtreecommitdiff
path: root/import/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-10-24 07:40:51 +0200
committermetamuffin <metamuffin@disroot.org>2023-10-24 07:40:51 +0200
commitb462195f2dcfe457eae7791c14e4b834b2d5ab29 (patch)
tree492ba43952fa6798320f2b2bb4d4bd5484e2e4f2 /import/src
parent6e9ccad881a7f887599bc8f3f6b9ca2424a2cc5e (diff)
parent55f7f06cecd5b6f5661f6f22e8bb3e0448b9713a (diff)
downloadjellything-b462195f2dcfe457eae7791c14e4b834b2d5ab29.tar
jellything-b462195f2dcfe457eae7791c14e4b834b2d5ab29.tar.bz2
jellything-b462195f2dcfe457eae7791c14e4b834b2d5ab29.tar.zst
Merge branch 'master' of codeberg.org:metamuffin/jellything
Diffstat (limited to 'import/src')
-rw-r--r--import/src/infojson.rs21
-rw-r--r--import/src/main.rs16
2 files changed, 36 insertions, 1 deletions
diff --git a/import/src/infojson.rs b/import/src/infojson.rs
index ca02551..dd2151b 100644
--- a/import/src/infojson.rs
+++ b/import/src/infojson.rs
@@ -4,6 +4,8 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
+use anyhow::Context;
+use jellycommon::chrono::{format::Parsed, DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
@@ -120,3 +122,22 @@ pub struct YHeatmapSample {
pub end_time: f64,
pub value: f64,
}
+
+pub fn parse_upload_date(d: &str) -> anyhow::Result<DateTime<Utc>> {
+ let (year, month, day) = (&d[0..4], &d[4..6], &d[6..8]);
+ let (year, month, day) = (
+ year.parse().context("parsing year")?,
+ month.parse().context("parsing month")?,
+ day.parse().context("parsing day")?,
+ );
+
+ let mut p = Parsed::new();
+ p.year = Some(year);
+ p.month = Some(month);
+ p.day = Some(day);
+ p.hour_div_12 = Some(0);
+ p.hour_mod_12 = Some(0);
+ p.minute = Some(0);
+ p.second = Some(0);
+ Ok(p.to_datetime_with_timezone(&Utc)?)
+}
diff --git a/import/src/main.rs b/import/src/main.rs
index 57e6b99..c274e54 100644
--- a/import/src/main.rs
+++ b/import/src/main.rs
@@ -11,7 +11,7 @@ pub mod tmdb;
use anyhow::Context;
use base64::Engine;
use clap::{Parser, Subcommand};
-use infojson::YVideo;
+use infojson::{parse_upload_date, YVideo};
use jellycommon::{
config::GlobalConfig, AssetLocation, LocalTrack, MediaInfo, MediaSource, Node, NodeKind,
NodePrivate, NodePublic, Rating,
@@ -22,6 +22,7 @@ use log::{info, warn};
use rand::random;
use std::{
collections::BTreeMap,
+ fmt::Debug,
fs::{remove_file, File},
io::{stdin, BufReader, Write},
path::PathBuf,
@@ -354,6 +355,9 @@ fn main() -> anyhow::Result<()> {
duration: m.duration,
tracks: m.tracks.clone(),
}),
+ release_date: infojson
+ .as_ref()
+ .and_then(|j| ok_or_warn(parse_upload_date(&j.upload_date))),
..Default::default()
},
};
@@ -399,3 +403,13 @@ fn make_ident(s: &str) -> String {
}
out
}
+
+fn ok_or_warn<T, E: Debug>(r: Result<T, E>) -> Option<T> {
+ match r {
+ Ok(t) => Some(t),
+ Err(e) => {
+ warn!("{e:?}");
+ None
+ }
+ }
+}