aboutsummaryrefslogtreecommitdiff
path: root/tool/src/import/tmdb.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-16 12:52:33 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-16 12:52:33 +0100
commit2ff80433ee16f6e3088af09cac07cd6484b25b50 (patch)
tree5f54ffa2383c650396ec1cd594f456df8ad0e35d /tool/src/import/tmdb.rs
parent0a3abebd73e7e7d879ad94fc1d2ec26f9221edc2 (diff)
downloadjellything-2ff80433ee16f6e3088af09cac07cd6484b25b50.tar
jellything-2ff80433ee16f6e3088af09cac07cd6484b25b50.tar.bz2
jellything-2ff80433ee16f6e3088af09cac07cd6484b25b50.tar.zst
release dates from tmdb
Diffstat (limited to 'tool/src/import/tmdb.rs')
-rw-r--r--tool/src/import/tmdb.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tool/src/import/tmdb.rs b/tool/src/import/tmdb.rs
index 5f21afd..38d6534 100644
--- a/tool/src/import/tmdb.rs
+++ b/tool/src/import/tmdb.rs
@@ -1,3 +1,5 @@
+use anyhow::Context;
+use jellycommon::chrono::{format::Parsed, DateTime, Utc};
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
@@ -93,3 +95,22 @@ pub fn tmdb_image(path: &str, out: &mut impl Write) -> anyhow::Result<()> {
res.copy_to(out)?;
Ok(())
}
+
+pub fn parse_release_date(d: &str) -> anyhow::Result<DateTime<Utc>> {
+ let (year, month, day) = (&d[0..4], &d[5..7], &d[8..10]);
+ 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)?)
+}