aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/src/lib.rs1
-rw-r--r--server/src/routes/ui/node.rs3
-rw-r--r--tool/src/import/mod.rs15
-rw-r--r--tool/src/import/tmdb.rs21
4 files changed, 36 insertions, 4 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs
index 1a08750..ea19205 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -130,6 +130,7 @@ pub enum Rating {
YoutubeViews,
YoutubeLikes,
YoutubeFollowers,
+ Tmdb,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index 972299b..7ba455d 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -182,13 +182,14 @@ markup::define! {
Rating::RottenTomatoes => { @value " Tomatoes" }
Rating::Metacritic => { "Metacritic Score: " @value }
Rating::Imdb => { "IMDb Rating: " @value }
+ Rating::Tmdb => { "TMDB Rating: " @value }
} }
}
@if !node.children.is_empty() {
p { @format!("{} items", node.children.len()) }
}
@if let Some(d) = &node.release_date {
- p { "Released " @d.to_rfc2822() }
+ p { "Released " @d.format("%Y-%m-%d").to_string() }
}
@if let Some(f) = &node.federated {
p.federation { @f }
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)?)
+}