@@ -385,10 +385,14 @@ def alert_callback(data):
385385 "--accept-eula" , help = "Accept Plex's EULA" , default = False , action = "store_true"
386386 ) # noqa
387387 parser .add_argument (
388- "--additional-server-queries-put" ,
389- help = "Comma separated list of additional PUT requests to send to the server. The requests are sent before the "
390- "library sections are created. You can use this to enable third party metadata agents, as an example. "
391- "e.g. `/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>`" ,
388+ "--additional-server-queries" ,
389+ help = "Space separated list of additional requests to send to the server. The type of request should be at the "
390+ "beginning of the endpoint, followed by a `|`. "
391+ "If no `|` is found the default request type of `PUT` will be used. "
392+ "The requests are sent before the library sections are created. "
393+ "You can use this to enable third party metadata agents, as an example. "
394+ "e.g. "
395+ "`put|/system/agents/com.plexapp.agents.imdb/config/1?order=com.plexapp.agents.imdb%2C<my_movie_agent>` " ,
392396 default = [],
393397 nargs = '*' ,
394398 ) # noqa
@@ -734,13 +738,50 @@ def alert_callback(data):
734738 )
735739
736740 # send additional server queries
737- if opts .additional_server_queries_put :
738- print ("Sending additional PUT requests to the server" )
739- print ("Additional PUT requests: {}" .format (opts .additional_server_queries_put ))
740- for query in opts .additional_server_queries_put :
741- query = query .strip ()
742- print ("Sending PUT request to {}" .format (query ))
743- server .query (key = query , method = server ._session .put )
741+ if opts .additional_server_queries :
742+ request_map = {
743+ "delete" : server ._session .delete ,
744+ "get" : server ._session .get ,
745+ "post" : server ._session .post ,
746+ "put" : server ._session .put ,
747+ }
748+
749+ print ("Sending additional requests to the server" )
750+ print ("Additional requests: {}" .format (opts .additional_server_queries ))
751+
752+ completed_queries = []
753+ start = time .time ()
754+ runtime = 0
755+ while runtime < 60 and len (completed_queries ) < len (opts .additional_server_queries ):
756+ for query in opts .additional_server_queries :
757+ query = query .strip ()
758+ if query not in completed_queries :
759+ if '|' in query :
760+ method , key = query .split ('|' )
761+ method = method .strip ()
762+ key = key .strip ()
763+ else :
764+ method = 'put'
765+ key = query .strip ()
766+
767+ if method not in request_map :
768+ raise SystemExit ("Invalid method specified: {}" .format (method ))
769+ if not key .startswith ('/' ):
770+ raise SystemExit ("Invalid key specified: {}" .format (key ))
771+ print ("Sending {} request to {}" .format (method , key ))
772+ try :
773+ server .query (key = key , method = request_map [method ])
774+ except NotFound as err :
775+ # if 404, wait
776+ print ("error: {}" .format (err ))
777+ time .sleep (5 )
778+ else :
779+ completed_queries .append (query )
780+ finally :
781+ runtime = time .time () - start
782+
783+ if len (completed_queries ) < len (opts .additional_server_queries ):
784+ raise SystemExit ("Did not successfully complete all additional server queries" )
744785
745786 # Create the Plex library in our instance
746787 if sections :
0 commit comments