Commit 5a483c7846
Unsigned
Layout: unified · split
Cargo.lock +28 −1
| @@ -986,6 +986,18 @@ dependencies = [ | ||
| 986 | 986 | "unicase", |
| 987 | 987 | ] |
| 988 | 988 | |
| 989 | [[package]] | |
| 990 | name = "http_req" | |
| 991 | version = "0.14.1" | |
| 992 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 993 | checksum = "bec91a96dfaaf08e42e32408d01988e2578c78e8017fd9484a6b213d0e802ee6" | |
| 994 | dependencies = [ | |
| 995 | "base64", | |
| 996 | "native-tls", | |
| 997 | "unicase", | |
| 998 | "zeroize", | |
| 999 | ] | |
| 1000 | ||
| 989 | 1001 | [[package]] |
| 990 | 1002 | name = "httparse" |
| 991 | 1003 | version = "1.10.1" |
| @@ -1272,7 +1284,7 @@ version = "0.7.8" | ||
| 1272 | 1284 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1273 | 1285 | checksum = "fa2cff01a915c4780785828f6bec4ad5f8d03f34307d4183ca210830a8a6d88d" |
| 1274 | 1286 | dependencies = [ |
| 1275 | "http_req", | |
| 1287 | "http_req 0.12.0", | |
| 1276 | 1288 | "serde", |
| 1277 | 1289 | "serde_json", |
| 1278 | 1290 | ] |
| @@ -3470,6 +3482,7 @@ dependencies = [ | ||
| 3470 | 3482 | "dyn-clone", |
| 3471 | 3483 | "futures", |
| 3472 | 3484 | "home", |
| 3485 | "http_req 0.14.1", | |
| 3473 | 3486 | "invidious", |
| 3474 | 3487 | "libmpv-sirno", |
| 3475 | 3488 | "ratatui", |
| @@ -3531,6 +3544,20 @@ name = "zeroize" | ||
| 3531 | 3544 | version = "1.8.1" |
| 3532 | 3545 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3533 | 3546 | checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" |
| 3547 | dependencies = [ | |
| 3548 | "zeroize_derive", | |
| 3549 | ] | |
| 3550 | ||
| 3551 | [[package]] | |
| 3552 | name = "zeroize_derive" | |
| 3553 | version = "1.4.2" | |
| 3554 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3555 | checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" | |
| 3556 | dependencies = [ | |
| 3557 | "proc-macro2", | |
| 3558 | "quote", | |
| 3559 | "syn", | |
| 3560 | ] | |
| 3534 | 3561 | |
| 3535 | 3562 | [[package]] |
| 3536 | 3563 | name = "zerotrie" |
Cargo.toml +5 −2
| @@ -16,11 +16,13 @@ exclude = ["/docs", "/LICENSE", "/threadcounter.sh", "/PKGBUILD"] | ||
| 16 | 16 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
| 17 | 17 | |
| 18 | 18 | [features] |
| 19 | default = ["sixel", "halfblock", "clipboard", "mpv"] | |
| 19 | default = ["sixel", "halfblock", "clipboard", "mpv", "rustypipe"] | |
| 20 | 20 | sixel = ["viuer/sixel"] |
| 21 | 21 | halfblock = ["viuer"] |
| 22 | 22 | clipboard = ["dep:clipboard"] |
| 23 | 23 | mpv = ["dep:libmpv-sirno"] |
| 24 | invidious = ["invidious/httpreq_sync"] | |
| 25 | rustypipe = [] | |
| 24 | 26 | |
| 25 | 27 | [dependencies] |
| 26 | 28 | serde = {version = "1.0", default-features = false, features = ["derive"]} |
| @@ -30,7 +32,7 @@ home = "0.5" | ||
| 30 | 32 | chrono = {version = "0.4", default-features = false, features = ["clock"]} |
| 31 | 33 | typemap = {version = "0.3", default-features = false} |
| 32 | 34 | tui-additions = {version = "0.4", default-features = false, features = ["framework", "widgets"]} |
| 33 | invidious = {version = "0.7"} | |
| 35 | invidious = { version = "0.7", default-features = false } | |
| 34 | 36 | serde_yaml_ng = {version = "0.10", default-features = false} |
| 35 | 37 | dyn-clone = {version = "1.0", default-features = false} |
| 36 | 38 | serde_json = {version = "1.0", default-features = false} |
| @@ -43,6 +45,7 @@ libmpv-sirno = { version = "2.0.2-fork.1", optional = true } | ||
| 43 | 45 | rustypipe = "0.11" |
| 44 | 46 | futures = { version = "0.3", features = [ "executor" ] } |
| 45 | 47 | tokio = { version = "1", features = [ "rt" ]} |
| 48 | http_req = "0.14.1" | |
| 46 | 49 | |
| 47 | 50 | # libmpv = { path = "libmpv-rs", optional = true, version = "2" } |
| 48 | 51 | # tui-additions = {path = "../Rust/tui-additions", default-features = false, features = ["framework", "widgets"]} |
src/config/main.rs +21 −10
| @@ -1,10 +1,4 @@ | ||
| 1 | use crate::{ | |
| 2 | global::{ | |
| 3 | structs::{InvidiousClient, RustyPipeWrapper}, | |
| 4 | traits::{ConfigTrait, SearchProviderTrait}, | |
| 5 | }, | |
| 6 | MAIN_CONFIG, | |
| 7 | }; | |
| 1 | use crate::global::traits::{ConfigTrait, SearchProviderTrait}; | |
| 8 | 2 | use serde::{Deserialize, Serialize}; |
| 9 | 3 | use std::collections::HashMap; |
| 10 | 4 | use typemap::Key; |
| @@ -152,20 +146,24 @@ pub enum Provider { | ||
| 152 | 146 | |
| 153 | 147 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] |
| 154 | 148 | pub enum SearchProvider { |
| 149 | #[cfg(feature = "invidious")] | |
| 155 | 150 | Invidious, |
| 151 | #[cfg(feature = "rustypipe")] | |
| 156 | 152 | RustyPipe, |
| 157 | 153 | } |
| 158 | 154 | |
| 159 | 155 | impl SearchProvider { |
| 160 | 156 | pub fn create(&self) -> Box<dyn SearchProviderTrait> { |
| 161 | 157 | match self { |
| 162 | Self::Invidious => Box::new(InvidiousClient::new( | |
| 163 | unsafe { MAIN_CONFIG.get() } | |
| 158 | #[cfg(feature = "invidious")] | |
| 159 | Self::Invidious => Box::new(crate::global::structs::InvidiousClient::new( | |
| 160 | unsafe { crate::MAIN_CONFIG.get() } | |
| 164 | 161 | .unwrap() |
| 165 | 162 | .invidious_instance |
| 166 | 163 | .clone(), |
| 167 | 164 | )), |
| 168 | Self::RustyPipe => Box::new(RustyPipeWrapper::default()), | |
| 165 | #[cfg(feature = "rustypipe")] | |
| 166 | Self::RustyPipe => Box::new(crate::global::structs::RustyPipeWrapper::default()), | |
| 169 | 167 | } |
| 170 | 168 | } |
| 171 | 169 | } |
| @@ -173,7 +171,9 @@ impl SearchProvider { | ||
| 173 | 171 | impl SearchProvider { |
| 174 | 172 | pub fn as_str(&self) -> &str { |
| 175 | 173 | match self { |
| 174 | #[cfg(feature = "invidious")] | |
| 176 | 175 | Self::Invidious => "Invidious", |
| 176 | #[cfg(feature = "rustypipe")] | |
| 177 | 177 | Self::RustyPipe => "RustyPipe", |
| 178 | 178 | } |
| 179 | 179 | } |
| @@ -232,10 +232,21 @@ const fn provider_default() -> Provider { | ||
| 232 | 232 | Provider::YouTube |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | #[cfg(not(any(feature = "rustypipe", feature = "invidious")))] | |
| 236 | compile_error!( | |
| 237 | "You must include a search provider in your feature list, they are `rustypipe` and `invidious`" | |
| 238 | ); | |
| 239 | ||
| 240 | #[cfg(feature = "rustypipe")] | |
| 235 | 241 | const fn search_provider_default() -> SearchProvider { |
| 236 | 242 | SearchProvider::RustyPipe |
| 237 | 243 | } |
| 238 | 244 | |
| 245 | #[cfg(all(feature = "invidious", not(feature = "rustypipe")))] | |
| 246 | const fn search_provider_default() -> SearchProvider { | |
| 247 | SearchProvider::Invidious | |
| 248 | } | |
| 249 | ||
| 239 | 250 | const fn search_history_default() -> usize { |
| 240 | 251 | 75 |
| 241 | 252 | } |
src/global/functions/download_all_images.rs +7 −1
| @@ -61,8 +61,14 @@ pub fn download_all_images(downloads: Vec<Option<DownloadRequest>>) { | ||
| 61 | 61 | }) |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | fn httpreq_get(url: &str) -> Result<Vec<u8>, http_req::error::Error> { | |
| 65 | let mut buffer = Vec::new(); | |
| 66 | http_req::request::get(url, &mut buffer)?; | |
| 67 | Ok(buffer) | |
| 68 | } | |
| 69 | ||
| 64 | 70 | fn download_single(url: &str, path: PathBuf) -> Result<(), Box<dyn Error>> { |
| 65 | let res = invidious::functions::httpreq_get(url)?; | |
| 71 | let res = httpreq_get(url)?; | |
| 66 | 72 | let mut file = fs::File::create(path)?; |
| 67 | 73 | let mut content = Cursor::new(res); |
| 68 | 74 | std::io::copy(&mut content, &mut file)?; |
src/global/structs/mod.rs +2
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | //! enums and structs |
| 2 | 2 | mod errors; |
| 3 | 3 | mod history; |
| 4 | #[cfg(feature = "invidious")] | |
| 4 | 5 | mod invidiousclient; |
| 5 | 6 | mod item; |
| 6 | 7 | mod keyaction; |
| @@ -17,6 +18,7 @@ mod tasks; | ||
| 17 | 18 | |
| 18 | 19 | pub use errors::*; |
| 19 | 20 | pub use history::*; |
| 21 | #[cfg(feature = "invidious")] | |
| 20 | 22 | pub use invidiousclient::*; |
| 21 | 23 | pub use item::*; |
| 22 | 24 | pub use keyaction::*; |