aboutsummaryrefslogtreecommitdiff
path: root/import/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'import/src/lib.rs')
-rw-r--r--import/src/lib.rs53
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);
}