Add video, data, and playlist structs

This commit is contained in:
2026-09-16 21:40:44 -04:00
parent 1b4b4d39c4
commit 5fc42bd0fb
2 changed files with 51 additions and 3 deletions
+51 -2
View File
@@ -2,10 +2,12 @@ use std::time::Duration;
use eframe::{Frame, Storage, CreationContext}; use eframe::{Frame, Storage, CreationContext};
use eframe::egui::{Context, Ui}; use eframe::egui::{Context, Ui};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use yt_dlp::model::VideoQuality;
pub(crate) struct Application { pub(crate) struct Application {
settings: AppSettings, settings: AppSettings,
layers: Vec<Box<dyn crate::layer::Layer>>, layers: Vec<Box<dyn crate::layer::Layer>>,
data: Data,
} }
#[derive(Serialize, Deserialize, Default)] #[derive(Serialize, Deserialize, Default)]
@@ -16,6 +18,36 @@ struct AppSettings {
save_thumbnails: bool, save_thumbnails: bool,
} }
#[derive(Serialize, Deserialize, Default)]
struct Data {
playlists: Vec<Playlist>,
videos: Vec<Video>,
root_path: String,
}
#[derive(Serialize, Deserialize, Default)]
struct Video {
name: String,
uuid: String,
original_url: String,
video_path: String,
thumbnail_path: String,
thumbnail_path_low_quality: String,
video_quality: VideoQuality,
}
#[derive(Serialize, Deserialize, Default)]
struct Playlist {
name: String,
uuid: String,
original_url: String,
videos: Vec<Video>,
creator: String,
thumbnail_path: String,
thumbnail_path_low_quality: String,
}
impl Application { impl Application {
pub fn new(cc: &CreationContext, layers: Vec<Box<dyn crate::layer::Layer>>) -> Self { pub fn new(cc: &CreationContext, layers: Vec<Box<dyn crate::layer::Layer>>) -> Self {
let mut settings = AppSettings::default(); let mut settings = AppSettings::default();
@@ -27,7 +59,16 @@ impl Application {
} }
} }
Self { settings, layers } let mut data = Data::default();
if let Some(storage) = cc.storage {
if let Some(stored_str) = storage.get_string("app_data") {
if let Ok(parsed) = serde_json::from_str(&stored_str) {
data = parsed;
}
}
}
Self { settings, layers, data }
} }
} }
@@ -53,10 +94,18 @@ impl eframe::App for Application {
if let Ok(serialized) = serde_json::to_string(&self.settings) { if let Ok(serialized) = serde_json::to_string(&self.settings) {
_storage.set_string("app_settings", serialized); _storage.set_string("app_settings", serialized);
} }
if let Ok(serialized) = serde_json::to_string(&self.data) {
_storage.set_string("app_data", serialized);
}
} }
fn on_exit(&mut self) { fn on_exit(&mut self) {
let mut layers = std::mem::take(&mut self.layers);
for layer in &mut layers {
layer.on_exit(self);
}
self.layers = layers;
} }
fn auto_save_interval(&self) -> Duration { fn auto_save_interval(&self) -> Duration {
-1
View File
@@ -30,7 +30,6 @@ fn main() {
let mut layers: Vec<Box<dyn layer::Layer>> = Vec::new(); let mut layers: Vec<Box<dyn layer::Layer>> = Vec::new();
layers.push(Box::new(TestLayer::default())); layers.push(Box::new(TestLayer::default()));
let mut options = eframe::NativeOptions::default(); let mut options = eframe::NativeOptions::default();
options.persistence_path = Some(args.state.parse().expect("Failed to parse state config file path into path")); options.persistence_path = Some(args.state.parse().expect("Failed to parse state config file path into path"));
eframe::run_native( eframe::run_native(