aboutsummaryrefslogtreecommitdiff
path: root/tool/src/import/infojson.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-10-24 19:32:26 +0200
committermetamuffin <metamuffin@disroot.org>2023-10-24 19:32:26 +0200
commit42568332b5433c97813e8c291db0fc0d15867b76 (patch)
tree299ef0d2306b2c986bdbe0df39545a5a2b04f062 /tool/src/import/infojson.rs
parent2fc5931a6ce9bbb75757c4a20022b19778bd91c5 (diff)
downloadjellything-42568332b5433c97813e8c291db0fc0d15867b76.tar
jellything-42568332b5433c97813e8c291db0fc0d15867b76.tar.bz2
jellything-42568332b5433c97813e8c291db0fc0d15867b76.tar.zst
import -> jellytool
Diffstat (limited to 'tool/src/import/infojson.rs')
-rw-r--r--tool/src/import/infojson.rs143
1 files changed, 143 insertions, 0 deletions
diff --git a/tool/src/import/infojson.rs b/tool/src/import/infojson.rs
new file mode 100644
index 0000000..dd2151b
--- /dev/null
+++ b/tool/src/import/infojson.rs
@@ -0,0 +1,143 @@
+/*
+ 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.
+ Copyright (C) 2023 metamuffin <metamuffin.org>
+*/
+
+use anyhow::Context;
+use jellycommon::chrono::{format::Parsed, DateTime, Utc};
+use serde::{Deserialize, Serialize};
+use std::collections::HashMap;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YVideo {
+ pub id: String,
+ pub title: String,
+ pub formats: Vec<YFormat>,
+ pub thumbnails: Vec<YThumbnail>,
+ pub thumbnail: String,
+ pub description: String,
+ pub channel_id: String,
+ pub duration: Option<f64>,
+ pub view_count: usize,
+ pub average_rating: Option<String>,
+ pub age_limit: usize,
+ pub webpage_url: String,
+ pub categories: Vec<String>,
+ pub tags: Vec<String>,
+ pub playable_in_embed: bool,
+ pub automatic_captions: HashMap<String, Vec<YCaption>>,
+ pub comment_count: Option<usize>,
+ pub chapters: Option<Vec<YChapter>>,
+ pub heatmap: Option<Vec<YHeatmapSample>>,
+ pub like_count: Option<usize>,
+ pub channel: Option<String>,
+ pub channel_follower_count: usize,
+ pub channel_is_verified: Option<bool>,
+ pub uploader: String,
+ pub uploader_id: String,
+ pub uploader_url: String,
+ pub upload_date: String,
+ pub availability: String, // "public" | "private" | "unlisted",
+ pub original_url: Option<String>,
+ pub webpage_url_basename: String,
+ pub webpage_url_domain: String,
+ pub extractor: String,
+ pub extractor_key: String,
+ pub playlist_count: usize,
+ pub playlist: String,
+ pub playlist_id: String,
+ pub playlist_title: String,
+ pub playlist_uploader: String,
+ pub playlist_uploader_id: String,
+ pub n_entries: usize,
+ pub playlist_index: usize,
+ pub display_id: String,
+ pub fulltitle: String,
+ pub duration_string: String,
+ pub is_live: bool,
+ pub was_live: bool,
+ pub epoch: usize,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YCaption {
+ pub url: Option<String>,
+ pub ext: String, //"vtt" | "json3" | "srv1" | "srv2" | "srv3" | "ttml",
+ pub protocol: Option<String>,
+ pub name: Option<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YFormat {
+ pub format_id: String,
+ pub format_note: Option<String>,
+ pub ext: String,
+ pub protocol: String,
+ pub acodec: Option<String>,
+ pub vcodec: Option<String>,
+ pub url: Option<String>,
+ pub width: Option<u32>,
+ pub height: Option<u32>,
+ pub fps: Option<f64>,
+ pub columns: Option<u32>,
+ pub fragments: Option<Vec<YFragment>>,
+ pub resolution: String,
+ pub dynamic_range: Option<String>,
+ pub aspect_ratio: Option<f64>,
+ pub http_headers: HashMap<String, String>,
+ pub audio_ext: String,
+ pub video_ext: String,
+ pub vbr: Option<f64>,
+ pub abr: Option<f64>,
+ pub format: String,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YFragment {
+ pub url: Option<String>,
+ pub duration: Option<f64>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YThumbnail {
+ pub url: String,
+ pub preference: i32,
+ pub id: String,
+ pub height: Option<u32>,
+ pub width: Option<u32>,
+ pub resolution: Option<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YChapter {
+ pub start_time: f64,
+ pub end_time: f64,
+ pub title: String,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct YHeatmapSample {
+ pub start_time: f64,
+ pub end_time: f64,
+ pub value: f64,
+}
+
+pub fn parse_upload_date(d: &str) -> anyhow::Result<DateTime<Utc>> {
+ let (year, month, day) = (&d[0..4], &d[4..6], &d[6..8]);
+ 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)?)
+}