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 = [
986986 "unicase",
987987]
988988
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
9891001[[package]]
9901002name = "httparse"
9911003version = "1.10.1"
@@ -1272,7 +1284,7 @@ version = "0.7.8"
12721284source = "registry+https://github.com/rust-lang/crates.io-index"
12731285checksum = "fa2cff01a915c4780785828f6bec4ad5f8d03f34307d4183ca210830a8a6d88d"
12741286dependencies = [
1275 "http_req",
1287 "http_req 0.12.0",
12761288 "serde",
12771289 "serde_json",
12781290]
@@ -3470,6 +3482,7 @@ dependencies = [
34703482 "dyn-clone",
34713483 "futures",
34723484 "home",
3485 "http_req 0.14.1",
34733486 "invidious",
34743487 "libmpv-sirno",
34753488 "ratatui",
@@ -3531,6 +3544,20 @@ name = "zeroize"
35313544version = "1.8.1"
35323545source = "registry+https://github.com/rust-lang/crates.io-index"
35333546checksum = "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]
35343561
35353562[[package]]
35363563name = "zerotrie"
Cargo.toml +5 −2
@@ -16,11 +16,13 @@ exclude = ["/docs", "/LICENSE", "/threadcounter.sh", "/PKGBUILD"]
1616# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1717
1818[features]
19default = ["sixel", "halfblock", "clipboard", "mpv"]
19default = ["sixel", "halfblock", "clipboard", "mpv", "rustypipe"]
2020sixel = ["viuer/sixel"]
2121halfblock = ["viuer"]
2222clipboard = ["dep:clipboard"]
2323mpv = ["dep:libmpv-sirno"]
24invidious = ["invidious/httpreq_sync"]
25rustypipe = []
2426
2527[dependencies]
2628serde = {version = "1.0", default-features = false, features = ["derive"]}
@@ -30,7 +32,7 @@ home = "0.5"
3032chrono = {version = "0.4", default-features = false, features = ["clock"]}
3133typemap = {version = "0.3", default-features = false}
3234tui-additions = {version = "0.4", default-features = false, features = ["framework", "widgets"]}
33invidious = {version = "0.7"}
35invidious = { version = "0.7", default-features = false }
3436serde_yaml_ng = {version = "0.10", default-features = false}
3537dyn-clone = {version = "1.0", default-features = false}
3638serde_json = {version = "1.0", default-features = false}
@@ -43,6 +45,7 @@ libmpv-sirno = { version = "2.0.2-fork.1", optional = true }
4345rustypipe = "0.11"
4446futures = { version = "0.3", features = [ "executor" ] }
4547tokio = { version = "1", features = [ "rt" ]}
48http_req = "0.14.1"
4649
4750# libmpv = { path = "libmpv-rs", optional = true, version = "2" }
4851# tui-additions = {path = "../Rust/tui-additions", default-features = false, features = ["framework", "widgets"]}
src/config/main.rs +21 −10
@@ -1,10 +1,4 @@
1use crate::{
2 global::{
3 structs::{InvidiousClient, RustyPipeWrapper},
4 traits::{ConfigTrait, SearchProviderTrait},
5 },
6 MAIN_CONFIG,
7};
1use crate::global::traits::{ConfigTrait, SearchProviderTrait};
82use serde::{Deserialize, Serialize};
93use std::collections::HashMap;
104use typemap::Key;
@@ -152,20 +146,24 @@ pub enum Provider {
152146
153147#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
154148pub enum SearchProvider {
149 #[cfg(feature = "invidious")]
155150 Invidious,
151 #[cfg(feature = "rustypipe")]
156152 RustyPipe,
157153}
158154
159155impl SearchProvider {
160156 pub fn create(&self) -> Box<dyn SearchProviderTrait> {
161157 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() }
164161 .unwrap()
165162 .invidious_instance
166163 .clone(),
167164 )),
168 Self::RustyPipe => Box::new(RustyPipeWrapper::default()),
165 #[cfg(feature = "rustypipe")]
166 Self::RustyPipe => Box::new(crate::global::structs::RustyPipeWrapper::default()),
169167 }
170168 }
171169}
@@ -173,7 +171,9 @@ impl SearchProvider {
173171impl SearchProvider {
174172 pub fn as_str(&self) -> &str {
175173 match self {
174 #[cfg(feature = "invidious")]
176175 Self::Invidious => "Invidious",
176 #[cfg(feature = "rustypipe")]
177177 Self::RustyPipe => "RustyPipe",
178178 }
179179 }
@@ -232,10 +232,21 @@ const fn provider_default() -> Provider {
232232 Provider::YouTube
233233}
234234
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")]
235241const fn search_provider_default() -> SearchProvider {
236242 SearchProvider::RustyPipe
237243}
238244
245#[cfg(all(feature = "invidious", not(feature = "rustypipe")))]
246const fn search_provider_default() -> SearchProvider {
247 SearchProvider::Invidious
248}
249
239250const fn search_history_default() -> usize {
240251 75
241252}
src/global/functions/download_all_images.rs +7 −1
@@ -61,8 +61,14 @@ pub fn download_all_images(downloads: Vec<Option<DownloadRequest>>) {
6161 })
6262}
6363
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
6470fn download_single(url: &str, path: PathBuf) -> Result<(), Box<dyn Error>> {
65 let res = invidious::functions::httpreq_get(url)?;
71 let res = httpreq_get(url)?;
6672 let mut file = fs::File::create(path)?;
6773 let mut content = Cursor::new(res);
6874 std::io::copy(&mut content, &mut file)?;
src/global/structs/mod.rs +2
@@ -1,6 +1,7 @@
11//! enums and structs
22mod errors;
33mod history;
4#[cfg(feature = "invidious")]
45mod invidiousclient;
56mod item;
67mod keyaction;
@@ -17,6 +18,7 @@ mod tasks;
1718
1819pub use errors::*;
1920pub use history::*;
21#[cfg(feature = "invidious")]
2022pub use invidiousclient::*;
2123pub use item::*;
2224pub use keyaction::*;