Skip to content

Commit

Permalink
fix: home hubs showing watched items in certain cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Aug 4, 2023
1 parent 3700979 commit 1c4ea8f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
56 changes: 56 additions & 0 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,65 @@ pub fn route() -> Router {
async fn test(req: &mut Request, _depot: &mut Depot, res: &mut Response) {
let params: PlexParams = req.extract().await.unwrap();
let plex_client = PlexClient::from_request(req, params.clone());

// not sure anymore why i have this lol
let content_directory_id_size =
params.clone().content_directory_id.unwrap().len();
if content_directory_id_size > usize::try_from(1).unwrap() {
let upstream_res = plex_client.request(req).await.unwrap();
let container = from_reqwest_response(upstream_res).await.unwrap();
res.render(container);
}

if params.clone().content_directory_id.unwrap()[0]
!= params.clone().pinned_content_directory_id.unwrap()[0]
{
// We only fill the first one.
let mut container: MediaContainerWrapper<MediaContainer> =
MediaContainerWrapper::default();
container.content_type =
get_content_type_from_headers(req.headers_mut());
container.media_container.size = Some(0);
container.media_container.allow_sync = Some(true);
container.media_container.identifier =
Some("com.plexapp.plugins.library".to_string());
return res.render(container);
}

// first directory, load everything here because we wanna reemiiiixxx

for id in params.clone().content_directory_id.unwrap() {
add_query_param_salvo(
req,
"contentDirectoryID".to_string(),
id,
);
let u = plex_client.request(req).await.unwrap();
let mut c: MediaContainerWrapper<MediaContainer> =
from_reqwest_response(u).await.unwrap();
}

// Hack, as the list could be smaller when removing watched items. So we request more.
if let Some(original_count) = params.clone().count {
add_query_param_salvo(
req,
"count".to_string(),
(original_count * 2).to_string(),
);
}

let upstream_res = plex_client.request(req).await.unwrap();
let mut container: MediaContainerWrapper<MediaContainer> =
from_reqwest_response(upstream_res).await.unwrap();

TransformBuilder::new(plex_client, params.clone())
.with_transform(HubStyleTransform)
.with_transform(HubMixTransform)
.with_transform(HubChildrenLimitTransform {
limit: params.clone().count.unwrap(),
})
.apply_to(&mut container)
.await;
res.render(container);
}

Expand Down
10 changes: 2 additions & 8 deletions src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,24 +438,20 @@ impl Transform for HubMixTransform {
let mut new_hubs: Vec<MetaData> = vec![];
// let mut library_section_id: Vec<Option<u32>> = vec![]; //librarySectionID
for mut hub in item.children_mut() {
let mut children = hub.children();
if !config.include_watched {
children.retain(|x| !x.is_watched());
hub.children_mut().retain(|x| !x.is_watched());
}

// we only process collection hubs
if !hub.is_collection_hub() {
hub.set_children(children);
new_hubs.push(hub.to_owned());
continue
}

let p = new_hubs.iter().position(|v| v.title == hub.title);
// dbg!(&hub.context);
if hub.r#type != "clip" {
hub.r#type = "mixed".to_string();
}

match p {
Some(v) => {
new_hubs[v].key = merge_children_keys(
Expand All @@ -465,15 +461,13 @@ impl Transform for HubMixTransform {
let c = new_hubs[v].children();
new_hubs[v].set_children(
c.into_iter()
.interleave(children)
.interleave(hub.children())
.collect::<Vec<MetaData>>(),
);
}
None => new_hubs.push(hub.to_owned()),
}
// dbg!(&new_hubs.get(0).unwrap().title);
}
// dbg!(&new_hubs.len());
item.set_children_mut(&mut new_hubs);
}
}
Expand Down

0 comments on commit 1c4ea8f

Please sign in to comment.