diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-30 13:46:29 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-30 13:46:29 +0100 |
commit | 570f24c99af8c9cd1b9050564c32adb85e2c9c0f (patch) | |
tree | d7513a4d0bc8a6813f2b567054fea1c5b207f230 /import/src/lib.rs | |
parent | a5a73dc868c714391e4da4a53b4e4993fc77372e (diff) | |
download | jellything-570f24c99af8c9cd1b9050564c32adb85e2c9c0f.tar jellything-570f24c99af8c9cd1b9050564c32adb85e2c9c0f.tar.bz2 jellything-570f24c99af8c9cd1b9050564c32adb85e2c9c0f.tar.zst |
channel.info.json
Diffstat (limited to 'import/src/lib.rs')
-rw-r--r-- | import/src/lib.rs | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index 243ac8a..add7e4d 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -9,27 +9,22 @@ use ebml_struct::{ matroska::*, read::{EbmlReadExt, TagRead}, }; +use infojson::YVideo; use jellybase::{assetfed::AssetInner, cache::cache_file, database::Database, CONF, SECRETS}; use jellycommon::{ Chapter, LocalTrack, MediaInfo, Node, NodeID, NodeKind, Rating, SourceTrack, SourceTrackKind, TrackSource, }; -use log::{info, warn}; -use rayon::iter::{ - IntoParallelIterator, IntoParallelRefIterator, ParallelBridge, ParallelDrainRange, - ParallelIterator, -}; +use log::info; +use rayon::iter::{ParallelDrainRange, ParallelIterator}; use regex::Regex; use std::{ - collections::{HashMap, VecDeque}, + collections::HashMap, fs::File, io::{BufReader, ErrorKind, Read, Write}, mem::swap, path::{Path, PathBuf}, - sync::{ - atomic::{AtomicUsize, Ordering}, - LazyLock, - }, + sync::LazyLock, time::UNIX_EPOCH, }; use tmdb::Tmdb; @@ -126,7 +121,6 @@ fn import_iter_inner(path: &Path, db: &Database, incremental: bool) -> Result<Ve } fn import_file(db: &Database, path: &Path) -> Result<()> { - let filename = path.file_stem().unwrap().to_string_lossy(); let parent = NodeID::from_slug( &path .parent() @@ -135,20 +129,22 @@ fn import_file(db: &Database, path: &Path) -> Result<()> { .ok_or(anyhow!("parent no filename"))? .to_string_lossy(), ); + + let filename = path.file_name().unwrap().to_string_lossy(); match filename.as_ref() { - "poster" => { + "poster.jpeg" | "poster.webp" => { db.update_node_init(parent, |node| { node.poster = Some(AssetInner::Media(path.to_owned()).ser()); Ok(()) })?; } - "backdrop" => { + "backdrop.jpeg" | "backdrop.webp" => { db.update_node_init(parent, |node| { node.backdrop = Some(AssetInner::Media(path.to_owned()).ser()); Ok(()) })?; } - "info" => { + "info.json" | "info.yaml" => { let data = serde_yaml::from_reader::<_, Node>(BufReader::new(File::open(path)?))?; db.update_node_init(parent, |node| { fn merge_option<T>(a: &mut Option<T>, b: Option<T>) { @@ -162,6 +158,23 @@ fn import_file(db: &Database, path: &Path) -> Result<()> { Ok(()) })?; } + "channel.info.json" => { + let data = serde_json::from_reader::<_, YVideo>(BufReader::new(File::open(path)?))?; + db.update_node_init(parent, |node| { + node.title = Some( + data.title + .strip_suffix(" - Videos") + .unwrap_or(&data.title) + .to_owned(), + ); + node.description = Some(data.description); + if let Some(followers) = data.channel_follower_count { + node.ratings + .insert(Rating::YoutubeFollowers, followers as f64); + } + Ok(()) + })?; + } _ => (), } @@ -288,12 +301,14 @@ fn import_media_file(db: &Database, path: &Path, parent: NodeID) -> Result<()> { node.title = Some(infojson.title); node.description = Some(infojson.description); node.tagline = Some(infojson.webpage_url); - node.release_date = Some( - infojson::parse_upload_date(&infojson.upload_date) - .context("parsing upload date")?, + if let Some(date) = &infojson.upload_date { + node.release_date = + Some(infojson::parse_upload_date(date).context("parsing upload date")?); + } + node.ratings.insert( + Rating::YoutubeViews, + infojson.view_count.unwrap_or_default() as f64, ); - node.ratings - .insert(Rating::YoutubeViews, infojson.view_count as f64); if let Some(lc) = infojson.like_count { node.ratings.insert(Rating::YoutubeLikes, lc as f64); } |