From 2562334ad4645a222a7f51f3673e96d926658eac Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Fri, 18 Jun 2021 14:21:43 -0700 Subject: [PATCH] Add reverseSearchType util --- plexapi/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plexapi/utils.py b/plexapi/utils.py index 5fe31caa..310200f6 100644 --- a/plexapi/utils.py +++ b/plexapi/utils.py @@ -148,6 +148,7 @@ def searchType(libtype): Parameters: libtype (str): LibType to lookup (movie, show, season, episode, artist, album, track, collection) + Raises: :exc:`~plexapi.exceptions.NotFound`: Unknown libtype """ @@ -159,6 +160,24 @@ def searchType(libtype): raise NotFound('Unknown libtype: %s' % libtype) +def reverseSearchType(libtype): + """ Returns the string value of the library type. + + Parameters: + libtype (int): Integer value of the library type. + + Raises: + :exc:`~plexapi.exceptions.NotFound`: Unknown libtype + """ + if libtype in SEARCHTYPES: + return libtype + libtype = int(libtype) + for k, v in SEARCHTYPES.items(): + if libtype == v: + return k + raise NotFound('Unknown libtype: %s' % libtype) + + def threaded(callback, listargs): """ Returns the result of for each set of `*args` in listargs. Each call to is called concurrently in their own separate threads.