Commit 5a483c7846
Unsigned
Layout: unified · split
Cargo.lock +28 −1
| @@ -986,6 +986,18 @@ dependencies = [ | |||
| 986 | "unicase", | 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 | [[package]] | 1001 | [[package]] |
| 990 | name = "httparse" | 1002 | name = "httparse" |
| 991 | version = "1.10.1" | 1003 | version = "1.10.1" |
| @@ -1272,7 +1284,7 @@ version = "0.7.8" | |||
| 1272 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1284 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1273 | checksum = "fa2cff01a915c4780785828f6bec4ad5f8d03f34307d4183ca210830a8a6d88d" | 1285 | checksum = "fa2cff01a915c4780785828f6bec4ad5f8d03f34307d4183ca210830a8a6d88d" |
| 1274 | dependencies = [ | 1286 | dependencies = [ |
| 1275 | "http_req", | 1287 | "http_req 0.12.0", |
| 1276 | "serde", | 1288 | "serde", |
| 1277 | "serde_json", | 1289 | "serde_json", |
| 1278 | ] | 1290 | ] |
| @@ -3470,6 +3482,7 @@ dependencies = [ | |||
| 3470 | "dyn-clone", | 3482 | "dyn-clone", |
| 3471 | "futures", | 3483 | "futures", |
| 3472 | "home", | 3484 | "home", |
| 3485 | "http_req 0.14.1", | ||
| 3473 | "invidious", | 3486 | "invidious", |
| 3474 | "libmpv-sirno", | 3487 | "libmpv-sirno", |
| 3475 | "ratatui", | 3488 | "ratatui", |
| @@ -3531,6 +3544,20 @@ name = "zeroize" | |||
| 3531 | version = "1.8.1" | 3544 | version = "1.8.1" |
| 3532 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3545 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3533 | checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" | 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 | [[package]] | 3562 | [[package]] |
| 3536 | name = "zerotrie" | 3563 | name = "zerotrie" |
Cargo.toml +5 −2
| @@ -16,11 +16,13 @@ exclude = ["/docs", "/LICENSE", "/threadcounter.sh", "/PKGBUILD"] | |||
| 16 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 16 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
| 17 | 17 | ||
| 18 | [features] | 18 | [features] |
| 19 | default = ["sixel", "halfblock", "clipboard", "mpv"] | 19 | default = ["sixel", "halfblock", "clipboard", "mpv", "rustypipe"] |
| 20 | sixel = ["viuer/sixel"] | 20 | sixel = ["viuer/sixel"] |
| 21 | halfblock = ["viuer"] | 21 | halfblock = ["viuer"] |
| 22 | clipboard = ["dep:clipboard"] | 22 | clipboard = ["dep:clipboard"] |
| 23 | mpv = ["dep:libmpv-sirno"] | 23 | mpv = ["dep:libmpv-sirno"] |
| 24 | invidious = ["invidious/httpreq_sync"] | ||
| 25 | rustypipe = [] | ||
| 24 | 26 | ||
| 25 | [dependencies] | 27 | [dependencies] |
| 26 | serde = {version = "1.0", default-features = false, features = ["derive"]} | 28 | serde = {version = "1.0", default-features = false, features = ["derive"]} |
| @@ -30,7 +32,7 @@ home = "0.5" | |||
| 30 | chrono = {version = "0.4", default-features = false, features = ["clock"]} | 32 | chrono = {version = "0.4", default-features = false, features = ["clock"]} |
| 31 | typemap = {version = "0.3", default-features = false} | 33 | typemap = {version = "0.3", default-features = false} |
| 32 | tui-additions = {version = "0.4", default-features = false, features = ["framework", "widgets"]} | 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 | serde_yaml_ng = {version = "0.10", default-features = false} | 36 | serde_yaml_ng = {version = "0.10", default-features = false} |
| 35 | dyn-clone = {version = "1.0", default-features = false} | 37 | dyn-clone = {version = "1.0", default-features = false} |
| 36 | serde_json = {version = "1.0", default-features = false} | 38 | serde_json = {version = "1.0", default-features = false} |
| @@ -43,6 +45,7 @@ libmpv-sirno = { version = "2.0.2-fork.1", optional = true } | |||
| 43 | rustypipe = "0.11" | 45 | rustypipe = "0.11" |
| 44 | futures = { version = "0.3", features = [ "executor" ] } | 46 | futures = { version = "0.3", features = [ "executor" ] } |
| 45 | tokio = { version = "1", features = [ "rt" ]} | 47 | tokio = { version = "1", features = [ "rt" ]} |
| 48 | http_req = "0.14.1" | ||
| 46 | 49 | ||
| 47 | # libmpv = { path = "libmpv-rs", optional = true, version = "2" } | 50 | # libmpv = { path = "libmpv-rs", optional = true, version = "2" } |
| 48 | # tui-additions = {path = "../Rust/tui-additions", default-features = false, features = ["framework", "widgets"]} | 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::{ | 1 | use crate::global::traits::{ConfigTrait, SearchProviderTrait}; |
| 2 | global::{ | ||
| 3 | structs::{InvidiousClient, RustyPipeWrapper}, | ||
| 4 | traits::{ConfigTrait, SearchProviderTrait}, | ||
| 5 | }, | ||
| 6 | MAIN_CONFIG, | ||
| 7 | }; | ||
| 8 | use serde::{Deserialize, Serialize}; | 2 | use serde::{Deserialize, Serialize}; |
| 9 | use std::collections::HashMap; | 3 | use std::collections::HashMap; |
| 10 | use typemap::Key; | 4 | use typemap::Key; |
| @@ -152,20 +146,24 @@ pub enum Provider { | |||
| 152 | 146 | ||
| 153 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] | 147 | #[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] |
| 154 | pub enum SearchProvider { | 148 | pub enum SearchProvider { |
| 149 | #[cfg(feature = "invidious")] | ||
| 155 | Invidious, | 150 | Invidious, |
| 151 | #[cfg(feature = "rustypipe")] | ||
| 156 | RustyPipe, | 152 | RustyPipe, |
| 157 | } | 153 | } |
| 158 | 154 | ||
| 159 | impl SearchProvider { | 155 | impl SearchProvider { |
| 160 | pub fn create(&self) -> Box<dyn SearchProviderTrait> { | 156 | pub fn create(&self) -> Box<dyn SearchProviderTrait> { |
| 161 | match self { | 157 | match self { |
| 162 | Self::Invidious => Box::new(InvidiousClient::new( | 158 | #[cfg(feature = "invidious")] |
| 163 | unsafe { MAIN_CONFIG.get() } | 159 | Self::Invidious => Box::new(crate::global::structs::InvidiousClient::new( |
| 160 | unsafe { crate::MAIN_CONFIG.get() } | ||
| 164 | .unwrap() | 161 | .unwrap() |
| 165 | .invidious_instance | 162 | .invidious_instance |
| 166 | .clone(), | 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 | impl SearchProvider { | 171 | impl SearchProvider { |
| 174 | pub fn as_str(&self) -> &str { | 172 | pub fn as_str(&self) -> &str { |
| 175 | match self { | 173 | match self { |
| 174 | #[cfg(feature = "invidious")] | ||
| 176 | Self::Invidious => "Invidious", | 175 | Self::Invidious => "Invidious", |
| 176 | #[cfg(feature = "rustypipe")] | ||
| 177 | Self::RustyPipe => "RustyPipe", | 177 | Self::RustyPipe => "RustyPipe", |
| 178 | } | 178 | } |
| 179 | } | 179 | } |
| @@ -232,10 +232,21 @@ const fn provider_default() -> Provider { | |||
| 232 | Provider::YouTube | 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 | const fn search_provider_default() -> SearchProvider { | 241 | const fn search_provider_default() -> SearchProvider { |
| 236 | SearchProvider::RustyPipe | 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 | const fn search_history_default() -> usize { | 250 | const fn search_history_default() -> usize { |
| 240 | 75 | 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 | fn download_single(url: &str, path: PathBuf) -> Result<(), Box<dyn Error>> { | 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 | let mut file = fs::File::create(path)?; | 72 | let mut file = fs::File::create(path)?; |
| 67 | let mut content = Cursor::new(res); | 73 | let mut content = Cursor::new(res); |
| 68 | std::io::copy(&mut content, &mut file)?; | 74 | std::io::copy(&mut content, &mut file)?; |
src/global/structs/mod.rs +2
| @@ -1,6 +1,7 @@ | |||
| 1 | //! enums and structs | 1 | //! enums and structs |
| 2 | mod errors; | 2 | mod errors; |
| 3 | mod history; | 3 | mod history; |
| 4 | #[cfg(feature = "invidious")] | ||
| 4 | mod invidiousclient; | 5 | mod invidiousclient; |
| 5 | mod item; | 6 | mod item; |
| 6 | mod keyaction; | 7 | mod keyaction; |
| @@ -17,6 +18,7 @@ mod tasks; | |||
| 17 | 18 | ||
| 18 | pub use errors::*; | 19 | pub use errors::*; |
| 19 | pub use history::*; | 20 | pub use history::*; |
| 21 | #[cfg(feature = "invidious")] | ||
| 20 | pub use invidiousclient::*; | 22 | pub use invidiousclient::*; |
| 21 | pub use item::*; | 23 | pub use item::*; |
| 22 | pub use keyaction::*; | 24 | pub use keyaction::*; |