Skip to content
This repository was archived by the owner on Apr 12, 2025. It is now read-only.

Commit e2c669b

Browse files
committed
feat: Filter hubs for restrictions
1 parent 0aa81b8 commit e2c669b

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ run:
3232
REPLEX_DISABLE_USER_STATE=0 \
3333
REPLEX_ENABLE_CONSOLE=0 \
3434
REPLEX_CACHE_TTL=600 \
35-
RUST_LOG="info,replex=info" \
35+
REPLEX_HUB_RESTRICTIONS=0 \
36+
RUST_LOG="info,replex=debug" \
3637
REPLEX_NTF_WATCHLIST_FORCE=1 \
3738
RUSTFLAGS=-Awarnings \
3839
cargo watch -w src -x run

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Remix your plex recommendations.
1010
- Remove watched items from recommendations.
1111
- Choose between styles, shelf (default) or hero.
1212
- Auto load artwork for hero styles.
13+
- Filter hubs by its restrictions (per user hub)
1314
- Disable user state: remove unplayed badges from row items.
1415
- Disable leaf count: remove episode count from artwork.
1516
- Force maximum quality.
@@ -77,6 +78,7 @@ Settings are set via [environment variables](https://kinsta.com/knowledgebase/wh
7778
| REPLEX_TOKEN | | server admin plex token, needed for hero images. To find your token see: https://support.plex.tv/articles/204059436-finding-an-authentication |
7879
| REPLEX_INTERLEAVE | true | Interleave home recommendations. Collection rows with the same name from different libraries are interleaved (combined) into one. |
7980
| REPLEX_EXCLUDE_WATCHED | true | If set to true, hide watched items for recommended rows |
81+
| REPLEX_HUB_RESTRICTIONS | true | Apply collections restrictions to their hub's. Plex does not apply restrictions to hubs, so you cannot have different collection hubs for users. this fixes that. |
8082
| REPLEX_DISABLE_CONTINUE_WATCHING | false | Disable/remove the continue watching row |
8183
| REPLEX_DISABLE_USER_STATE | false | Remove unplayed badges from row items |
8284
| REPLEX_DISABLE_LEAF_COUNT| false | Remove episode count label from show artwork. |

src/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ pub struct Config {
2222
default = "default_as_true",
2323
deserialize_with = "figment::util::bool_from_str_or_int"
2424
)]
25+
pub hub_restrictions: bool,
26+
#[serde(
27+
default = "default_as_true",
28+
deserialize_with = "figment::util::bool_from_str_or_int"
29+
)]
2530
pub exclude_watched: bool,
2631
#[serde(default = "default_cache_ttl")]
2732
pub cache_ttl: u64,

src/routes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ pub async fn transform_hubs_home(
616616
container.content_type = content_type;
617617

618618
TransformBuilder::new(plex_client, params.clone())
619+
.with_filter(HubRestrictionsFilter)
619620
.with_transform(HubStyleTransform { is_home: true })
620621
.with_transform(HubWatchedTransform)
621622
.with_transform(HubInterleaveTransform)
@@ -671,6 +672,7 @@ pub async fn get_hubs_sections(
671672
container.content_type = content_type;
672673

673674
TransformBuilder::new(plex_client, params.clone())
675+
.with_filter(HubRestrictionsFilter)
674676
.with_transform(HubSectionDirectoryTransform)
675677
.with_transform(HubStyleTransform { is_home: false })
676678
.with_transform(HubWatchedTransform)
@@ -728,6 +730,7 @@ pub async fn get_collections_children(
728730

729731
// filtering of watched happens in the transform
730732
TransformBuilder::new(plex_client, params.clone())
733+
.with_filter(HubRestrictionsFilter)
731734
.with_transform(LibraryInterleaveTransform {
732735
collection_ids: collection_ids.clone(),
733736
offset,

src/transform.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,21 @@ impl TransformBuilder {
235235
}
236236
}
237237

238-
// const T: usize;
239238
#[derive(Default)]
240-
pub struct CollectionHubPermissionFilter;
239+
pub struct HubRestrictionsFilter;
241240

242241
#[async_trait]
243-
impl Filter for CollectionHubPermissionFilter {
242+
impl Filter for HubRestrictionsFilter {
244243
async fn filter_metadata(
245244
&self,
246245
item: &mut MetaData,
247246
plex_client: PlexClient,
248247
options: PlexContext,
249248
) -> bool {
249+
let config: Config = Config::figment().extract().unwrap();
250+
if !config.hub_restrictions {
251+
return true;
252+
}
250253
tracing::debug!("filter collection permissions");
251254

252255
if item.is_hub() && !item.is_collection_hub() {
@@ -263,8 +266,7 @@ impl Filter for CollectionHubPermissionFilter {
263266
.library_section_id
264267
.expect("Missing Library section id")
265268
});
266-
// dbg!(section_id);
267-
// let mut custom_collections = plex_client.get_section_collections(section_id).await.unwrap();
269+
268270
let mut custom_collections = plex_client
269271
.clone()
270272
.get_cached(
@@ -273,7 +275,7 @@ impl Filter for CollectionHubPermissionFilter {
273275
)
274276
.await
275277
.unwrap();
276-
// dbg!(&custom_collections);
278+
277279
let custom_collections_ids: Vec<String> = custom_collections
278280
.media_container
279281
.children()

0 commit comments

Comments
 (0)