Skip to content

Commit da0efef

Browse files
committed
feat: add a command for fetching all videos of the channel
1 parent 3fb7270 commit da0efef

12 files changed

Lines changed: 27 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Add a command to load all videos for channels.
10+
811
### Changed
912
- Don't return immediately if there are new recent videos when getting more videos.
1013

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ fg = "Green"
228228
"r" = "refresh_channel" # Refresh videos of the selected channel
229229
"R" = "refresh_channels" # Refresh videos of every channel
230230
"J" = "load_more_videos" # Load more videos for the selected channel
231+
"ctrl-j" = "load_all_videos" # Load all videos for the selected channel
231232
"F" = "refresh_failed_channels" # Refresh videos of channels which their latest refresh was a failure
232233
"o" = "open_in_youtube" # Open channel or video Youtube page in browser
233234
"O" = "open_in_invidious" # Open channel or video Invidious page in browser

src/api/invidious.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ impl Api for Instance {
138138
channel_id: &str,
139139
tab: ChannelTab,
140140
present_videos: HashSet<String>,
141+
get_all: bool,
141142
) -> Result<ChannelFeed> {
142143
let mut feed = ChannelFeed::new(channel_id);
143144
let videos = self.get_more_videos_helper(channel_id, tab).await?;
@@ -154,15 +155,15 @@ impl Api for Instance {
154155
.all(|video| present_videos.contains(&video.video_id))
155156
};
156157

157-
let new = new_video_present(feed.get_videos(tab));
158+
let mut new = new_video_present(feed.get_videos(tab));
158159

159160
while self.continuation.is_some()
160161
&& let Ok(videos) = self.get_more_videos_helper(channel_id, tab).await
161162
{
162-
let new = new_video_present(&videos);
163+
new = new || new_video_present(&videos);
163164
feed.extend_videos(videos, tab);
164165

165-
if new {
166+
if !get_all && new {
166167
return Ok(feed);
167168
}
168169
}

src/api/local.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ impl Api for Local {
510510
channel_id: &str,
511511
tab: ChannelTab,
512512
present_videos: HashSet<String>,
513+
get_all: bool,
513514
) -> Result<ChannelFeed> {
514515
let mut feed = ChannelFeed::new(channel_id);
515516

@@ -525,13 +526,13 @@ impl Api for Local {
525526
.all(|video| present_videos.contains(&video.video_id))
526527
};
527528

528-
let new = new_video_present(feed.get_videos(tab));
529+
let mut new = new_video_present(feed.get_videos(tab));
529530

530531
while let Ok(videos) = self.get_continuation(tab).await {
531-
let new = new_video_present(&videos);
532+
new = new || new_video_present(&videos);
532533
feed.extend_videos(videos, tab);
533534

534-
if new {
535+
if !get_all && new {
535536
return Ok(feed);
536537
}
537538
}

src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ pub trait Api: Sync + Send + DynClone {
469469
channel_id: &str,
470470
tab: ChannelTab,
471471
present_videos: HashSet<String>,
472+
get_all: bool,
472473
) -> Result<ChannelFeed>;
473474
async fn get_video_formats(&self, video_id: &str) -> Result<VideoInfo>;
474475
async fn get_caption_paths(&self, formats: &Formats) -> Vec<String>;

src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl App {
198198
}
199199
}
200200

201-
pub fn get_more_videos(&mut self) {
201+
pub fn get_more_videos(&mut self, get_all: bool) {
202202
if let Some(current_channel) = self.channels.get_selected()
203203
&& let Some(tab) = self.tabs.get_selected()
204204
{
@@ -225,6 +225,7 @@ impl App {
225225
channel_id,
226226
tab.variant,
227227
present_videos,
228+
get_all,
228229
));
229230
}
230231
}

src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ impl Client {
105105
let instance = self.instance();
106106
tokio::spawn(async move { refresh_channels(instance, ids).await });
107107
}
108-
IoEvent::LoadMoreVideos(id, tab, present_videos) => {
108+
IoEvent::LoadMoreVideos(id, tab, present_videos, load_all) => {
109109
let instance = self.instance();
110110
tokio::spawn(async move {
111-
get_more_videos(instance, &id, tab, present_videos).await
111+
get_more_videos(instance, &id, tab, present_videos, load_all).await
112112
});
113113
}
114114
IoEvent::FetchFormats(title, video_id, play_selected) => {
@@ -339,8 +339,9 @@ async fn get_more_videos(
339339
id: &str,
340340
tab: ChannelTab,
341341
present: HashSet<String>,
342+
get_all: bool,
342343
) -> Result<()> {
343-
match instance.get_more_videos(id, tab, present).await {
344+
match instance.get_more_videos(id, tab, present, get_all).await {
344345
Ok(feed) => {
345346
if feed.get_videos(tab).is_empty() {
346347
emit_msg!(warning, "There are no videos to load");

src/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum Command {
2424
RefreshChannels,
2525
RefreshFailedChannels,
2626
LoadMoreVideos,
27+
LoadAllVideos,
2728
OpenInInvidious,
2829
OpenInYoutube,
2930
PlayFromFormats,
@@ -64,6 +65,7 @@ impl TryFrom<&str> for Command {
6465
"refresh_channels" => Command::RefreshChannels,
6566
"refresh_failed_channels" => Command::RefreshFailedChannels,
6667
"load_more_videos" => Command::LoadMoreVideos,
68+
"load_all_videos" => Command::LoadAllVideos,
6769
"open_in_invidious" => Command::OpenInInvidious,
6870
"open_in_youtube" => Command::OpenInYoutube,
6971
"play_from_formats" => Command::PlayFromFormats,

src/config/keys.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl Default for KeyBindings {
114114
insert_binding!(general, "R", Command::RefreshChannels);
115115
insert_binding!(general, "F", Command::RefreshFailedChannels);
116116
insert_binding!(general, "J", Command::LoadMoreVideos);
117+
insert_binding!(general, "ctrl-j", Command::LoadAllVideos);
117118
insert_binding!(general, "o", Command::OpenInYoutube);
118119
insert_binding!(general, "O", Command::OpenInInvidious);
119120
insert_binding!(general, "p", Command::PlayFromFormats);

src/help.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::KEY_BINDINGS;
22
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
33
use std::ops::{Deref, DerefMut};
44

5-
const DESCRIPTIONS_LEN: usize = 33;
5+
const DESCRIPTIONS_LEN: usize = 34;
66
const DESCRIPTIONS: [&str; DESCRIPTIONS_LEN] = [
77
"Switch to subscriptions mode",
88
"Switch to latest videos mode",
@@ -28,6 +28,7 @@ const DESCRIPTIONS: [&str; DESCRIPTIONS_LEN] = [
2828
"Refresh videos of every channel",
2929
"Refresh videos of channels which their latest refresh was a failure",
3030
"Load more videos",
31+
"Load all videos",
3132
"Open channel or video Invidious page in browser",
3233
"Open channel or video Youtube page in browser",
3334
"Play video in video player using stream formats",

0 commit comments

Comments
 (0)