Commit 7be6138 1 parent f4c33f0 commit 7be6138 Copy full SHA for 7be6138
File tree 1 file changed +71
-0
lines changed
1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ use async_trait:: async_trait;
2
+ use crate :: {
3
+ config:: Config ,
4
+ models:: * ,
5
+ plex_client:: { PlexClient } ,
6
+ } ;
7
+
8
+ use super :: Transform ;
9
+ #[ derive( Default ) ]
10
+ pub struct HubRestrictionTransform ;
11
+
12
+ #[ async_trait]
13
+ impl Transform for HubRestrictionTransform {
14
+ async fn filter_metadata (
15
+ & self ,
16
+ item : MetaData ,
17
+ plex_client : PlexClient ,
18
+ options : PlexContext ,
19
+ ) -> bool {
20
+ let config: Config = Config :: figment ( ) . extract ( ) . unwrap ( ) ;
21
+
22
+ if !config. hub_restrictions {
23
+ return true ;
24
+ }
25
+
26
+ if item. is_hub ( ) && !item. is_collection_hub ( ) {
27
+ return true ;
28
+ }
29
+
30
+ if !item. is_hub ( ) {
31
+ return true ;
32
+ }
33
+
34
+ if item. size . unwrap ( ) == 0 {
35
+ return false ;
36
+ }
37
+
38
+ let section_id: i64 = item. library_section_id . unwrap_or_else ( || {
39
+ item. hub_identifier . clone ( ) . unwrap ( ) . split ( '.' ) . collect :: < Vec < & str > > ( ) [ 2 ] . parse ( ) . unwrap ( )
40
+ } ) ;
41
+
42
+ //let start = Instant::now();
43
+ let mut custom_collections = plex_client
44
+ . clone ( )
45
+ . get_cached (
46
+ plex_client. get_section_collections ( section_id) ,
47
+ format ! ( "sectioncollections:{}" , section_id) . to_string ( ) ,
48
+ )
49
+ . await
50
+ . unwrap ( ) ;
51
+
52
+ //println!("Elapsed time: {:.2?}", start.elapsed());
53
+ let custom_collections_ids: Vec < String > = custom_collections
54
+ . media_container
55
+ . children ( )
56
+ . iter ( )
57
+ . map ( |c| c. rating_key . clone ( ) . unwrap ( ) )
58
+ . collect ( ) ;
59
+
60
+ custom_collections_ids. contains (
61
+ & item
62
+ . hub_identifier
63
+ . clone ( )
64
+ . unwrap ( )
65
+ . split ( '.' )
66
+ . last ( )
67
+ . unwrap ( )
68
+ . to_owned ( ) ,
69
+ )
70
+ }
71
+ }
You can’t perform that action at this time.
0 commit comments