Skip to content

Commit

Permalink
fix: merge filter and metadata ao we can have ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Jul 23, 2024
1 parent f4c33f0 commit 7be6138
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/transform/restrictions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use async_trait::async_trait;
use crate::{
config::Config,
models::*,
plex_client::{PlexClient},
};

use super::Transform;
#[derive(Default)]
pub struct HubRestrictionTransform;

#[async_trait]
impl Transform for HubRestrictionTransform {
async fn filter_metadata(
&self,
item: MetaData,
plex_client: PlexClient,
options: PlexContext,
) -> bool {
let config: Config = Config::figment().extract().unwrap();

if !config.hub_restrictions {
return true;
}

if item.is_hub() && !item.is_collection_hub() {
return true;
}

if !item.is_hub() {
return true;
}

if item.size.unwrap() == 0 {
return false;
}

let section_id: i64 = item.library_section_id.unwrap_or_else(|| {
item.hub_identifier.clone().unwrap().split('.').collect::<Vec<&str>>()[2].parse().unwrap()
});

//let start = Instant::now();
let mut custom_collections = plex_client
.clone()
.get_cached(
plex_client.get_section_collections(section_id),
format!("sectioncollections:{}", section_id).to_string(),
)
.await
.unwrap();

//println!("Elapsed time: {:.2?}", start.elapsed());
let custom_collections_ids: Vec<String> = custom_collections
.media_container
.children()
.iter()
.map(|c| c.rating_key.clone().unwrap())
.collect();

custom_collections_ids.contains(
&item
.hub_identifier
.clone()
.unwrap()
.split('.')
.last()
.unwrap()
.to_owned(),
)
}
}

0 comments on commit 7be6138

Please sign in to comment.