Commit 6b52ccce6c
Unsigned
Layout: unified · split
docs/src/commands.md +8
| @@ -47,6 +47,14 @@ run [command] | ||
| 47 | 47 | > |
| 48 | 48 | > But for when tasks are stacked up in the *same* event loop and the order of which they are executed matters, this command can be used to force the already stacked up commands to be ran first. |
| 49 | 49 | |
| 50 | ## Library | |
| 51 | ||
| 52 | ```vim | |
| 53 | bookmark [id] | |
| 54 | unmark [id] | |
| 55 | togglemark [id] | |
| 56 | ``` | |
| 57 | ||
| 50 | 58 | ## Text commands |
| 51 | 59 | |
| 52 | 60 | Text commands generates a *text only response* without launching the TUI. |
src/config/commands.rs +29 −33
| @@ -83,7 +83,7 @@ impl Default for CommandsConfigSerde { | ||
| 83 | 83 | // Different pages may contain different `env`s (for example `url` is different in each page) |
| 84 | 84 | |
| 85 | 85 | fn launch_command_default() -> String { |
| 86 | String::from("loadpage popular ;; flush ;; history clear") | |
| 86 | String::from("loadpage watchhistory ;; flush ;; history clear") | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | fn video_default() -> Vec<HashMap<String, String>> { |
| @@ -111,16 +111,16 @@ fn video_default() -> Vec<HashMap<String, String>> { | ||
| 111 | 111 | String::from("run ${browser} '${url}'"), |
| 112 | 112 | )]), |
| 113 | 113 | HashMap::from([( |
| 114 | String::from("Download video (webm)"), | |
| 115 | String::from( | |
| 116 | "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} '${embed-url}'", | |
| 117 | ), | |
| 114 | String::from("Toggle bookmark"), | |
| 115 | String::from("togglemark ${id}") | |
| 118 | 116 | )]), |
| 119 | 117 | HashMap::from([( |
| 120 | String::from("Download audio (opus)"), | |
| 121 | String::from( | |
| 122 | "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} '${embed-url}' -x", | |
| 123 | ), | |
| 118 | String::from("Save video"), | |
| 119 | String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}' ;; run ${terminal-emulator} ${youtube-downloader} ${all-videos} -o '${save-path}${id}/%(id)s'") | |
| 120 | )]), | |
| 121 | HashMap::from([( | |
| 122 | String::from("Save audio"), | |
| 123 | String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}' ;; run ${terminal-emulator} ${youtube-downloader} ${all-videos} -x -o '${save-path}${id}/%(id)s'") | |
| 124 | 124 | )]), |
| 125 | 125 | HashMap::from([( |
| 126 | 126 | String::from("Mode: ${provider}"), |
| @@ -132,6 +132,10 @@ fn video_default() -> Vec<HashMap<String, String>> { | ||
| 132 | 132 | fn playlist_default() -> Vec<HashMap<String, String>> { |
| 133 | 133 | vec![ |
| 134 | 134 | HashMap::from([(String::from("Switch view"), String::from("%switch-view%"))]), |
| 135 | HashMap::from([( | |
| 136 | String::from("Reload as online mode"), | |
| 137 | String::from("playlist ${id}"), | |
| 138 | )]), | |
| 135 | 139 | HashMap::from([( |
| 136 | 140 | String::from("Play all videos"), |
| 137 | 141 | String::from("run ${video-player} ${all-videos}"), |
| @@ -140,10 +144,6 @@ fn playlist_default() -> Vec<HashMap<String, String>> { | ||
| 140 | 144 | String::from("Play all audio"), |
| 141 | 145 | String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video"), |
| 142 | 146 | )]), |
| 143 | HashMap::from([( | |
| 144 | String::from("Shuffle play all audio"), | |
| 145 | String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle"), | |
| 146 | )]), | |
| 147 | 147 | HashMap::from([( |
| 148 | 148 | String::from("Shuffle play all audio (loop)"), |
| 149 | 149 | String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf"), |
| @@ -157,12 +157,12 @@ fn playlist_default() -> Vec<HashMap<String, String>> { | ||
| 157 | 157 | String::from("run ${browser} '${url}'"), |
| 158 | 158 | )]), |
| 159 | 159 | HashMap::from([( |
| 160 | String::from("Download all video (webm)"), | |
| 161 | String::from("run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}") | |
| 160 | String::from("Toggle bookmark"), | |
| 161 | String::from("togglemark ${id}") | |
| 162 | 162 | )]), |
| 163 | 163 | HashMap::from([( |
| 164 | String::from("Download all audio (opus)"), | |
| 165 | String::from("run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x") | |
| 164 | String::from("Save all audio"), | |
| 165 | String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}' ;; run mkdir '${save-path}${id}' ;; run ${terminal-emulator} ${youtube-downloader} ${all-videos} -x -o '${save-path}${id}/%(id)s'") | |
| 166 | 166 | )]), |
| 167 | 167 | HashMap::from([( |
| 168 | 168 | String::from("Mode: ${provider}"), |
| @@ -200,16 +200,16 @@ fn local_video_default() -> Vec<HashMap<String, String>> { | ||
| 200 | 200 | String::from("run ${browser} '${url}'"), |
| 201 | 201 | )]), |
| 202 | 202 | HashMap::from([( |
| 203 | String::from("Download video (webm)"), | |
| 204 | String::from( | |
| 205 | "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} '${embed-url}'", | |
| 206 | ), | |
| 203 | String::from("Toggle bookmark"), | |
| 204 | String::from("togglemark ${id}") | |
| 207 | 205 | )]), |
| 208 | 206 | HashMap::from([( |
| 209 | String::from("Download audio (opus)"), | |
| 210 | String::from( | |
| 211 | "run ${terminal-emulator} ${youtube-downloader} -o ${download-path} '${embed-url}' -x", | |
| 212 | ), | |
| 207 | String::from("Save video"), | |
| 208 | String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}' ;; run ${terminal-emulator} ${youtube-downloader} ${all-videos} -o '${save-path}${id}/%(id)s'") | |
| 209 | )]), | |
| 210 | HashMap::from([( | |
| 211 | String::from("Save audio"), | |
| 212 | String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}' ;; run ${terminal-emulator} ${youtube-downloader} ${all-videos} -x -o '${save-path}${id}/%(id)s'") | |
| 213 | 213 | )]), |
| 214 | 214 | HashMap::from([( |
| 215 | 215 | String::from("Mode: ${provider}"), |
| @@ -233,10 +233,6 @@ fn local_playlist_default() -> Vec<HashMap<String, String>> { | ||
| 233 | 233 | String::from("Play all audio"), |
| 234 | 234 | String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video"), |
| 235 | 235 | )]), |
| 236 | HashMap::from([( | |
| 237 | String::from("Shuffle play all audio"), | |
| 238 | String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle"), | |
| 239 | )]), | |
| 240 | 236 | HashMap::from([( |
| 241 | 237 | String::from("Shuffle play all audio (loop)"), |
| 242 | 238 | String::from("run ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf"), |
| @@ -250,12 +246,12 @@ fn local_playlist_default() -> Vec<HashMap<String, String>> { | ||
| 250 | 246 | String::from("run ${browser} '${url}'"), |
| 251 | 247 | )]), |
| 252 | 248 | HashMap::from([( |
| 253 | String::from("Download all video (webm)"), | |
| 254 | String::from("run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}") | |
| 249 | String::from("Toggle bookmark"), | |
| 250 | String::from("togglemark ${id}") | |
| 255 | 251 | )]), |
| 256 | 252 | HashMap::from([( |
| 257 | String::from("Download all audio (opus)"), | |
| 258 | String::from("run ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x") | |
| 253 | String::from("Save all audio"), | |
| 254 | String::from("bookmark ${id} ;; run rm -rf '${save-path}${id}' ;; run mkdir '${save-path}${id}' ;; run ${terminal-emulator} ${youtube-downloader} ${all-videos} -x -o '${save-path}${id}/%(id)s'") | |
| 259 | 255 | )]), |
| 260 | 256 | HashMap::from([( |
| 261 | 257 | String::from("Mode: ${provider}"), |
src/config/main.rs +5 −1
| @@ -147,7 +147,11 @@ fn default_env() -> HashMap<String, String> { | ||
| 147 | 147 | (String::from("youtube-downloader"), String::from("yt-dlp")), |
| 148 | 148 | ( |
| 149 | 149 | String::from("download-path"), |
| 150 | String::from("'~/Downloads/%(title)s-%(id)s.%(ext)s'"), | |
| 150 | String::from("~/Downloads/%(title)s-%(id)s.%(ext)s"), | |
| 151 | ), | |
| 152 | ( | |
| 153 | String::from("save-path"), | |
| 154 | String::from("~/.local/share/youtube-tui/saved/"), | |
| 151 | 155 | ), |
| 152 | 156 | ]) |
| 153 | 157 | } |
src/exit.rs +1 −1
| @@ -2,7 +2,7 @@ use home::home_dir; | ||
| 2 | 2 | use std::{error::Error, fs}; |
| 3 | 3 | use tui_additions::framework::Framework; |
| 4 | 4 | |
| 5 | use crate::global::structs::WatchHistory; | |
| 5 | use crate::global::{structs::WatchHistory, traits::Collection}; | |
| 6 | 6 | |
| 7 | 7 | /// function to run when the app ends |
| 8 | 8 | // exit tasks: |
src/global/functions/download_all_images.rs +1 −1
| @@ -36,7 +36,7 @@ impl From<&Item> for Option<DownloadRequest> { | ||
| 36 | 36 | url: fullchannel.thumbnail_url.clone(), |
| 37 | 37 | id: fullchannel.id.clone(), |
| 38 | 38 | }, |
| 39 | Item::Unknown(_) | Item::Page(_) => return None, | |
| 39 | _ => return None, | |
| 40 | 40 | }) |
| 41 | 41 | } |
| 42 | 42 | } |
src/global/functions/from_url.rs +2 −6
| @@ -10,15 +10,11 @@ pub fn from_channel_url(identifier: &str) -> Result<String, String> { | ||
| 10 | 10 | // if there isnt 24 characters after `/channel/`, that url must not have |
| 11 | 11 | // contained a channel id |
| 12 | 12 | if identifier.len() < index + 33 { |
| 13 | return Err(format!( | |
| 14 | "Cannot find channel id from string `{identifier}`" | |
| 15 | )); | |
| 13 | return Err(format!("Cannot find channel id from string `{identifier}`")); | |
| 16 | 14 | } |
| 17 | 15 | index + 9 |
| 18 | 16 | } else { |
| 19 | return Err(format!( | |
| 20 | "Cannot find channel id from string `{identifier}`" | |
| 21 | )); | |
| 17 | return Err(format!("Cannot find channel id from string `{identifier}`")); | |
| 22 | 18 | }; |
| 23 | 19 | |
| 24 | 20 | Ok(identifier[index..index + 24].to_string()) |
src/global/functions/init_move.rs added +28
| @@ -0,0 +1,28 @@ | ||
| 1 | use std::fs; | |
| 2 | ||
| 3 | use home::home_dir; | |
| 4 | ||
| 5 | pub fn init_move() { | |
| 6 | let home_dir = home_dir().unwrap(); | |
| 7 | let store_dir = home_dir.join(".local/share/youtube-tui/"); | |
| 8 | let cache_dir = home_dir.join(".cache/youtube-tui"); | |
| 9 | ||
| 10 | let store_info_dir = store_dir.join("info/"); | |
| 11 | let cache_info_dir = cache_dir.join("info/"); | |
| 12 | fs::read_dir(store_info_dir).unwrap().for_each(|entry| { | |
| 13 | let entry = entry.unwrap().path(); | |
| 14 | let _ = fs::rename(&entry, cache_info_dir.join(entry.file_name().unwrap())); | |
| 15 | }); | |
| 16 | ||
| 17 | let store_thumbnails_dir = store_dir.join("thumbnails/"); | |
| 18 | let cache_thumbnails_dir = cache_dir.join("thumbnails/"); | |
| 19 | fs::read_dir(store_thumbnails_dir) | |
| 20 | .unwrap() | |
| 21 | .for_each(|entry| { | |
| 22 | let entry = entry.unwrap().path(); | |
| 23 | let _ = fs::rename( | |
| 24 | &entry, | |
| 25 | cache_thumbnails_dir.join(entry.file_name().unwrap()), | |
| 26 | ); | |
| 27 | }); | |
| 28 | } | |
src/global/functions/mod.rs +2
| @@ -23,3 +23,5 @@ mod envs; | ||
| 23 | 23 | pub use envs::*; |
| 24 | 24 | mod update_provider; |
| 25 | 25 | pub use update_provider::*; |
| 26 | mod init_move; | |
| 27 | pub use init_move::*; | |
src/global/functions/run_command.rs +56 −4
| @@ -1,13 +1,17 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | 2 | config::Search, |
| 3 | global::structs::{ | |
| 4 | ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Message, Page, SingleItemPage, | |
| 5 | Status, Task, Tasks, | |
| 3 | global::{ | |
| 4 | structs::{ | |
| 5 | ChannelDisplayPage, ChannelDisplayPageType, Item, Library, MainMenuPage, Message, Page, | |
| 6 | SingleItemPage, Status, Task, Tasks, | |
| 7 | }, | |
| 8 | traits::Collection, | |
| 6 | 9 | }, |
| 7 | 10 | load_configs, |
| 8 | 11 | }; |
| 12 | use home::home_dir; | |
| 9 | 13 | use run_script::ScriptOptions; |
| 10 | use std::{env, io::Stdout, thread}; | |
| 14 | use std::{env, error::Error, fs, io::Stdout, thread}; | |
| 11 | 15 | use tui::{backend::CrosstermBackend, Terminal}; |
| 12 | 16 | use tui_additions::framework::Framework; |
| 13 | 17 | |
| @@ -59,6 +63,49 @@ pub fn run_single_command( | ||
| 59 | 63 | // match a command splitted by space to a bunch of avaliable commands |
| 60 | 64 | match command { |
| 61 | 65 | [] => {} |
| 66 | ["bookmark", id] => { | |
| 67 | match (|| -> Result<Item, Box<dyn Error>> { | |
| 68 | Ok(serde_json::from_str(&fs::read_to_string( | |
| 69 | home_dir() | |
| 70 | .unwrap() | |
| 71 | .join(format!(".cache/youtube-tui/info/{id}.json")), | |
| 72 | )?)?) | |
| 73 | })() { | |
| 74 | Ok(item) => { | |
| 75 | let library = framework.data.global.get_mut::<Library>().unwrap(); | |
| 76 | let _ = library.push(item, None); | |
| 77 | let _ = library.save(); | |
| 78 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 79 | Message::Success(String::from("Item bookmarked")) | |
| 80 | } | |
| 81 | Err(e) => { | |
| 82 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 83 | Message::Error(format!("Unknown item: {e}")) | |
| 84 | } | |
| 85 | } | |
| 86 | } | |
| 87 | ["unmark", id] => { | |
| 88 | let library = framework.data.global.get_mut::<Library>().unwrap(); | |
| 89 | ||
| 90 | if library.remove(id) { | |
| 91 | let _ = library.save(); | |
| 92 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 93 | Message::Success(String::from("Bookmark removed")) | |
| 94 | } else { | |
| 95 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 96 | Message::Error(String::from("No item with that ID found")) | |
| 97 | } | |
| 98 | } | |
| 99 | ["togglemark", id] => { | |
| 100 | let library = framework.data.global.get_mut::<Library>().unwrap(); | |
| 101 | if library.remove(id) { | |
| 102 | let _ = library.save(); | |
| 103 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 104 | Message::Success(String::from("Bookmark removed")) | |
| 105 | } else { | |
| 106 | run_single_command(&["bookmark", id], framework, terminal); | |
| 107 | } | |
| 108 | } | |
| 62 | 109 | ["help"] | ["h"] => { |
| 63 | 110 | *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from( |
| 64 | 111 | "Avaliable commands can be viewed by running `youtube-tui help` in terminal", |
| @@ -361,6 +408,11 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m | ||
| 361 | 408 | \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run firefox example.com`) |
| 362 | 409 | \x1b[33mcopy [text]\x1b[0m Copies text to clipboard |
| 363 | 410 | |
| 411 | \x1b[91mLIBRARY:\x1b[0m | |
| 412 | \x1b[33mbookmark [id]\x1b[0m Bookmark item with ID (item must be already loaded) | |
| 413 | \x1b[33munmark [id]\x1b[0m Remove bookmark item with ID | |
| 414 | \x1b[33mtogglemark [id]\x1b[0m Toggle bookmark status | |
| 415 | ||
| 364 | 416 | \x1b[91mALT:\x1b[0m |
| 365 | 417 | \x1b[37malts links back to the original command\x1b[30m |
| 366 | 418 | \x1b[33m[page] (additional options)\x1b[0m `loadpage [page]` |
src/global/structs/library.rs added +24
| @@ -0,0 +1,24 @@ | ||
| 1 | use crate::global::traits::Collection; | |
| 2 | ||
| 3 | use super::Item; | |
| 4 | use serde::{Deserialize, Serialize}; | |
| 5 | use typemap::Key; | |
| 6 | ||
| 7 | #[derive(Clone, Default, Serialize, Deserialize)] | |
| 8 | pub struct Library(pub Vec<Item>); | |
| 9 | ||
| 10 | impl Key for Library { | |
| 11 | type Value = Self; | |
| 12 | } | |
| 13 | ||
| 14 | impl Collection for Library { | |
| 15 | const INDEX_PATH: &'static str = ".local/share/youtube-tui/library.json"; | |
| 16 | ||
| 17 | fn items(&self) -> &Vec<Item> { | |
| 18 | &self.0 | |
| 19 | } | |
| 20 | ||
| 21 | fn items_mut(&mut self) -> &mut Vec<Item> { | |
| 22 | &mut self.0 | |
| 23 | } | |
| 24 | } | |
src/global/structs/mod.rs +2
| @@ -3,6 +3,7 @@ mod errors; | ||
| 3 | 3 | mod invidiousclient; |
| 4 | 4 | mod item; |
| 5 | 5 | mod keyaction; |
| 6 | mod library; | |
| 6 | 7 | mod message; |
| 7 | 8 | mod page; |
| 8 | 9 | mod state_env; |
| @@ -14,6 +15,7 @@ pub use errors::*; | ||
| 14 | 15 | pub use invidiousclient::*; |
| 15 | 16 | pub use item::*; |
| 16 | 17 | pub use keyaction::*; |
| 18 | pub use library::*; | |
| 17 | 19 | pub use message::*; |
| 18 | 20 | pub use page::*; |
| 19 | 21 | pub use state_env::*; |
src/global/structs/watchhistory.rs +8 −145
| @@ -1,11 +1,7 @@ | ||
| 1 | use crate::global::traits::Collection; | |
| 2 | ||
| 1 | 3 | use super::Item; |
| 2 | use home::home_dir; | |
| 3 | 4 | use serde::{Deserialize, Serialize}; |
| 4 | use std::{ | |
| 5 | error::Error, | |
| 6 | fs::{self, OpenOptions}, | |
| 7 | io::Write, | |
| 8 | }; | |
| 9 | 5 | use typemap::Key; |
| 10 | 6 | |
| 11 | 7 | #[derive(Clone, Default, Serialize, Deserialize)] |
| @@ -15,147 +11,14 @@ impl Key for WatchHistory { | ||
| 15 | 11 | type Value = Self; |
| 16 | 12 | } |
| 17 | 13 | |
| 18 | impl WatchHistory { | |
| 19 | /// saves the current state of watch history into a file | |
| 20 | pub fn save(&self) -> Result<(), Box<dyn Error>> { | |
| 21 | let save_string = serde_json::to_string_pretty( | |
| 22 | &self | |
| 23 | .0 | |
| 24 | .iter() | |
| 25 | .map(|item| item.id().unwrap_or_default()) | |
| 26 | .filter(|id| !id.is_empty()) | |
| 27 | .collect::<Vec<&str>>(), | |
| 28 | )?; | |
| 29 | let path = home_dir() | |
| 30 | .unwrap() | |
| 31 | .join(".local/share/youtube-tui/watch_history/index.json"); | |
| 32 | ||
| 33 | let mut file = OpenOptions::new() | |
| 34 | .write(true) | |
| 35 | .create(true) | |
| 36 | .truncate(true) | |
| 37 | .open(path)?; | |
| 38 | ||
| 39 | file.write_all(save_string.as_bytes())?; | |
| 40 | ||
| 41 | Ok(()) | |
| 42 | } | |
| 43 | ||
| 44 | /// add an item to watch history | |
| 45 | pub fn push(&mut self, item: Item, max_items: usize) -> Result<(), Box<dyn Error>> { | |
| 46 | let info = home_dir() | |
| 47 | .unwrap() | |
| 48 | .join(".local/share/youtube-tui/watch_history/info/"); | |
| 49 | ||
| 50 | // removes duplicates and place them on top (if exists) | |
| 51 | let id = item.id().unwrap_or("invalid-dump"); | |
| 52 | if let Some(index) = self | |
| 53 | .0 | |
| 54 | .iter() | |
| 55 | .position(|item_in_iter| item_in_iter.id().unwrap_or_default() == id) | |
| 56 | { | |
| 57 | let _ = fs::remove_file(info.join(format!("{id}.json"))); | |
| 58 | self.0.remove(index); | |
| 59 | } | |
| 60 | let mut file = OpenOptions::new() | |
| 61 | .write(true) | |
| 62 | .create(true) | |
| 63 | .truncate(true) | |
| 64 | .open(info.join(format!("{id}.json")))?; | |
| 65 | let item_string = serde_json::to_string(&item)?; | |
| 66 | file.write_all(item_string.as_bytes())?; | |
| 67 | ||
| 68 | self.0.push(item); | |
| 69 | ||
| 70 | // if length of history exceeds the maximum history length, removes that oldest item | |
| 71 | if self.0.len() > max_items { | |
| 72 | let _ = fs::remove_file( | |
| 73 | info.join(format!("{}.json", self.0[0].id().unwrap_or("invalid-dump"))), | |
| 74 | ); | |
| 75 | self.0.remove(0); | |
| 76 | } | |
| 14 | impl Collection for WatchHistory { | |
| 15 | const INDEX_PATH: &'static str = ".local/share/youtube-tui/watch_history.json"; | |
| 77 | 16 | |
| 78 | Ok(()) | |
| 17 | fn items(&self) -> &Vec<Item> { | |
| 18 | &self.0 | |
| 79 | 19 | } |
| 80 | 20 | |
| 81 | /// loads watch history from file | |
| 82 | pub fn load() -> Self { | |
| 83 | let path = home_dir() | |
| 84 | .unwrap() | |
| 85 | .join(".local/share/youtube-tui/watch_history/index.json"); | |
| 86 | let res = (|| -> Result<Vec<String>, Box<dyn Error>> { | |
| 87 | let file_string = fs::read_to_string(&path)?; | |
| 88 | let deserialized = serde_json::from_str(&file_string)?; | |
| 89 | Ok(deserialized) | |
| 90 | })(); | |
| 91 | ||
| 92 | // if res is err, then the file either doesn't exist of has be altered incorrectly, in | |
| 93 | // which case returns Self::default() | |
| 94 | if let Ok(deserialized) = res { | |
| 95 | let info = home_dir() | |
| 96 | .unwrap() | |
| 97 | .join(".local/share/youtube-tui/watch_history/info/"); | |
| 98 | Self( | |
| 99 | deserialized | |
| 100 | .into_iter() | |
| 101 | .filter_map(|id| fs::read_to_string(info.join(format!("{id}.json"))).ok()) | |
| 102 | .filter_map(|file_content| serde_json::from_str(&file_content).ok()) | |
| 103 | .collect(), | |
| 104 | ) | |
| 105 | } else { | |
| 106 | // if the file does exist, back it up | |
| 107 | // if it doesn't exist, it will throw an error but we dont care | |
| 108 | let mut new_path = path.clone(); | |
| 109 | new_path.pop(); | |
| 110 | new_path.push(format!("index-{}.json", chrono::offset::Local::now(),)); | |
| 111 | let _ = fs::rename(&path, &new_path); | |
| 112 | ||
| 113 | Self::default() | |
| 114 | } | |
| 115 | } | |
| 116 | ||
| 117 | /// moves all thumbnails from storage to cache when starting | |
| 118 | pub fn init_move() { | |
| 119 | let history_thumbnails_path = home_dir() | |
| 120 | .unwrap() | |
| 121 | .join(".local/share/youtube-tui/watch_history/thumbnails/"); | |
| 122 | let cache_thumbnails_path = home_dir().unwrap().join(".cache/youtube-tui/thumbnails/"); | |
| 123 | ||
| 124 | fs::read_dir(history_thumbnails_path) | |
| 125 | .unwrap() | |
| 126 | .into_iter() | |
| 127 | .for_each(|path| { | |
| 128 | let path = path.unwrap().path(); | |
| 129 | let _ = fs::rename( | |
| 130 | path.clone(), | |
| 131 | cache_thumbnails_path.join(path.file_name().unwrap()), | |
| 132 | ); | |
| 133 | }); | |
| 134 | } | |
| 135 | ||
| 136 | /// moves thumbnails of videos in watch history from cache back to storage when exiting, so that thumbnails can be viewed offline | |
| 137 | pub fn exit_move(&self) { | |
| 138 | let history_thumbnails_path = home_dir() | |
| 139 | .unwrap() | |
| 140 | .join(".local/share/youtube-tui/watch_history/thumbnails/"); | |
| 141 | let cache_thumbnails_path = home_dir().unwrap().join(".cache/youtube-tui/thumbnails/"); | |
| 142 | ||
| 143 | self.0.iter().for_each(|item| { | |
| 144 | let id = item.id().unwrap(); | |
| 145 | let _ = fs::rename( | |
| 146 | cache_thumbnails_path.join(id), | |
| 147 | history_thumbnails_path.join(id), | |
| 148 | ); | |
| 149 | ||
| 150 | if let Ok(fullplaylist) = item.fullplaylist() { | |
| 151 | fullplaylist.videos.iter().for_each(|video| { | |
| 152 | let id = video.id().unwrap_or("invalid-dump"); | |
| 153 | let _ = fs::rename( | |
| 154 | cache_thumbnails_path.join(id), | |
| 155 | history_thumbnails_path.join(id), | |
| 156 | ); | |
| 157 | }) | |
| 158 | } | |
| 159 | }) | |
| 21 | fn items_mut(&mut self) -> &mut Vec<Item> { | |
| 22 | &mut self.0 | |
| 160 | 23 | } |
| 161 | 24 | } |
src/global/traits/collection.rs added +152
| @@ -0,0 +1,152 @@ | ||
| 1 | use home::home_dir; | |
| 2 | use serde::{de::DeserializeOwned, Serialize}; | |
| 3 | use std::{ | |
| 4 | error::Error, | |
| 5 | fs::{self, OpenOptions}, | |
| 6 | io::Write, | |
| 7 | }; | |
| 8 | use typemap::Key; | |
| 9 | ||
| 10 | use crate::global::structs::Item; | |
| 11 | ||
| 12 | pub trait Collection | |
| 13 | where | |
| 14 | Self: Default + Clone + Serialize + DeserializeOwned + Key, | |
| 15 | { | |
| 16 | const INDEX_PATH: &'static str; | |
| 17 | ||
| 18 | fn items(&self) -> &Vec<Item>; | |
| 19 | fn items_mut(&mut self) -> &mut Vec<Item>; | |
| 20 | ||
| 21 | /// saves the current state of watch history into a file | |
| 22 | fn save(&self) -> Result<(), Box<dyn Error>> { | |
| 23 | let save_string = serde_json::to_string_pretty( | |
| 24 | &self | |
| 25 | .items() | |
| 26 | .iter() | |
| 27 | .map(|item| item.id().unwrap_or_default()) | |
| 28 | .filter(|id| !id.is_empty()) | |
| 29 | .collect::<Vec<&str>>(), | |
| 30 | )?; | |
| 31 | let path = home_dir().unwrap().join(Self::INDEX_PATH); | |
| 32 | ||
| 33 | let mut file = OpenOptions::new() | |
| 34 | .write(true) | |
| 35 | .create(true) | |
| 36 | .truncate(true) | |
| 37 | .open(path)?; | |
| 38 | ||
| 39 | file.write_all(save_string.as_bytes())?; | |
| 40 | ||
| 41 | Ok(()) | |
| 42 | } | |
| 43 | ||
| 44 | /// add an item to watch history | |
| 45 | fn push(&mut self, item: Item, max_length: Option<usize>) -> Result<(), Box<dyn Error>> { | |
| 46 | let info = home_dir().unwrap().join(".cache/youtube-tui/info/"); | |
| 47 | ||
| 48 | // removes duplicates and place them on top (if exists) | |
| 49 | let id = item.id().unwrap_or("invalid-dump"); | |
| 50 | if let Some(index) = self | |
| 51 | .items_mut() | |
| 52 | .iter_mut() | |
| 53 | .position(|item_in_iter| item_in_iter.id().unwrap_or_default() == id) | |
| 54 | { | |
| 55 | self.items_mut().remove(index); | |
| 56 | } | |
| 57 | let mut file = OpenOptions::new() | |
| 58 | .write(true) | |
| 59 | .create(true) | |
| 60 | .truncate(true) | |
| 61 | .open(info.join(format!("{id}.json")))?; | |
| 62 | let item_string = serde_json::to_string(&item)?; | |
| 63 | file.write_all(item_string.as_bytes())?; | |
| 64 | ||
| 65 | self.items_mut().push(item); | |
| 66 | ||
| 67 | // if length of history exceeds the maximum history length, removes that oldest item | |
| 68 | if self.items().len() > max_length.unwrap_or(usize::MAX) { | |
| 69 | self.items_mut().remove(0); | |
| 70 | } | |
| 71 | ||
| 72 | Ok(()) | |
| 73 | } | |
| 74 | ||
| 75 | /// loads watch history from file | |
| 76 | fn load() -> Vec<Item> { | |
| 77 | let path = home_dir().unwrap().join(Self::INDEX_PATH); | |
| 78 | let res = (|| -> Result<Vec<String>, Box<dyn Error>> { | |
| 79 | let file_string = fs::read_to_string(&path)?; | |
| 80 | let deserialized = serde_json::from_str(&file_string)?; | |
| 81 | Ok(deserialized) | |
| 82 | })(); | |
| 83 | ||
| 84 | // if res is err, then the file either doesn't exist of has be altered incorrectly, in | |
| 85 | // which case returns Self::default() | |
| 86 | if let Ok(deserialized) = res { | |
| 87 | let info = home_dir().unwrap().join(".cache/youtube-tui/info/"); | |
| 88 | deserialized | |
| 89 | .into_iter() | |
| 90 | .filter_map(|id| fs::read_to_string(info.join(format!("{id}.json"))).ok()) | |
| 91 | .filter_map(|file_content| serde_json::from_str(&file_content).ok()) | |
| 92 | .collect() | |
| 93 | } else { | |
| 94 | // if the file does exist, back it up | |
| 95 | // if it doesn't exist, it will throw an error but we dont care | |
| 96 | let mut new_path = path.clone(); | |
| 97 | new_path.pop(); | |
| 98 | new_path.push(format!("index-{}.json", chrono::offset::Local::now(),)); | |
| 99 | let _ = fs::rename(&path, &new_path); | |
| 100 | ||
| 101 | Vec::new() | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | /// moves thumbnails of videos in watch history from cache back to storage when exiting, so that thumbnails can be viewed offline | |
| 106 | fn exit_move(&self) { | |
| 107 | let home_dir = home_dir().unwrap(); | |
| 108 | let store_thumbnails_path = home_dir.join(".local/share/youtube-tui/thumbnails/"); | |
| 109 | let store_info_path = home_dir.join(".local/share/youtube-tui/info/"); | |
| 110 | let cache_thumbnails_path = home_dir.join(".cache/youtube-tui/thumbnails/"); | |
| 111 | let cache_info_path = home_dir.join(".cache/youtube-tui/info"); | |
| 112 | ||
| 113 | self.items().iter().for_each(|item| { | |
| 114 | let id = item.id().unwrap_or("invalid-dump"); | |
| 115 | let _ = fs::rename( | |
| 116 | cache_thumbnails_path.join(id), | |
| 117 | store_thumbnails_path.join(id), | |
| 118 | ); | |
| 119 | ||
| 120 | let _ = fs::rename( | |
| 121 | cache_info_path.join(format!("{id}.json")), | |
| 122 | store_info_path.join(format!("{id}.json")), | |
| 123 | ); | |
| 124 | ||
| 125 | if let Item::FullPlaylist(fullplaylist) = item { | |
| 126 | fullplaylist.videos.iter().for_each(|video| { | |
| 127 | let id = video.id().unwrap_or("invalid-dump"); | |
| 128 | let _ = fs::rename( | |
| 129 | cache_thumbnails_path.join(id), | |
| 130 | store_thumbnails_path.join(id), | |
| 131 | ); | |
| 132 | }) | |
| 133 | } | |
| 134 | }) | |
| 135 | } | |
| 136 | ||
| 137 | /// remove item based on their id | |
| 138 | fn remove(&mut self, id: &str) -> bool { | |
| 139 | let items = self.items_mut(); | |
| 140 | ||
| 141 | if let Some(found) = items | |
| 142 | .iter() | |
| 143 | .enumerate() | |
| 144 | .find(|(_index, item)| item.id() == Some(id)) | |
| 145 | { | |
| 146 | items.remove(found.0); | |
| 147 | true | |
| 148 | } else { | |
| 149 | false | |
| 150 | } | |
| 151 | } | |
| 152 | } | |
src/global/traits/mod.rs +2
| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | //! public traits |
| 2 | 2 | mod asurlstring; |
| 3 | mod collection; | |
| 3 | 4 | mod configtrait; |
| 4 | 5 | mod searchfilteritem; |
| 5 | 6 | |
| 6 | 7 | pub use asurlstring::*; |
| 8 | pub use collection::*; | |
| 7 | 9 | pub use configtrait::*; |
| 8 | 10 | pub use searchfilteritem::*; |
src/init.rs +29 −25
| @@ -4,9 +4,11 @@ use crate::{ | ||
| 4 | 4 | CommandsConfigSerde, KeyBindingsConfig, MainConfig, MinDimentions, PagesConfig, Search, |
| 5 | 5 | }, |
| 6 | 6 | global::{ |
| 7 | functions::run_command, | |
| 8 | structs::{InvidiousClient, Message, Page, StateEnvs, Status, Tasks, WatchHistory}, | |
| 9 | traits::ConfigTrait, | |
| 7 | functions::{init_move, run_command}, | |
| 8 | structs::{ | |
| 9 | InvidiousClient, Library, Message, Page, StateEnvs, Status, Tasks, WatchHistory, | |
| 10 | }, | |
| 11 | traits::{Collection, ConfigTrait}, | |
| 10 | 12 | }, |
| 11 | 13 | }; |
| 12 | 14 | use home::home_dir; |
| @@ -24,30 +26,36 @@ pub fn init( | ||
| 24 | 26 | terminal: &mut Terminal<CrosstermBackend<Stdout>>, |
| 25 | 27 | command: Option<&str>, |
| 26 | 28 | ) -> Result<(), Box<dyn Error>> { |
| 27 | // creating files | |
| 28 | 29 | let home_dir = home_dir().unwrap(); |
| 29 | let cache_thumbnails_path = home_dir.join(".cache/youtube-tui/thumbnails/"); | |
| 30 | let history_thumbnails_path = | |
| 31 | home_dir.join(".local/share/youtube-tui/watch_history/thumbnails/"); | |
| 32 | let history_info_path = home_dir.join(".local/share/youtube-tui/watch_history/info/"); | |
| 33 | ||
| 34 | if !&cache_thumbnails_path.exists() { | |
| 35 | fs::create_dir_all(&cache_thumbnails_path).unwrap(); | |
| 36 | } | |
| 37 | ||
| 38 | if !&history_thumbnails_path.exists() { | |
| 39 | fs::create_dir_all(&history_thumbnails_path).unwrap(); | |
| 40 | } | |
| 41 | 30 | |
| 42 | if !&history_info_path.exists() { | |
| 43 | fs::create_dir_all(&history_info_path).unwrap(); | |
| 44 | } | |
| 31 | // creating files | |
| 32 | [ | |
| 33 | ".cache/youtube-tui/thumbnails/", | |
| 34 | ".cache/youtube-tui/info/", | |
| 35 | ".local/share/youtube-tui/thumbnails/", | |
| 36 | ".local/share/youtube-tui/info/", | |
| 37 | ".local/share/youtube-tui/saved/", | |
| 38 | ] | |
| 39 | .into_iter() | |
| 40 | .for_each(|s| { | |
| 41 | let dir = home_dir.join(s); | |
| 42 | if !dir.exists() { | |
| 43 | fs::create_dir_all(dir).unwrap(); | |
| 44 | } | |
| 45 | }); | |
| 45 | 46 | |
| 46 | // watch history init | |
| 47 | WatchHistory::init_move(); | |
| 47 | init_move(); | |
| 48 | 48 | |
| 49 | 49 | load_configs(&mut framework.split_clean().0).ok(); |
| 50 | 50 | |
| 51 | framework | |
| 52 | .data | |
| 53 | .global | |
| 54 | .insert::<WatchHistory>(WatchHistory(WatchHistory::load())); | |
| 55 | framework | |
| 56 | .data | |
| 57 | .global | |
| 58 | .insert::<Library>(Library(Library::load())); | |
| 51 | 59 | framework.data.global.insert::<Message>(Message::None); |
| 52 | 60 | framework.data.global.insert::<Status>(Status { |
| 53 | 61 | provider: framework.data.global.get::<MainConfig>().unwrap().provider, |
| @@ -101,10 +109,6 @@ pub fn load_configs(framework: &mut FrameworkClean) -> Result<(), Box<dyn Error> | ||
| 101 | 109 | .data |
| 102 | 110 | .global |
| 103 | 111 | .insert::<CommandsConfig>(CommandsConfig::from(*CommandsConfigSerde::load()?)); |
| 104 | framework | |
| 105 | .data | |
| 106 | .global | |
| 107 | .insert::<WatchHistory>(WatchHistory::load()); | |
| 108 | 112 | framework |
| 109 | 113 | .data |
| 110 | 114 | .global |
src/items/itemlist.rs +17 −15
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | use std::error::Error; |
| 2 | 2 | |
| 3 | use home::home_dir; | |
| 3 | 4 | use tui::{ |
| 4 | 5 | layout::{Constraint, Rect}, |
| 5 | 6 | style::Style, |
| @@ -16,7 +17,7 @@ use crate::{ | ||
| 16 | 17 | functions::{download_all_images, set_envs, update_provider}, |
| 17 | 18 | structs::{ |
| 18 | 19 | ChannelDisplayPage, ChannelDisplayPageType, FullChannelItem, FullPlaylistItem, |
| 19 | FullVideoItem, InvidiousClient, Item, KeyAction, MainMenuPage, Message, | |
| 20 | FullVideoItem, InvidiousClient, Item, KeyAction, Library, MainMenuPage, Message, | |
| 20 | 21 | MiniChannelItem, MiniPlaylistItem, MiniVideoItem, Page, SingleItemPage, StateEnvs, |
| 21 | 22 | Status, Task, Tasks, WatchHistory, |
| 22 | 23 | }, |
| @@ -40,7 +41,7 @@ impl ItemList { | ||
| 40 | 41 | status: &Status, |
| 41 | 42 | ) -> Vec<(String, String)> { |
| 42 | 43 | if self.textlist.items.is_empty() { |
| 43 | return vec![]; | |
| 44 | return Vec::new(); | |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | match &self.items[self.textlist.selected] { |
| @@ -125,8 +126,14 @@ impl ItemList { | ||
| 125 | 126 | |
| 126 | 127 | /// handles select (enter) |
| 127 | 128 | fn select_at_cursor(&self, framework: &mut FrameworkClean) { |
| 128 | let page = framework.data.state.get::<Page>().unwrap(); | |
| 129 | let page_to_load = if *page == Page::MainMenu(MainMenuPage::History) { | |
| 129 | let page_to_load = if home_dir() | |
| 130 | .unwrap() | |
| 131 | .join(format!( | |
| 132 | ".cache/youtube-tui/info/{}.json", | |
| 133 | self.items[self.textlist.selected].id().unwrap_or_default() | |
| 134 | )) | |
| 135 | .exists() | |
| 136 | { | |
| 130 | 137 | match &self.items[self.textlist.selected] { |
| 131 | 138 | Item::MiniVideo(MiniVideoItem { id, .. }) |
| 132 | 139 | | Item::FullVideo(FullVideoItem { id, .. }) => { |
| @@ -312,20 +319,15 @@ impl FrameworkItem for ItemList { | ||
| 312 | 319 | .collect(); |
| 313 | 320 | } |
| 314 | 321 | Page::MainMenu(MainMenuPage::Subscriptions) => {} |
| 315 | Page::MainMenu(MainMenuPage::Library) => {} | |
| 322 | Page::MainMenu(MainMenuPage::Library) => { | |
| 323 | let history = framework.data.global.get::<Library>().unwrap(); | |
| 324 | self.items = history.0.clone().into_iter().rev().collect(); | |
| 325 | } | |
| 316 | 326 | Page::MainMenu(MainMenuPage::History) => { |
| 317 | 327 | // the vector needs to be reversed because the latest watch history is pushed to |
| 318 | 328 | // the back, meaning it needs to be reversed so that the latests one are on top |
| 319 | self.items = framework | |
| 320 | .data | |
| 321 | .global | |
| 322 | .get::<WatchHistory>() | |
| 323 | .unwrap() | |
| 324 | .0 | |
| 325 | .clone() | |
| 326 | .into_iter() | |
| 327 | .rev() | |
| 328 | .collect(); | |
| 329 | let history = framework.data.global.get::<WatchHistory>().unwrap(); | |
| 330 | self.items = history.0.clone().into_iter().rev().collect(); | |
| 329 | 331 | } |
| 330 | 332 | Page::Search(search) => { |
| 331 | 333 | self.items = client |
src/items/singleitem.rs +31 −15
| @@ -9,6 +9,7 @@ use crate::{ | ||
| 9 | 9 | InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, StateEnvs, Status, |
| 10 | 10 | Task, Tasks, WatchHistory, |
| 11 | 11 | }, |
| 12 | traits::Collection, | |
| 12 | 13 | }, |
| 13 | 14 | }; |
| 14 | 15 | use home::home_dir; |
| @@ -70,21 +71,25 @@ pub struct SinglePlaylistItem { | ||
| 70 | 71 | |
| 71 | 72 | impl SingleVideoItem { |
| 72 | 73 | pub fn new(commands: &CommandsConfig) -> Self { |
| 73 | Self::new_with_map(commands | |
| 74 | Self::new_with_map( | |
| 75 | commands | |
| 74 | 76 | .video |
| 75 | 77 | .clone() |
| 76 | 78 | .into_iter() |
| 77 | 79 | .map(|(display, command)| (display, command)) |
| 78 | .collect()) | |
| 80 | .collect(), | |
| 81 | ) | |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | pub fn new_local(commands: &CommandsConfig) -> Self { |
| 82 | Self::new_with_map(commands | |
| 85 | Self::new_with_map( | |
| 86 | commands | |
| 83 | 87 | .local_video |
| 84 | 88 | .clone() |
| 85 | 89 | .into_iter() |
| 86 | 90 | .map(|(display, command)| (display, command)) |
| 87 | .collect()) | |
| 91 | .collect(), | |
| 92 | ) | |
| 88 | 93 | } |
| 89 | 94 | |
| 90 | 95 | pub fn new_with_map(commands: Vec<(String, String)>) -> Self { |
| @@ -182,21 +187,27 @@ impl SingleVideoItem { | ||
| 182 | 187 | |
| 183 | 188 | impl SinglePlaylistItem { |
| 184 | 189 | pub fn new(commands: &CommandsConfig, playlist_items: &[Item]) -> Self { |
| 185 | Self::new_with_map(commands | |
| 190 | Self::new_with_map( | |
| 191 | commands | |
| 186 | 192 | .playlist |
| 187 | 193 | .clone() |
| 188 | 194 | .into_iter() |
| 189 | 195 | .map(|(display, command)| (display, command)) |
| 190 | .collect(), playlist_items) | |
| 196 | .collect(), | |
| 197 | playlist_items, | |
| 198 | ) | |
| 191 | 199 | } |
| 192 | 200 | |
| 193 | 201 | pub fn new_local(commands: &CommandsConfig, playlist_items: &[Item]) -> Self { |
| 194 | Self::new_with_map(commands | |
| 202 | Self::new_with_map( | |
| 203 | commands | |
| 195 | 204 | .local_playlist |
| 196 | 205 | .clone() |
| 197 | 206 | .into_iter() |
| 198 | 207 | .map(|(display, command)| (display, command)) |
| 199 | .collect(), playlist_items) | |
| 208 | .collect(), | |
| 209 | playlist_items, | |
| 210 | ) | |
| 200 | 211 | } |
| 201 | 212 | |
| 202 | 213 | pub fn new_with_map(commands: Vec<(String, String)>, playlist_items: &[Item]) -> Self { |
| @@ -659,9 +670,11 @@ impl FrameworkItem for SingleItem { | ||
| 659 | 670 | Some(playlist) |
| 660 | 671 | } |
| 661 | 672 | SingleItemPage::LocalVideo(id) => { |
| 662 | let s = fs::read_to_string(home_dir().unwrap().join(format!( | |
| 663 | ".local/share/youtube-tui/watch_history/info/{id}.json" | |
| 664 | )))?; | |
| 673 | let s = fs::read_to_string( | |
| 674 | home_dir() | |
| 675 | .unwrap() | |
| 676 | .join(format!(".cache/youtube-tui/info/{id}.json")), | |
| 677 | )?; | |
| 665 | 678 | self.r#type = SingleItemType::Video(SingleVideoItem::new_local( |
| 666 | 679 | framework.data.global.get::<CommandsConfig>().unwrap(), |
| 667 | 680 | )); |
| @@ -670,9 +683,11 @@ impl FrameworkItem for SingleItem { | ||
| 670 | 683 | } |
| 671 | 684 | |
| 672 | 685 | SingleItemPage::LocalPlaylist(id) => { |
| 673 | let s = fs::read_to_string(home_dir().unwrap().join(format!( | |
| 674 | ".local/share/youtube-tui/watch_history/info/{id}.json" | |
| 675 | )))?; | |
| 686 | let s = fs::read_to_string( | |
| 687 | home_dir() | |
| 688 | .unwrap() | |
| 689 | .join(format!(".cache/youtube-tui/info/{id}.json")), | |
| 690 | )?; | |
| 676 | 691 | |
| 677 | 692 | let playlist: Item = serde_json::from_str(&s)?; |
| 678 | 693 | let videos = &playlist.fullplaylist()?.videos; |
| @@ -704,13 +719,14 @@ impl FrameworkItem for SingleItem { | ||
| 704 | 719 | |
| 705 | 720 | // push to watch history |
| 706 | 721 | let watch_history = framework.data.global.get_mut::<WatchHistory>().unwrap(); |
| 707 | watch_history.push(item, max_watch_history)?; | |
| 722 | watch_history.push(item, Some(max_watch_history))?; | |
| 708 | 723 | watch_history.save()?; |
| 709 | 724 | } |
| 710 | 725 | |
| 711 | 726 | let mainconfig = framework.data.global.get::<MainConfig>().unwrap(); |
| 712 | 727 | // need to update provider every time the item loads or else it will display `${provider}` |
| 713 | 728 | // instead of the actual provider (e.g. `YouTube`) |
| 729 | ||
| 714 | 730 | set_envs( |
| 715 | 731 | self.r#type |
| 716 | 732 | .inflate_load( |