@ -305,23 +305,37 @@ class CollectionBuilder:
else : raise Failed ( f " Collection Error: { method_name } attribute must be either true or false " )
else : raise Failed ( f " Collection Error: { method_name } attribute must be either true or false " )
elif method_name in util . all_details :
elif method_name in util . all_details :
self . details [ method_name ] = method_data
self . details [ method_name ] = method_data
elif method_name in [ " title " , " title.and " , " title.not " , " title.begins " , " title.ends " ] :
self . methods . append ( ( " plex_search " , [ { method_name : util . get_list ( method_data , split = False ) } ] ) )
elif method_name in [ " decade " , " year.greater " , " year.less " ] :
self . methods . append ( ( " plex_search " , [ { method_name : util . check_year ( method_data , current_year , method_name ) } ] ) )
elif method_name in [ " added.before " , " added.after " , " originally_available.before " , " originally_available.after " ] :
self . methods . append ( ( " plex_search " , [ { method_name : util . check_date ( method_data , method_name , return_string = True , plex_date = True ) } ] ) )
elif method_name in [ " duration.greater " , " duration.less " , " rating.greater " , " rating.less " ] :
self . methods . append ( ( " plex_search " , [ { method_name : util . check_number ( method_data , method_name , minimum = 0 ) } ] ) )
elif method_name in [ " year " , " year.not " ] :
elif method_name in [ " year " , " year.not " ] :
self . methods . append ( ( " plex_search " , [ [ ( method_name , util . get_year_list ( self . data [ m ] , method_name ) ) ] ] ) )
self . methods . append ( ( " plex_search " , [ { method_name : util . get_year_list ( method_data , current_year , method_name ) } ] ) )
elif method_name in [ " decade " , " decade.not " ] :
self . methods . append ( ( " plex_search " , [ [ ( method_name , util . get_int_list ( self . data [ m ] , util . remove_not ( method_name ) ) ) ] ] ) )
elif method_name in util . tmdb_searches :
elif method_name in util . tmdb_searches :
final_values = [ ]
final_values = [ ]
for value in util . get_list ( self . data [ m ] ) :
for value in util . get_list ( method_data ) :
if value . lower ( ) == " tmdb " and " tmdb_person " in self . details :
if value . lower ( ) == " tmdb " and " tmdb_person " in self . details :
for name in self . details [ " tmdb_person " ] :
for name in self . details [ " tmdb_person " ] :
final_values . append ( name )
final_values . append ( name )
else :
else :
final_values . append ( value )
final_values . append ( value )
self . methods . append ( ( " plex_search " , [ [ ( method_name , final_values ) ] ] ) )
self . methods . append ( ( " plex_search " , [ { method_name : self . library . validate_search_list ( final_values , os . path . splitext ( method_name ) [ 0 ] ) } ] ) )
elif method_name == " title " :
self . methods . append ( ( " plex_search " , [ [ ( method_name , util . get_list ( self . data [ m ] , split = False ) ) ] ] ) )
elif method_name in util . plex_searches :
elif method_name in util . plex_searches :
self . methods . append ( ( " plex_search " , [ [ ( method_name , util . get_list ( self . data [ m ] ) ) ] ] ) )
if method_name in util . tmdb_searches :
final_values = [ ]
for value in util . get_list ( method_data ) :
if value . lower ( ) == " tmdb " and " tmdb_person " in self . details :
for name in self . details [ " tmdb_person " ] :
final_values . append ( name )
else :
final_values . append ( value )
else :
final_values = method_data
self . methods . append ( ( " plex_search " , [ { method_name : self . library . validate_search_list ( final_values , os . path . splitext ( method_name ) [ 0 ] ) } ] ) )
elif method_name == " plex_all " :
elif method_name == " plex_all " :
self . methods . append ( ( method_name , [ " " ] ) )
self . methods . append ( ( method_name , [ " " ] ) )
elif method_name == " plex_collection " :
elif method_name == " plex_collection " :
@ -436,31 +450,63 @@ class CollectionBuilder:
new_dictionary [ " exclude " ] = exact_list
new_dictionary [ " exclude " ] = exact_list
self . methods . append ( ( method_name , [ new_dictionary ] ) )
self . methods . append ( ( method_name , [ new_dictionary ] ) )
elif method_name == " plex_search " :
elif method_name == " plex_search " :
searches = [ ]
searches = { }
used = [ ]
for search_name , search_data in method_data :
for s in self . data [ m ] :
search , modifier = os . path . splitext ( str ( search_name ) . lower ( ) )
if s in util . method_alias or ( s . endswith ( " .not " ) and s [ : - 4 ] in util . method_alias ) :
if search in util . method_alias :
search = ( util . method_alias [ s [ : - 4 ] ] + s [ - 4 : ] ) if s . endswith ( " .not " ) else util . method_alias [ s ]
search = util . method_alias [ search ]
logger . warning ( f " Collection Warning: { s } plex search attribute will run as { search } " )
logger . warning ( f " Collection Warning: { str ( search_name ) . lower ( ) } plex search attribute will run as { search } { modifier if modifier else ' ' } " )
else :
search_final = f " { search } { modifier } "
search = s
if search_final in util . movie_only_searches and self . library . is_show :
if search in util . movie_only_searches and self . library . is_show :
raise Failed ( f " Collection Error: { search_final } plex search attribute only works for movie libraries " )
raise Failed ( f " Collection Error: { search } plex search attribute only works for movie libraries " )
elif search_data is None :
elif util . remove_not ( search ) in used :
raise Failed ( f " Collection Error: { search_final } plex search attribute is blank " )
raise Failed ( f " Collection Error: Only one instance of { search } can be used try using it as a filter instead " )
elif search == " sort_by " :
elif search in [ " year " , " year.not " ] :
if str ( search_data ) . lower ( ) in util . plex_sort :
years = util . get_year_list ( self . data [ m ] [ s ] , search )
searches [ search ] = str ( search_data ) . lower ( )
if len ( years ) > 0 :
else :
used . append ( util . remove_not ( search ) )
logger . warning ( f " Collection Error: { search_data } is not a valid plex search sort defaulting to title.asc " )
searches . append ( ( search , util . get_int_list ( self . data [ m ] [ s ] , util . remove_not ( search ) ) ) )
elif search == " limit " :
elif search == " title " :
if not search_data :
used . append ( util . remove_not ( search ) )
raise Failed ( f " Collection Warning: plex search limit attribute is blank " )
searches . append ( ( search , util . get_list ( self . data [ m ] [ s ] , split = False ) ) )
elif not isinstance ( search_data , int ) and search_data > 0 :
elif search in util . plex_searches :
raise Failed ( f " Collection Warning: plex search limit attribute: { search_data } must be an integer greater then 0 " )
used . append ( util . remove_not ( search ) )
else :
searches . append ( ( search , util . get_list ( self . data [ m ] [ s ] ) ) )
searches [ search ] = search_data
else :
elif search == " title " and modifier in [ " " , " .and " , " .not " , " .begins " , " .ends " ] :
logger . error ( f " Collection Error: { search } plex search attribute not supported " )
searches [ search_final ] = util . get_list ( search_data , split = False )
elif ( search == " studio " and modifier in [ " " , " .and " , " .not " , " .begins " , " .ends " ] ) \
or ( search in [ " actor " , " audio_language " , " collection " , " content_rating " , " country " , " director " , " genre " , " label " , " producer " , " subtitle_language " , " writer " ] and modifier in [ " " , " .and " , " .not " ] ) \
or ( search == " resolution " and modifier in [ " " ] ) :
if search_final in util . tmdb_searches :
final_values = [ ]
for value in util . get_list ( search_data ) :
if value . lower ( ) == " tmdb " and " tmdb_person " in self . details :
for name in self . details [ " tmdb_person " ] :
final_values . append ( name )
else :
final_values . append ( value )
else :
final_values = search_data
searches [ search_final ] = self . library . validate_search_list ( final_values , search )
elif ( search == " decade " and modifier in [ " " ] ) \
or ( search == " year " and modifier in [ " .greater " , " .less " ] ) :
searches [ search_final ] = util . check_year ( search_data , current_year , search_final )
elif search in [ " added " , " originally_available " ] and modifier in [ " .before " , " .after " ] :
searches [ search_final ] = util . check_date ( search_data , search_final , return_string = True , plex_date = True )
elif search in [ " duration " , " rating " ] and modifier in [ " .greater " , " .less " ] :
searches [ search_final ] = util . check_number ( search_data , search_final , minimum = 0 )
elif search == " year " and modifier in [ " " , " .not " ] :
searches [ search_final ] = util . get_year_list ( search_data , current_year , search_final )
elif ( search in [ " title " , " studio " ] and modifier not in [ " " , " .and " , " .not " , " .begins " , " .ends " ] ) \
or ( search in [ " actor " , " audio_language " , " collection " , " content_rating " , " country " , " director " , " genre " , " label " , " producer " , " subtitle_language " , " writer " ] and modifier not in [ " " , " .and " , " .not " ] ) \
or ( search in [ " resolution " , " decade " ] and modifier not in [ " " ] ) \
or ( search in [ " added " , " originally_available " ] and modifier not in [ " .before " , " .after " ] ) \
or ( search in [ " duration " , " rating " ] and modifier not in [ " .greater " , " .less " ] ) \
or ( search in [ " year " ] and modifier not in [ " " , " .not " , " .greater " , " .less " ] ) :
raise Failed ( f " Collection Error: modifier: { modifier } not supported with the { search } plex search attribute " )
else :
raise Failed ( f " Collection Error: { search_final } plex search attribute not supported " )
self . methods . append ( ( method_name , [ searches ] ) )
self . methods . append ( ( method_name , [ searches ] ) )
elif method_name == " tmdb_discover " :
elif method_name == " tmdb_discover " :
new_dictionary = { " limit " : 100 }
new_dictionary = { " limit " : 100 }
@ -758,38 +804,31 @@ class CollectionBuilder:
items_found + = len ( items )
items_found + = len ( items )
elif method == " plex_search " :
elif method == " plex_search " :
search_terms = { }
search_terms = { }
title_searches = None
has_processed = False
has_processed = False
for search_method , search_list in value :
search_limit = None
if search_method == " title " :
search_sort = None
ors = " "
for search_method , search_data in value :
for o , param in enumerate ( search_list ) :
if search_method == " limit " :
ors + = f " { ' OR ' if o > 0 else ' ' } { param } "
search_limit = search_data
title_searches = search_list
elif search_method == " sort_by " :
logger . info ( f " Processing { pretty } : title( { ors } ) " )
search_sort = util . plex_sort [ search_data ]
has_processed = True
else :
break
search , modifier = os . path . splitext ( str ( search_method ) . lower ( ) )
for search_method , search_list in value :
final_search = util . search_alias [ search ] if search in util . search_alias else search
if search_method != " title " :
final_mod = util . plex_modifiers [ modifier ] if modifier in util . plex_modifiers else " "
final_method = search_method [ : - 4 ] + " ! " if search_method [ - 4 : ] == " .not " else search_method
final_method = f " { final_search } { final_mod } "
if self . library . is_show :
search_terms [ final_method ] = search_data * 60000 if final_search == " duration " else search_data
final_method = " show. " + final_method
search_terms [ final_method ] = search_list
ors = " "
ors = " "
for o , param in enumerate ( search_list ) :
conjunction = " AND " if final_mod == " & " else " OR "
or_des = " OR " if o > 0 else f " { search_method } ( "
for o , param in enumerate ( search_data ) :
or_des = conjunction if o > 0 else f " { search_method } ( "
ors + = f " { or_des } { param } "
ors + = f " { or_des } { param } "
if has_processed :
if has_processed :
logger . info ( f " \t \t AND { ors } ) " )
logger . info ( f " \t \t AND { ors } ) " )
else :
else :
logger . info ( f " Processing { pretty } : { ors } ) " )
logger . info ( f " Processing { pretty } : { ors } ) " )
has_processed = True
has_processed = True
if title_searches :
items = self . library . Plex . search ( sort = search_sort , maxresults = search_limit , * * search_terms )
items = [ ]
for title_search in title_searches :
items . extend ( self . library . Plex . search ( title_search , * * search_terms ) )
else :
items = self . library . Plex . search ( * * search_terms )
items_found + = len ( items )
items_found + = len ( items )
elif method == " plex_collectionless " :
elif method == " plex_collectionless " :
good_collections = [ ]
good_collections = [ ]