diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:21:27 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:21:27 +0200 |
commit | a491792196c034efbd2f8998944af3f7958c0e52 (patch) | |
tree | a295342aef8cd38e32b05af273ff305b7f2a5cc5 /tool/src/import/infojson.rs | |
parent | 5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8 (diff) | |
parent | 8fc2d47f1f6cde93554ba096b959b3bef3652ac1 (diff) | |
download | jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar.bz2 jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar.zst |
Merge branch 'master' of codeberg.org:metamuffin/jellything
Diffstat (limited to 'tool/src/import/infojson.rs')
-rw-r--r-- | tool/src/import/infojson.rs | 143 |
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)?) +} |