Commit 57e6337180

57e633718089527b1f7a720af055c43c9d221481

parent: c07a23d21c

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-05-08 16:29 UTC

added subscribtions struct

Layout: unified · split

Cargo.lock +1
@@ -2057,6 +2057,7 @@ dependencies = [
2057 "futures", 2057 "futures",
2058 "home", 2058 "home",
2059 "invidious", 2059 "invidious",
2060 "rayon",
2060 "reqwest", 2061 "reqwest",
2061 "serde", 2062 "serde",
2062 "serde_json", 2063 "serde_json",
docs/src/changelogs.md +1
@@ -5,6 +5,7 @@
5### Added 5### Added
6 6
7- Options for config loading. (`write_config` in `main.yml`) 7- Options for config loading. (`write_config` in `main.yml`)
8- Parrallel/blocking commands `parrun`/`run`
8 9
9### Fixed 10### Fixed
10 11
docs/src/contributors.md +4
@@ -8,6 +8,10 @@ Creator and main developer of YouTube TUI.
8 8
9Maintainer of the <a href="https://aur.archlinux.org/packages/youtube-tui" target=_blank>`youtube-tui`</a> package on AUR. 9Maintainer of the <a href="https://aur.archlinux.org/packages/youtube-tui" target=_blank>`youtube-tui`</a> package on AUR.
10 10
11## <a href="https://github.com/Ruixi-rebirth" target=_blank>Ruixi-rebirth</a>
12
13Maintainer of the <a href="https://search.nixos.org/packages?channel=unstable&query=youtube-tui" >`youtube-tui`</a> on the NixOS repository.
14
11## <a href="https://github.com/zaedus" target=_blank>Zaedus</a> 15## <a href="https://github.com/zaedus" target=_blank>Zaedus</a>
12 16
13Maintainer of the <a href="https://aur.archlinux.org/packages/youtube-tui-full-bin" target=_blank>`youtube-tui-full-bin`</a>, <a href="https://aur.archlinux.org/packages/youtube-tui-nodefaults-bin" target=_blank>`youtube-tui-nodefaults-bin`</a> and <a href="https://aur.archlinux.org/packages/youtube-tui-git" target=_blank>`youtube-tui-git`</a> package on AUR. 17Maintainer of the <a href="https://aur.archlinux.org/packages/youtube-tui-full-bin" target=_blank>`youtube-tui-full-bin`</a>, <a href="https://aur.archlinux.org/packages/youtube-tui-nodefaults-bin" target=_blank>`youtube-tui-nodefaults-bin`</a> and <a href="https://aur.archlinux.org/packages/youtube-tui-git" target=_blank>`youtube-tui-git`</a> package on AUR.
docs/src/installation.md −2
@@ -1,7 +1,5 @@
1# Installation 1# Installation
2 2
3> Currently YouTube TUI requires `libxcb`, which should come preinstalled in most Linux system.
4
5The YouTube TUI is *not* tested for Windows. 3The YouTube TUI is *not* tested for Windows.
6 4
7## Install from Crates.io (recommended) 5## Install from Crates.io (recommended)
src/config/commands.rs +6 −6
@@ -141,15 +141,15 @@ fn saved_video_default() -> Vec<HashMap<String, String>> {
141 )]), 141 )]),
142 HashMap::from([( 142 HashMap::from([(
143 String::from("[Offline] Play saved file"), 143 String::from("[Offline] Play saved file"),
144 String::from("parrun find ${save-path} | grep ${id} | ${video-player} --playlist=- --force-window"), 144 String::from("parrun ${video-player} ${save-path}*${id}* --force-window"),
145 )]), 145 )]),
146 HashMap::from([( 146 HashMap::from([(
147 String::from("[Offline] Play saved file (audio)"), 147 String::from("[Offline] Play saved file (audio)"),
148 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video'"), 148 String::from("parrun ${terminal-emulator} ${video-player} ${save-path}*${id}* --no-video"),
149 )]), 149 )]),
150 HashMap::from([( 150 HashMap::from([(
151 String::from("[Offline] Play saved file (audio loop)"), 151 String::from("[Offline] Play saved file (audio loop)"),
152 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video --loop'"), 152 String::from("parrun ${terminal-emulator} ${video-player} ${save-path}*${id}* --no-video --loop"),
153 )]), 153 )]),
154 HashMap::from([( 154 HashMap::from([(
155 String::from("View channel"), 155 String::from("View channel"),
@@ -233,15 +233,15 @@ fn saved_playlist_default() -> Vec<HashMap<String, String>> {
233 )]), 233 )]),
234 HashMap::from([( 234 HashMap::from([(
235 String::from("[Offline] Play all (videos)"), 235 String::from("[Offline] Play all (videos)"),
236 String::from("parrun find ${save-path} | grep ${id} | ${video-player} --playlist=- --force-window"), 236 String::from("parrun ${terminal-emulator} bash -c '${video-player} ${save-path}*${id}*/* --force-window'"),
237 )]), 237 )]),
238 HashMap::from([( 238 HashMap::from([(
239 String::from("[Offline] Play all (audio)"), 239 String::from("[Offline] Play all (audio)"),
240 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video'"), 240 String::from("parrun ${terminal-emulator} bash -c '${video-player} ${save-path}*${id}*/* --no-video'"),
241 )]), 241 )]),
242 HashMap::from([( 242 HashMap::from([(
243 String::from("[Offline] Shuffle play all (audio loop)"), 243 String::from("[Offline] Shuffle play all (audio loop)"),
244 String::from("parrun ${terminal-emulator} bash -c 'find ${save-path} | grep ${id} | ${video-player} --playlist=- --no-video --loop-playlist=inf --shuffle'"), 244 String::from("parrun ${terminal-emulator} bash -c '${video-player} ${save-path}*${id}*/* --no-video --loop-playlist=inf --shuffle'"),
245 )]), 245 )]),
246 HashMap::from([( 246 HashMap::from([(
247 String::from("View channel"), 247 String::from("View channel"),
src/global/structs/item.rs +52
@@ -37,6 +37,8 @@ pub struct MiniVideoItem {
37 pub description: Option<String>, 37 pub description: Option<String>,
38} 38}
39 39
40unsafe impl Send for MiniVideoItem {}
41
40/// stores information of a previewed playlist 42/// stores information of a previewed playlist
41#[derive(Clone, Serialize, Deserialize)] 43#[derive(Clone, Serialize, Deserialize)]
42pub struct MiniPlaylistItem { 44pub struct MiniPlaylistItem {
@@ -196,6 +198,56 @@ impl Item {
196 } 198 }
197} 199}
198 200
201
202impl Item {
203 /// stript self into a FullVideoItem
204 pub fn into_fullvideo(self) -> Result<FullVideoItem, Errors> {
205 match self {
206 Self::FullVideo(fullvideo) => Ok(fullvideo),
207 _ => Err(Errors::StrError("not a full video")),
208 }
209 }
210
211 /// stript self into a MiniVideoItem
212 pub fn into_minivideo(self) -> Result<MiniVideoItem, Errors> {
213 match self {
214 Self::MiniVideo(minivideo) => Ok(minivideo),
215 _ => Err(Errors::StrError("not a mini video")),
216 }
217 }
218
219 /// stript self into a MiniPlaylistItem
220 pub fn into_miniplaylist(self) -> Result<MiniPlaylistItem, Errors> {
221 match self {
222 Self::MiniPlaylist(miniplaylist) => Ok(miniplaylist),
223 _ => Err(Errors::StrError("not a mini playlist")),
224 }
225 }
226
227 /// stript self into a FullPlaylistItem
228 pub fn into_fullplaylist(self) -> Result<FullPlaylistItem, Errors> {
229 match self {
230 Self::FullPlaylist(fullplaylist) => Ok(fullplaylist),
231 _ => Err(Errors::StrError("not a full playlist")),
232 }
233 }
234
235 /// stript self into a MiniChannelItem
236 pub fn into_minichannel(self) -> Result<MiniChannelItem, Errors> {
237 match self {
238 Self::MiniChannel(minichannel) => Ok(minichannel),
239 _ => Err(Errors::StrError("not a mini channel")),
240 }
241 }
242
243 pub fn into_fullchannel(self) -> Result<FullChannelItem, Errors> {
244 match self {
245 Self::FullChannel(fullchannel) => Ok(fullchannel),
246 _ => Err(Errors::StrError("not a full channel")),
247 }
248 }
249}
250
199impl Item { 251impl Item {
200 /// returns the file save path for thumbnails (which is by their id) 252 /// returns the file save path for thumbnails (which is by their id)
201 /// returns `invalid` if the item does not have a thumbnail 253 /// returns `invalid` if the item does not have a thumbnail
src/global/structs/mod.rs +2
@@ -10,6 +10,7 @@ mod state_env;
10mod status; 10mod status;
11mod tasks; 11mod tasks;
12mod watchhistory; 12mod watchhistory;
13mod subscriptions;
13 14
14pub use errors::*; 15pub use errors::*;
15pub use invidiousclient::*; 16pub use invidiousclient::*;
@@ -22,3 +23,4 @@ pub use state_env::*;
22pub use status::*; 23pub use status::*;
23pub use tasks::*; 24pub use tasks::*;
24pub use watchhistory::*; 25pub use watchhistory::*;
26pub use subscriptions::*;
src/global/structs/subscriptions.rs added +49
@@ -0,0 +1,49 @@
1use std::{collections::HashMap, error::Error, sync::mpsc, thread};
2use serde::*;
3// use rayon::prelude::*;
4use crate::config::MainConfig;
5use super::{MiniVideoItem, InvidiousClient, Item};
6
7#[derive(Serialize, Deserialize)]
8/// id, videos
9pub struct Subscriptions(pub HashMap<String, Vec<MiniVideoItem>>);
10
11impl Subscriptions {
12 /// Res<(success, failed)>
13 pub fn sync(&mut self, client: &InvidiousClient, mainconfig: &MainConfig) -> (u32, u32) {
14 let mut failed: u32 = 0;
15 let mut success: u32 = 0;
16
17 let (tx, rx) = mpsc::channel();
18 let image_index = mainconfig.image_index;
19
20 self.0.keys().for_each(|k| {
21 let tx = tx.clone();
22 let client = client.clone();
23 let k = k.clone();
24 thread::spawn(move || {
25 let res = sync_one(&k, &client, image_index).ok();
26 tx.send((k, res))
27 });
28 });
29
30 for res in rx {
31 match res {
32 (id, Some(videos)) => {
33 self.0.insert(id, videos);
34 success += 1;
35 },
36 (id, None) => {
37 self.0.get_mut(&id).unwrap().clear();
38 failed += 1;
39 }
40 }
41 }
42
43 (success, failed)
44 }
45}
46
47fn sync_one(id: &str, client: &InvidiousClient, image_index: usize) -> Result<Vec<MiniVideoItem>, Box<dyn Error>> {
48 Ok(client.0.channel_videos(id, None)?.videos.into_iter().map(|video| Item::from_channel_video(video, image_index).into_minivideo().unwrap()).collect())
49}