From 2ff80433ee16f6e3088af09cac07cd6484b25b50 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 16 Dec 2023 12:52:33 +0100 Subject: release dates from tmdb --- tool/src/import/mod.rs | 15 ++++++++++++--- tool/src/import/tmdb.rs | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'tool') diff --git a/tool/src/import/mod.rs b/tool/src/import/mod.rs index 250643e..fb42c4d 100644 --- a/tool/src/import/mod.rs +++ b/tool/src/import/mod.rs @@ -8,7 +8,7 @@ pub mod tmdb; use crate::{make_ident, ok_or_warn, Action}; use anyhow::Context; -use infojson::{parse_upload_date, YVideo}; +use infojson::YVideo; use jellycommon::{ AssetLocation, LocalTrack, MediaInfo, MediaSource, Node, NodeKind, NodePrivate, NodePublic, Rating, @@ -216,6 +216,11 @@ pub(crate) fn import(action: Action, dry: bool) -> anyhow::Result<()> { .map(|i| i.like_count.map(|l| (Rating::YoutubeLikes, l as f64))) .flatten(), ); + ratings.extend( + tmdb_details + .as_ref() + .map(|d| (Rating::Tmdb, d.vote_average)), + ); let node = Node { private: NodePrivate { @@ -257,9 +262,13 @@ pub(crate) fn import(action: Action, dry: bool) -> anyhow::Result<()> { duration: m.duration, tracks: m.tracks.clone(), }), - release_date: infojson + release_date: tmdb_details .as_ref() - .and_then(|j| ok_or_warn(parse_upload_date(&j.upload_date))), + .map(|d| tmdb::parse_release_date(&d.release_date.clone()?).ok()) + .flatten() + .or(infojson + .as_ref() + .and_then(|j| ok_or_warn(infojson::parse_upload_date(&j.upload_date)))), ..Default::default() }, }; 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> { + 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)?) +} -- cgit v1.2.3-70-g09d2