Commit 5a483c7846

5a483c7846e01bf9862a7d62effa6b96c9ccf8dd

parent: bd0ed63038

Unsigned

siriusmart <siriusmart@tuta.io> · 2025-08-12 11:09 UTC

#97 invidious is now optional

Layout: unified · split

Cargo.lock +28 −1
@@ -986,6 +986,18 @@ dependencies = [
986 "unicase", 986 "unicase",
987] 987]
988 988
989[[package]]
990name = "http_req"
991version = "0.14.1"
992source = "registry+https://github.com/rust-lang/crates.io-index"
993checksum = "bec91a96dfaaf08e42e32408d01988e2578c78e8017fd9484a6b213d0e802ee6"
994dependencies = [
995 "base64",
996 "native-tls",
997 "unicase",
998 "zeroize",
999]
1000
989[[package]] 1001[[package]]
990name = "httparse" 1002name = "httparse"
991version = "1.10.1" 1003version = "1.10.1"
@@ -1272,7 +1284,7 @@ version = "0.7.8"
1272source = "registry+https://github.com/rust-lang/crates.io-index" 1284source = "registry+https://github.com/rust-lang/crates.io-index"
1273checksum = "fa2cff01a915c4780785828f6bec4ad5f8d03f34307d4183ca210830a8a6d88d" 1285checksum = "fa2cff01a915c4780785828f6bec4ad5f8d03f34307d4183ca210830a8a6d88d"
1274dependencies = [ 1286dependencies = [
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"
3531version = "1.8.1" 3544version = "1.8.1"
3532source = "registry+https://github.com/rust-lang/crates.io-index" 3545source = "registry+https://github.com/rust-lang/crates.io-index"
3533checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" 3546checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
3547dependencies = [
3548 "zeroize_derive",
3549]
3550
3551[[package]]
3552name = "zeroize_derive"
3553version = "1.4.2"
3554source = "registry+https://github.com/rust-lang/crates.io-index"
3555checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
3556dependencies = [
3557 "proc-macro2",
3558 "quote",
3559 "syn",
3560]
3534 3561
3535[[package]] 3562[[package]]
3536name = "zerotrie" 3563name = "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]
19default = ["sixel", "halfblock", "clipboard", "mpv"] 19default = ["sixel", "halfblock", "clipboard", "mpv", "rustypipe"]
20sixel = ["viuer/sixel"] 20sixel = ["viuer/sixel"]
21halfblock = ["viuer"] 21halfblock = ["viuer"]
22clipboard = ["dep:clipboard"] 22clipboard = ["dep:clipboard"]
23mpv = ["dep:libmpv-sirno"] 23mpv = ["dep:libmpv-sirno"]
24invidious = ["invidious/httpreq_sync"]
25rustypipe = []
24 26
25[dependencies] 27[dependencies]
26serde = {version = "1.0", default-features = false, features = ["derive"]} 28serde = {version = "1.0", default-features = false, features = ["derive"]}
@@ -30,7 +32,7 @@ home = "0.5"
30chrono = {version = "0.4", default-features = false, features = ["clock"]} 32chrono = {version = "0.4", default-features = false, features = ["clock"]}
31typemap = {version = "0.3", default-features = false} 33typemap = {version = "0.3", default-features = false}
32tui-additions = {version = "0.4", default-features = false, features = ["framework", "widgets"]} 34tui-additions = {version = "0.4", default-features = false, features = ["framework", "widgets"]}
33invidious = {version = "0.7"} 35invidious = { version = "0.7", default-features = false }
34serde_yaml_ng = {version = "0.10", default-features = false} 36serde_yaml_ng = {version = "0.10", default-features = false}
35dyn-clone = {version = "1.0", default-features = false} 37dyn-clone = {version = "1.0", default-features = false}
36serde_json = {version = "1.0", default-features = false} 38serde_json = {version = "1.0", default-features = false}
@@ -43,6 +45,7 @@ libmpv-sirno = { version = "2.0.2-fork.1", optional = true }
43rustypipe = "0.11" 45rustypipe = "0.11"
44futures = { version = "0.3", features = [ "executor" ] } 46futures = { version = "0.3", features = [ "executor" ] }
45tokio = { version = "1", features = [ "rt" ]} 47tokio = { version = "1", features = [ "rt" ]}
48http_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 @@
1use crate::{ 1use crate::global::traits::{ConfigTrait, SearchProviderTrait};
2 global::{
3 structs::{InvidiousClient, RustyPipeWrapper},
4 traits::{ConfigTrait, SearchProviderTrait},
5 },
6 MAIN_CONFIG,
7};
8use serde::{Deserialize, Serialize}; 2use serde::{Deserialize, Serialize};
9use std::collections::HashMap; 3use std::collections::HashMap;
10use typemap::Key; 4use 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)]
154pub enum SearchProvider { 148pub enum SearchProvider {
149 #[cfg(feature = "invidious")]
155 Invidious, 150 Invidious,
151 #[cfg(feature = "rustypipe")]
156 RustyPipe, 152 RustyPipe,
157} 153}
158 154
159impl SearchProvider { 155impl 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 {
173impl SearchProvider { 171impl 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")))]
236compile_error!(
237 "You must include a search provider in your feature list, they are `rustypipe` and `invidious`"
238);
239
240#[cfg(feature = "rustypipe")]
235const fn search_provider_default() -> SearchProvider { 241const fn search_provider_default() -> SearchProvider {
236 SearchProvider::RustyPipe 242 SearchProvider::RustyPipe
237} 243}
238 244
245#[cfg(all(feature = "invidious", not(feature = "rustypipe")))]
246const fn search_provider_default() -> SearchProvider {
247 SearchProvider::Invidious
248}
249
239const fn search_history_default() -> usize { 250const 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
64fn 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
64fn download_single(url: &str, path: PathBuf) -> Result<(), Box<dyn Error>> { 70fn 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
2mod errors; 2mod errors;
3mod history; 3mod history;
4#[cfg(feature = "invidious")]
4mod invidiousclient; 5mod invidiousclient;
5mod item; 6mod item;
6mod keyaction; 7mod keyaction;
@@ -17,6 +18,7 @@ mod tasks;
17 18
18pub use errors::*; 19pub use errors::*;
19pub use history::*; 20pub use history::*;
21#[cfg(feature = "invidious")]
20pub use invidiousclient::*; 22pub use invidiousclient::*;
21pub use item::*; 23pub use item::*;
22pub use keyaction::*; 24pub use keyaction::*;