diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-16 12:52:33 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-16 12:52:33 +0100 |
commit | 2ff80433ee16f6e3088af09cac07cd6484b25b50 (patch) | |
tree | 5f54ffa2383c650396ec1cd594f456df8ad0e35d /tool | |
parent | 0a3abebd73e7e7d879ad94fc1d2ec26f9221edc2 (diff) | |
download | jellything-2ff80433ee16f6e3088af09cac07cd6484b25b50.tar jellything-2ff80433ee16f6e3088af09cac07cd6484b25b50.tar.bz2 jellything-2ff80433ee16f6e3088af09cac07cd6484b25b50.tar.zst |
release dates from tmdb
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/import/mod.rs | 15 | ||||
-rw-r--r-- | tool/src/import/tmdb.rs | 21 |
2 files changed, 33 insertions, 3 deletions
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<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)?) +} |