@@ -456,10 +456,45 @@ def get(self, title):
456456
457457 Parameters:
458458 title (str): Title of the item to return.
459+
460+ Raises:
461+ :exc:`~plexapi.exceptions.NotFound`: The title is not found in the library.
459462 """
460- key = '/library/sections/%s/all?title=%s' % (self .key , quote (title , safe = '' ))
463+ key = '/library/sections/%s/all?includeGuids=1& title=%s' % (self .key , quote (title , safe = '' ))
461464 return self .fetchItem (key , title__iexact = title )
462465
466+ def getGuid (self , guid ):
467+ """ Returns the media item with the specified external IMDB, TMDB, or TVDB ID.
468+ Note: This search uses a PlexAPI operator so performance may be slow. All items from the
469+ entire Plex library need to be retrieved for each guid search. It is recommended to create
470+ your own lookup dictionary if you are searching for a lot of external guids.
471+
472+ Parameters:
473+ guid (str): The external guid of the item to return.
474+ Examples: IMDB ``imdb://tt0944947``, TMDB ``tmdb://1399``, TVDB ``tvdb://121361``.
475+
476+ Raises:
477+ :exc:`~plexapi.exceptions.NotFound`: The guid is not found in the library.
478+
479+ Example:
480+
481+ .. code-block:: python
482+
483+ # This will retrieve all items in the entire library 3 times
484+ result1 = library.getGuid('imdb://tt0944947')
485+ result2 = library.getGuid('tmdb://1399')
486+ result3 = library.getGuid('tvdb://121361')
487+
488+ # This will only retrieve all items in the library once to create a lookup dictionary
489+ guidLookup = {guid.id: item for item in library.all() for guid in item.guids}
490+ result1 = guidLookup['imdb://tt0944947']
491+ result2 = guidLookup['tmdb://1399']
492+ result3 = guidLookup['tvdb://121361']
493+
494+ """
495+ key = '/library/sections/%s/all?includeGuids=1' % self .key
496+ return self .fetchItem (key , Guid__id__iexact = guid )
497+
463498 def all (self , libtype = None , ** kwargs ):
464499 """ Returns a list of all items from this library section.
465500 See description of :func:`~plexapi.library.LibrarySection.search()` for details about filtering / sorting.
@@ -979,6 +1014,8 @@ def _buildSearchKey(self, title=None, sort=None, libtype=None, limit=None, filte
9791014 """
9801015 args = {}
9811016 filter_args = []
1017+
1018+ args ['includeGuids' ] = int (bool (kwargs .pop ('includeGuids' , True )))
9821019 for field , values in list (kwargs .items ()):
9831020 if field .split ('__' )[- 1 ] not in OPERATORS :
9841021 filter_args .append (self ._validateFilterField (field , values , libtype ))
@@ -1456,6 +1493,23 @@ def filterFields(self, mediaType=None):
14561493 def listChoices (self , category , libtype = None , ** kwargs ):
14571494 return self .listFilterChoices (field = category , libtype = libtype )
14581495
1496+ def getWebURL (self , base = None , tab = None , key = None ):
1497+ """ Returns the Plex Web URL for the library.
1498+
1499+ Parameters:
1500+ base (str): The base URL before the fragment (``#!``).
1501+ Default is https://app.plex.tv/desktop.
1502+ tab (str): The library tab (recommended, library, collections, playlists, timeline).
1503+ key (str): A hub key.
1504+ """
1505+ params = {'source' : self .key }
1506+ if tab is not None :
1507+ params ['pivot' ] = tab
1508+ if key is not None :
1509+ params ['key' ] = key
1510+ params ['pageType' ] = 'list'
1511+ return self ._server ._buildWebURL (base = base , ** params )
1512+
14591513
14601514class MovieSection (LibrarySection ):
14611515 """ Represents a :class:`~plexapi.library.LibrarySection` section containing movies.
@@ -1857,6 +1911,7 @@ def _loadData(self, data):
18571911 self .style = data .attrib .get ('style' )
18581912 self .title = data .attrib .get ('title' )
18591913 self .type = data .attrib .get ('type' )
1914+ self ._section = None # cache for self.section
18601915
18611916 def __len__ (self ):
18621917 return self .size
@@ -1868,6 +1923,13 @@ def reload(self):
18681923 self .more = False
18691924 self .size = len (self .items )
18701925
1926+ def section (self ):
1927+ """ Returns the :class:`~plexapi.library.LibrarySection` this hub belongs to.
1928+ """
1929+ if self ._section is None :
1930+ self ._section = self ._server .library .sectionByID (self .librarySectionID )
1931+ return self ._section
1932+
18711933
18721934class HubMediaTag (PlexObject ):
18731935 """ Base class of hub media tag search results.
0 commit comments