Skip to content

Commit

Permalink
handle retrieving StreamItem for metas without videos
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Nov 10, 2023
1 parent 26593fe commit 01f418e
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/types/streams/streams_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ impl StreamsBucket {
video_id: &String,
meta_item: &MetaItem,
) -> Option<&StreamsItem> {
meta_item
.videos
.iter()
.position(|video| video.id == *video_id)
.and_then(|max_index| {
meta_item.videos[max_index.saturating_sub(30)..=max_index]
.iter()
.rev()
.find_map(|video| {
self.items.get(&StreamsItemKey {
meta_id: meta_item.preview.id.to_string(),
video_id: video.id.to_owned(),
match meta_item.videos.len() {
0 => self.items.get(&StreamsItemKey {
meta_id: meta_item.preview.id.to_string(),
video_id: video_id.to_owned(),
}),
_ => meta_item
.videos
.iter()
.position(|video| video.id == *video_id)
.and_then(|max_index| {
meta_item.videos[max_index.saturating_sub(30)..=max_index]
.iter()
.rev()
.find_map(|video| {
self.items.get(&StreamsItemKey {
meta_id: meta_item.preview.id.to_string(),
video_id: video.id.to_owned(),
})
})
})
})
}),
}
}
}

0 comments on commit 01f418e

Please sign in to comment.