Skip to content

Commit

Permalink
refactor: move videos by season logic to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Jan 27, 2025
1 parent 0b2e5c2 commit 59da762
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
14 changes: 1 addition & 13 deletions src/models/meta_details.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{borrow::Cow, marker::PhantomData};

use itertools::Itertools;
use serde::{Deserialize, Serialize};

use stremio_watched_bitfield::WatchedBitField;
Expand Down Expand Up @@ -144,18 +143,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for MetaDetails {
.find(|meta_item| matches!(&meta_item.content, Some(Loadable::Ready(_))))
.and_then(|meta_item| meta_item.content.as_ref())
.and_then(|meta_item| meta_item.ready())
.map(|meta_item| {
meta_item
.videos
.iter()
.filter(|video| {
video
.series_info
.as_ref()
.is_some_and(|series_info| series_info.season == *season)
})
.collect_vec()
});
.map(|meta_item| meta_item.videos_by_season(*season));

match videos {
Some(videos) => {
Expand Down
12 changes: 1 addition & 11 deletions src/models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.as_ref()
.and_then(|meta_item| meta_item.content.as_ref())
.and_then(|meta_item| meta_item.ready())
.map(|meta_item| {
meta_item
.videos
.iter()
.filter(|video| {
video.series_info.as_ref().is_some_and(|series_info| {
series_info.season == *season
})
})
.collect_vec()
});
.map(|meta_item| meta_item.videos_by_season(*season));

match videos {
Some(videos) => {
Expand Down
13 changes: 13 additions & 0 deletions src/types/resource/meta_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ impl MetaItem {
Either::Right(self.videos.iter().rev())
}
}

/// Returns a vector of videos for a given season
pub fn videos_by_season(&self, season: u32) -> Vec<&Video> {
self.videos
.iter()
.filter(|video| {
video
.series_info
.as_ref()
.is_some_and(|series_info| series_info.season == season)
})
.collect_vec()
}
}

#[derive(Default, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit 59da762

Please sign in to comment.