2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-02-01 21:32:00 +00:00
|
|
|
from plexapi import X_PLEX_CONTAINER_SIZE, log, utils
|
2017-02-06 04:52:10 +00:00
|
|
|
from plexapi.base import PlexObject
|
2017-02-27 12:23:35 +00:00
|
|
|
from plexapi.compat import unquote, urlencode, quote_plus
|
2017-02-20 05:37:00 +00:00
|
|
|
from plexapi.media import MediaTag
|
2016-03-31 20:52:48 +00:00
|
|
|
from plexapi.exceptions import BadRequest, NotFound
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
class Library(PlexObject):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Represents a PlexServer library. This contains all sections of media defined
|
|
|
|
in your Plex server including video, shows and audio.
|
|
|
|
|
|
|
|
Attributes:
|
2017-02-14 04:32:27 +00:00
|
|
|
key (str): '/library'
|
2017-01-26 04:21:13 +00:00
|
|
|
identifier (str): Unknown ('com.plexapp.plugins.library').
|
|
|
|
mediaTagVersion (str): Unknown (/system/bundle/media/flags/)
|
|
|
|
server (:class:`~plexapi.server.PlexServer`): PlexServer this client is connected to.
|
|
|
|
title1 (str): 'Plex Library' (not sure how useful this is).
|
|
|
|
title2 (str): Second title (this is blank on my setup).
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
key = '/library'
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2017-02-04 08:08:47 +00:00
|
|
|
self._data = data
|
2017-02-06 04:52:10 +00:00
|
|
|
self._sectionsByID = {} # cached Section UUIDs
|
2014-12-29 03:21:58 +00:00
|
|
|
self.identifier = data.attrib.get('identifier')
|
|
|
|
self.mediaTagVersion = data.attrib.get('mediaTagVersion')
|
|
|
|
self.title1 = data.attrib.get('title1')
|
|
|
|
self.title2 = data.attrib.get('title2')
|
|
|
|
|
|
|
|
def sections(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of all media sections in this library. Library sections may be any of
|
|
|
|
:class:`~plexapi.library.MovieSection`, :class:`~plexapi.library.ShowSection`,
|
|
|
|
:class:`~plexapi.library.MusicSection`, :class:`~plexapi.library.PhotoSection`.
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
key = '/library/sections'
|
2017-02-13 02:55:55 +00:00
|
|
|
sections = []
|
2017-02-09 04:29:17 +00:00
|
|
|
for elem in self._server.query(key):
|
2017-02-13 02:55:55 +00:00
|
|
|
for cls in (MovieSection, ShowSection, MusicSection, PhotoSection):
|
|
|
|
if elem.attrib.get('type') == cls.TYPE:
|
|
|
|
section = cls(self._server, elem, key)
|
|
|
|
self._sectionsByID[section.key] = section
|
|
|
|
sections.append(section)
|
|
|
|
return sections
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
def section(self, title=None):
|
2017-01-31 04:48:21 +00:00
|
|
|
""" Returns the :class:`~plexapi.library.LibrarySection` that matches the specified title.
|
2017-01-26 04:21:13 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
title (str): Title of the section to return.
|
|
|
|
"""
|
2017-02-07 06:20:49 +00:00
|
|
|
for section in self.sections():
|
2017-02-13 02:55:55 +00:00
|
|
|
if section.title.lower() == title.lower():
|
2017-02-07 06:20:49 +00:00
|
|
|
return section
|
2014-12-29 03:21:58 +00:00
|
|
|
raise NotFound('Invalid library section: %s' % title)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-04-12 02:43:21 +00:00
|
|
|
def sectionByID(self, sectionID):
|
2017-01-31 04:48:21 +00:00
|
|
|
""" Returns the :class:`~plexapi.library.LibrarySection` that matches the specified sectionID.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Parameters:
|
2017-02-03 16:39:46 +00:00
|
|
|
sectionID (str): ID of the section to return.
|
2017-01-26 04:21:13 +00:00
|
|
|
"""
|
2017-02-01 21:32:00 +00:00
|
|
|
if not self._sectionsByID or sectionID not in self._sectionsByID:
|
2016-04-12 02:43:21 +00:00
|
|
|
self.sections()
|
|
|
|
return self._sectionsByID[sectionID]
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-02-09 04:08:25 +00:00
|
|
|
def all(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of all media from all library sections.
|
|
|
|
This may be a very large dataset to retrieve.
|
|
|
|
"""
|
2017-02-13 02:55:55 +00:00
|
|
|
items = []
|
|
|
|
for section in self.sections():
|
|
|
|
for item in section.all(**kwargs):
|
|
|
|
items.append(item)
|
|
|
|
return items
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
def onDeck(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of all media items on deck. """
|
2017-02-07 06:20:49 +00:00
|
|
|
return self.fetchItems('/library/onDeck')
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
def recentlyAdded(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of all media items recently added. """
|
2017-02-07 06:20:49 +00:00
|
|
|
return self.fetchItems('/library/recentlyAdded')
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-04-08 02:48:45 +00:00
|
|
|
def search(self, title=None, libtype=None, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Searching within a library section is much more powerful. It seems certain
|
|
|
|
attributes on the media objects can be targeted to filter this search down
|
|
|
|
a bit, but I havent found the documentation for it.
|
2016-12-15 23:06:12 +00:00
|
|
|
|
|
|
|
Example: "studio=Comedy%20Central" or "year=1999" "title=Kung Fu" all work. Other items
|
2017-01-26 04:21:13 +00:00
|
|
|
such as actor=<id> seem to work, but require you already know the id of the actor.
|
|
|
|
TLDR: This is untested but seems to work. Use library section search when you can.
|
2016-03-31 20:52:48 +00:00
|
|
|
"""
|
2016-01-19 09:50:31 +00:00
|
|
|
args = {}
|
2016-12-15 23:06:12 +00:00
|
|
|
if title:
|
|
|
|
args['title'] = title
|
|
|
|
if libtype:
|
|
|
|
args['type'] = utils.searchType(libtype)
|
2016-03-31 20:52:48 +00:00
|
|
|
for attr, value in kwargs.items():
|
|
|
|
args[attr] = value
|
2017-02-06 06:28:58 +00:00
|
|
|
key = '/library/all%s' % utils.joinArgs(args)
|
2017-02-07 06:20:49 +00:00
|
|
|
return self.fetchItems(key)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
def cleanBundles(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Poster images and other metadata for items in your library are kept in "bundle"
|
|
|
|
packages. When you remove items from your library, these bundles aren't immediately
|
|
|
|
removed. Removing these old bundles can reduce the size of your install. By default, your
|
|
|
|
server will automatically clean up old bundles once a week as part of Scheduled Tasks.
|
|
|
|
"""
|
2017-02-02 03:53:05 +00:00
|
|
|
# TODO: Should this check the response for success or the correct mediaprefix?
|
2017-02-09 04:29:17 +00:00
|
|
|
self._server.query('/library/clean/bundles')
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
def emptyTrash(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" If a library has items in the Library Trash, use this option to empty the Trash. """
|
2014-12-29 03:21:58 +00:00
|
|
|
for section in self.sections():
|
|
|
|
section.emptyTrash()
|
|
|
|
|
|
|
|
def optimize(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" The Optimize option cleans up the server database from unused or fragmented data.
|
|
|
|
For example, if you have deleted or added an entire library or many items in a
|
|
|
|
library, you may like to optimize the database.
|
|
|
|
"""
|
2017-02-09 04:29:17 +00:00
|
|
|
self._server.query('/library/optimize')
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
def update(self):
|
|
|
|
""" Scan this library for new items."""
|
2017-02-09 04:29:17 +00:00
|
|
|
self._server.query('/library/sections/all/refresh')
|
2017-01-03 22:58:35 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
def cancelUpdate(self):
|
2017-02-15 04:22:57 +00:00
|
|
|
""" Cancel a library update. """
|
|
|
|
key = '/library/sections/all/refresh'
|
|
|
|
self._server.query(key, method=self._server._session.delete)
|
2017-02-14 22:36:21 +00:00
|
|
|
|
|
|
|
def refresh(self):
|
2017-02-15 04:22:57 +00:00
|
|
|
""" Forces a download of fresh media information from the internet.
|
|
|
|
This can take a long time. Any locked fields are not modified.
|
|
|
|
"""
|
2017-02-14 22:36:21 +00:00
|
|
|
self._server.query('/library/sections/all/refresh?force=1')
|
|
|
|
|
2017-02-20 03:51:17 +00:00
|
|
|
def deleteMediaPreviews(self):
|
|
|
|
""" Delete the preview thumbnails for the all sections. This cannot be
|
|
|
|
undone. Recreating media preview files can take hours or even days.
|
2017-02-18 21:12:43 +00:00
|
|
|
"""
|
|
|
|
for section in self.sections():
|
2017-02-20 03:51:17 +00:00
|
|
|
section.deleteMediaPreviews()
|
2017-02-18 21:12:43 +00:00
|
|
|
|
2017-02-27 22:16:02 +00:00
|
|
|
def add(self, name='', type='', agent='', scanner='', location='', language='en', *args, **kwargs):
|
2017-02-27 12:23:35 +00:00
|
|
|
""" Simplified add for the most common options.
|
|
|
|
|
2017-03-22 03:04:23 +00:00
|
|
|
Parameters:
|
|
|
|
name (str): Name of the library
|
|
|
|
agent (str): Example com.plexapp.agents.imdb
|
|
|
|
type (str): movie, show, # check me
|
|
|
|
location (str): /path/to/files
|
|
|
|
language (str): Two letter language fx en
|
|
|
|
kwargs (dict): Advanced options should be passed as a dict. where the id is the key.
|
|
|
|
|
2017-04-23 05:18:53 +00:00
|
|
|
**Photo Preferences**
|
|
|
|
|
|
|
|
* **agent** (str): com.plexapp.agents.none
|
|
|
|
* **enableAutoPhotoTags** (bool): Tag photos. Default value false.
|
|
|
|
* **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true.
|
|
|
|
* **includeInGlobal** (bool): Include in dashboard. Default value true.
|
|
|
|
* **scanner** (str): Plex Photo Scanner
|
|
|
|
|
|
|
|
**Movie Preferences**
|
|
|
|
|
|
|
|
* **agent** (str): com.plexapp.agents.none, com.plexapp.agents.imdb, com.plexapp.agents.themoviedb
|
|
|
|
* **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true.
|
|
|
|
* **enableCinemaTrailers** (bool): Enable Cinema Trailers. Default value true.
|
|
|
|
* **includeInGlobal** (bool): Include in dashboard. Default value true.
|
|
|
|
* **scanner** (str): Plex Movie Scanner, Plex Video Files Scanner
|
|
|
|
|
|
|
|
**IMDB Movie Options** (com.plexapp.agents.imdb)
|
|
|
|
|
|
|
|
* **title** (bool): Localized titles. Default value false.
|
|
|
|
* **extras** (bool): Find trailers and extras automatically (Plex Pass required). Default value true.
|
|
|
|
* **only_trailers** (bool): Skip extras which aren't trailers. Default value false.
|
|
|
|
* **redband** (bool): Use red band (restricted audiences) trailers when available. Default value false.
|
|
|
|
* **native_subs** (bool): Include extras with subtitles in Library language. Default value false.
|
|
|
|
* **cast_list** (int): Cast List Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.
|
|
|
|
* **ratings** (int): Ratings Source, Default value 0 Possible options:
|
|
|
|
0:Rotten Tomatoes, 1:IMDb, 2:The Movie Database.
|
|
|
|
* **summary** (int): Plot Summary Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.
|
|
|
|
* **country** (int): Default value 46 Possible options 0:Argentina, 1:Australia, 2:Austria,
|
|
|
|
3:Belgium, 4:Belize, 5:Bolivia, 6:Brazil, 7:Canada, 8:Chile, 9:Colombia, 10:Costa Rica,
|
|
|
|
11:Czech Republic, 12:Denmark, 13:Dominican Republic, 14:Ecuador, 15:El Salvador,
|
|
|
|
16:France, 17:Germany, 18:Guatemala, 19:Honduras, 20:Hong Kong SAR, 21:Ireland,
|
|
|
|
22:Italy, 23:Jamaica, 24:Korea, 25:Liechtenstein, 26:Luxembourg, 27:Mexico, 28:Netherlands,
|
|
|
|
29:New Zealand, 30:Nicaragua, 31:Panama, 32:Paraguay, 33:Peru, 34:Portugal,
|
|
|
|
35:Peoples Republic of China, 36:Puerto Rico, 37:Russia, 38:Singapore, 39:South Africa,
|
|
|
|
40:Spain, 41:Sweden, 42:Switzerland, 43:Taiwan, 44:Trinidad, 45:United Kingdom,
|
|
|
|
46:United States, 47:Uruguay, 48:Venezuela.
|
|
|
|
* **collections** (bool): Use collection info from The Movie Database. Default value false.
|
|
|
|
* **localart** (bool): Prefer artwork based on library language. Default value true.
|
|
|
|
* **adult** (bool): Include adult content. Default value false.
|
|
|
|
* **usage** (bool): Send anonymous usage data to Plex. Default value true.
|
|
|
|
|
|
|
|
**TheMovieDB Movie Options** (com.plexapp.agents.themoviedb)
|
|
|
|
|
|
|
|
* **collections** (bool): Use collection info from The Movie Database. Default value false.
|
|
|
|
* **localart** (bool): Prefer artwork based on library language. Default value true.
|
|
|
|
* **adult** (bool): Include adult content. Default value false.
|
|
|
|
* **country** (int): Country (used for release date and content rating). Default value 47 Possible
|
|
|
|
options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile,
|
|
|
|
10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador,
|
|
|
|
16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland,
|
|
|
|
23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands,
|
|
|
|
30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, 36:Peoples Republic of China,
|
|
|
|
37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland,
|
|
|
|
44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.
|
|
|
|
|
|
|
|
**Show Preferences**
|
|
|
|
|
|
|
|
* **agent** (str): com.plexapp.agents.none, com.plexapp.agents.thetvdb, com.plexapp.agents.themoviedb
|
|
|
|
* **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true.
|
|
|
|
* **episodeSort** (int): Episode order. Default value -1 Possible options: 0:Oldest first,1:Newest first.
|
|
|
|
* **flattenSeasons** (int): Seasons. Default value 0 Possible options: 0:Show,1:Hide.
|
|
|
|
* **includeInGlobal** (bool): Include in dashboard. Default value true.
|
|
|
|
* **scanner** (str): Plex Series Scanner
|
|
|
|
|
|
|
|
**TheTVDB Show Options** (com.plexapp.agents.thetvdb)
|
|
|
|
|
|
|
|
* **extras** (bool): Find trailers and extras automatically (Plex Pass required). Default value true.
|
|
|
|
* **native_subs** (bool): Include extras with subtitles in Library language. Default value false.
|
|
|
|
|
|
|
|
**TheMovieDB Show Options** (com.plexapp.agents.themoviedb)
|
|
|
|
|
|
|
|
* **collections** (bool): Use collection info from The Movie Database. Default value false.
|
|
|
|
* **localart** (bool): Prefer artwork based on library language. Default value true.
|
|
|
|
* **adult** (bool): Include adult content. Default value false.
|
|
|
|
* **country** (int): Country (used for release date and content rating). Default value 47 Possible options
|
|
|
|
0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize, 6:Bolivia, 7:Brazil, 8:Canada, 9:Chile,
|
|
|
|
10:Colombia, 11:Costa Rica, 12:Czech Republic, 13:Denmark, 14:Dominican Republic, 15:Ecuador,
|
|
|
|
16:El Salvador, 17:France, 18:Germany, 19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland,
|
|
|
|
23:Italy, 24:Jamaica, 25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands,
|
|
|
|
30:New Zealand, 31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal, 36:Peoples Republic of China,
|
|
|
|
37:Puerto Rico, 38:Russia, 39:Singapore, 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland,
|
|
|
|
44:Taiwan, 45:Trinidad, 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.
|
|
|
|
|
|
|
|
**Other Video Preferences**
|
|
|
|
|
|
|
|
* **agent** (str): com.plexapp.agents.none, com.plexapp.agents.imdb, com.plexapp.agents.themoviedb
|
|
|
|
* **enableBIFGeneration** (bool): Enable video preview thumbnails. Default value true.
|
|
|
|
* **enableCinemaTrailers** (bool): Enable Cinema Trailers. Default value true.
|
|
|
|
* **includeInGlobal** (bool): Include in dashboard. Default value true.
|
|
|
|
* **scanner** (str): Plex Movie Scanner, Plex Video Files Scanner
|
|
|
|
|
|
|
|
**IMDB Other Video Options** (com.plexapp.agents.imdb)
|
|
|
|
|
|
|
|
* **title** (bool): Localized titles. Default value false.
|
|
|
|
* **extras** (bool): Find trailers and extras automatically (Plex Pass required). Default value true.
|
|
|
|
* **only_trailers** (bool): Skip extras which aren't trailers. Default value false.
|
|
|
|
* **redband** (bool): Use red band (restricted audiences) trailers when available. Default value false.
|
|
|
|
* **native_subs** (bool): Include extras with subtitles in Library language. Default value false.
|
|
|
|
* **cast_list** (int): Cast List Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.
|
|
|
|
* **ratings** (int): Ratings Source Default value 0 Possible options:
|
|
|
|
0:Rotten Tomatoes,1:IMDb,2:The Movie Database.
|
|
|
|
* **summary** (int): Plot Summary Source: Default value 1 Possible options: 0:IMDb,1:The Movie Database.
|
|
|
|
* **country** (int): Country: Default value 46 Possible options: 0:Argentina, 1:Australia, 2:Austria,
|
|
|
|
3:Belgium, 4:Belize, 5:Bolivia, 6:Brazil, 7:Canada, 8:Chile, 9:Colombia, 10:Costa Rica, 11:Czech Republic,
|
|
|
|
12:Denmark, 13:Dominican Republic, 14:Ecuador, 15:El Salvador, 16:France, 17:Germany, 18:Guatemala,
|
|
|
|
19:Honduras, 20:Hong Kong SAR, 21:Ireland, 22:Italy, 23:Jamaica, 24:Korea, 25:Liechtenstein,
|
|
|
|
26:Luxembourg, 27:Mexico, 28:Netherlands, 29:New Zealand, 30:Nicaragua, 31:Panama, 32:Paraguay,
|
|
|
|
33:Peru, 34:Portugal, 35:Peoples Republic of China, 36:Puerto Rico, 37:Russia, 38:Singapore,
|
|
|
|
39:South Africa, 40:Spain, 41:Sweden, 42:Switzerland, 43:Taiwan, 44:Trinidad, 45:United Kingdom,
|
|
|
|
46:United States, 47:Uruguay, 48:Venezuela.
|
|
|
|
* **collections** (bool): Use collection info from The Movie Database. Default value false.
|
|
|
|
* **localart** (bool): Prefer artwork based on library language. Default value true.
|
|
|
|
* **adult** (bool): Include adult content. Default value false.
|
|
|
|
* **usage** (bool): Send anonymous usage data to Plex. Default value true.
|
|
|
|
|
|
|
|
**TheMovieDB Other Video Options** (com.plexapp.agents.themoviedb)
|
|
|
|
|
|
|
|
* **collections** (bool): Use collection info from The Movie Database. Default value false.
|
|
|
|
* **localart** (bool): Prefer artwork based on library language. Default value true.
|
|
|
|
* **adult** (bool): Include adult content. Default value false.
|
|
|
|
* **country** (int): Country (used for release date and content rating). Default
|
|
|
|
value 47 Possible options 0:, 1:Argentina, 2:Australia, 3:Austria, 4:Belgium, 5:Belize,
|
|
|
|
6:Bolivia, 7:Brazil, 8:Canada, 9:Chile, 10:Colombia, 11:Costa Rica, 12:Czech Republic,
|
|
|
|
13:Denmark, 14:Dominican Republic, 15:Ecuador, 16:El Salvador, 17:France, 18:Germany,
|
|
|
|
19:Guatemala, 20:Honduras, 21:Hong Kong SAR, 22:Ireland, 23:Italy, 24:Jamaica,
|
|
|
|
25:Korea, 26:Liechtenstein, 27:Luxembourg, 28:Mexico, 29:Netherlands, 30:New Zealand,
|
|
|
|
31:Nicaragua, 32:Panama, 33:Paraguay, 34:Peru, 35:Portugal,
|
|
|
|
36:Peoples Republic of China, 37:Puerto Rico, 38:Russia, 39:Singapore,
|
|
|
|
40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad,
|
|
|
|
46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.
|
2017-02-27 12:23:35 +00:00
|
|
|
"""
|
2017-02-27 21:04:37 +00:00
|
|
|
part = '/library/sections?name=%s&type=%s&agent=%s&scanner=%s&language=%s&location=%s' % (
|
2017-04-23 05:18:53 +00:00
|
|
|
quote_plus(name), type, agent, quote_plus(scanner), language, quote_plus(location)) # noqa E126
|
2017-02-27 21:04:37 +00:00
|
|
|
if kwargs:
|
2017-02-27 12:23:35 +00:00
|
|
|
part += urlencode(kwargs)
|
2017-02-27 21:04:37 +00:00
|
|
|
return self._server.query(part, method=self._server._session.post)
|
2017-02-27 12:23:35 +00:00
|
|
|
|
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
class LibrarySection(PlexObject):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Base class for a single library section.
|
|
|
|
|
|
|
|
Attributes:
|
2017-02-14 04:32:27 +00:00
|
|
|
ALLOWED_FILTERS (tuple): ()
|
|
|
|
ALLOWED_SORT (tuple): ()
|
|
|
|
BOOLEAN_FILTERS (tuple<str>): ('unwatched', 'duplicate')
|
2017-01-26 04:21:13 +00:00
|
|
|
server (:class:`~plexapi.server.PlexServer`): Server this client is connected to.
|
|
|
|
initpath (str): Path requested when building this object.
|
|
|
|
agent (str): Unknown (com.plexapp.agents.imdb, etc)
|
|
|
|
allowSync (bool): True if you allow syncing content from this section.
|
|
|
|
art (str): Wallpaper artwork used to respresent this section.
|
|
|
|
composite (str): Composit image used to represent this section.
|
|
|
|
createdAt (datetime): Datetime this library section was created.
|
|
|
|
filters (str): Unknown
|
|
|
|
key (str): Key (or ID) of this library section.
|
|
|
|
language (str): Language represented in this section (en, xn, etc).
|
|
|
|
locations (str): Paths on disk where section content is stored.
|
|
|
|
refreshing (str): True if this section is currently being refreshed.
|
|
|
|
scanner (str): Internal scanner used to find media (Plex Movie Scanner, Plex Premium Music Scanner, etc.)
|
|
|
|
thumb (str): Thumbnail image used to represent this section.
|
|
|
|
title (str): Title of this section.
|
|
|
|
type (str): Type of content section represents (movie, artist, photo, show).
|
|
|
|
updatedAt (datetime): Datetime this library section was last updated.
|
|
|
|
uuid (str): Unique id for this section (32258d7c-3e6c-4ac5-98ad-bad7a3b78c63)
|
|
|
|
"""
|
2016-03-31 20:52:48 +00:00
|
|
|
ALLOWED_FILTERS = ()
|
|
|
|
ALLOWED_SORT = ()
|
|
|
|
BOOLEAN_FILTERS = ('unwatched', 'duplicate')
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
def _loadData(self, data):
|
2017-02-04 08:08:47 +00:00
|
|
|
self._data = data
|
2016-04-12 02:43:21 +00:00
|
|
|
self.agent = data.attrib.get('agent')
|
|
|
|
self.allowSync = utils.cast(bool, data.attrib.get('allowSync'))
|
|
|
|
self.art = data.attrib.get('art')
|
|
|
|
self.composite = data.attrib.get('composite')
|
|
|
|
self.createdAt = utils.toDatetime(data.attrib.get('createdAt'))
|
|
|
|
self.filters = data.attrib.get('filters')
|
2017-02-06 04:52:10 +00:00
|
|
|
self.key = data.attrib.get('key') # invalid key from plex
|
2014-12-29 03:21:58 +00:00
|
|
|
self.language = data.attrib.get('language')
|
2017-02-13 03:15:47 +00:00
|
|
|
self.locations = self.listAttrs(data, 'path', etag='Location')
|
2016-04-12 02:43:21 +00:00
|
|
|
self.refreshing = utils.cast(bool, data.attrib.get('refreshing'))
|
|
|
|
self.scanner = data.attrib.get('scanner')
|
|
|
|
self.thumb = data.attrib.get('thumb')
|
|
|
|
self.title = data.attrib.get('title')
|
|
|
|
self.type = data.attrib.get('type')
|
|
|
|
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt'))
|
|
|
|
self.uuid = data.attrib.get('uuid')
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-02-10 23:16:23 +00:00
|
|
|
def delete(self):
|
2017-03-22 03:04:23 +00:00
|
|
|
""" Delete a library section. """
|
2017-02-10 23:16:23 +00:00
|
|
|
try:
|
|
|
|
return self._server.query('/library/sections/%s' % self.key, method=self._server._session.delete)
|
2017-02-10 23:16:34 +00:00
|
|
|
except BadRequest: # pragma: no cover
|
2017-02-13 03:38:56 +00:00
|
|
|
msg = 'Failed to delete library %s' % self.key
|
|
|
|
msg += 'You may need to allow this permission in your Plex settings.'
|
|
|
|
log.error(msg)
|
2017-02-10 23:16:23 +00:00
|
|
|
raise
|
2017-02-08 07:00:43 +00:00
|
|
|
|
2017-02-27 21:04:37 +00:00
|
|
|
def edit(self, **kwargs):
|
2017-04-23 05:18:53 +00:00
|
|
|
""" Edit a library (Note: agent is required). See :class:`~plexapi.library.Library` for example usage.
|
2017-03-22 03:04:23 +00:00
|
|
|
|
|
|
|
Parameters:
|
|
|
|
kwargs (dict): Dict of settings to edit.
|
2017-02-27 21:04:37 +00:00
|
|
|
"""
|
2017-02-27 22:20:10 +00:00
|
|
|
part = '/library/sections/%s?%s' % (self.key, urlencode(kwargs))
|
2017-02-27 22:16:02 +00:00
|
|
|
self._server.query(part, method=self._server._session.put)
|
2017-02-27 22:20:10 +00:00
|
|
|
|
2017-02-27 22:16:02 +00:00
|
|
|
# Reload this way since the self.key dont have a full path, but is simply a id.
|
|
|
|
for s in self._server.library.sections():
|
|
|
|
if s.key == self.key:
|
|
|
|
return s
|
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
def get(self, title):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns the media item with the specified title.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
title (str): Title of the item to return.
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
key = '/library/sections/%s/all' % self.key
|
2017-02-09 06:54:38 +00:00
|
|
|
return self.fetchItem(key, title__iexact=title)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-02-09 04:08:25 +00:00
|
|
|
def all(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of media from this library section. """
|
2017-02-06 04:52:10 +00:00
|
|
|
key = '/library/sections/%s/all' % self.key
|
2017-02-09 04:08:25 +00:00
|
|
|
return self.fetchItems(key, **kwargs)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def onDeck(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of media items on deck from this library section. """
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/onDeck' % self.key
|
|
|
|
return self.fetchItems(key)
|
2016-05-24 01:41:02 +00:00
|
|
|
|
|
|
|
def recentlyAdded(self, maxresults=50):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of media items recently added from this library section.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Parameters:
|
|
|
|
maxresults (int): Max number of items to return (default 50).
|
|
|
|
"""
|
2016-05-24 01:41:02 +00:00
|
|
|
return self.search(sort='addedAt:desc', maxresults=maxresults)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-04-01 03:39:09 +00:00
|
|
|
def analyze(self):
|
2017-02-09 20:01:23 +00:00
|
|
|
""" Run an analysis on all of the items in this library section. See
|
|
|
|
See :func:`~plexapi.base.PlexPartialObject.analyze` for more details.
|
|
|
|
"""
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/analyze' % self.key
|
2017-02-09 04:29:17 +00:00
|
|
|
self._server.query(key, method=self._server._session.put)
|
2016-04-01 03:39:09 +00:00
|
|
|
|
|
|
|
def emptyTrash(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" If a section has items in the Trash, use this option to empty the Trash. """
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/emptyTrash' % self.key
|
2017-02-09 04:29:17 +00:00
|
|
|
self._server.query(key)
|
2016-04-01 03:39:09 +00:00
|
|
|
|
2017-02-14 22:36:21 +00:00
|
|
|
def update(self):
|
2017-02-15 04:22:57 +00:00
|
|
|
""" Scan this section for new media. """
|
2017-02-14 22:36:21 +00:00
|
|
|
key = '/library/sections/%s/refresh' % self.key
|
|
|
|
self._server.query(key)
|
|
|
|
|
|
|
|
def cancelUpdate(self):
|
2017-02-15 04:22:57 +00:00
|
|
|
""" Cancel update of this Library Section. """
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/refresh' % self.key
|
2017-02-14 22:36:21 +00:00
|
|
|
self._server.query(key, method=self._server._session.delete)
|
|
|
|
|
|
|
|
def refresh(self):
|
2017-02-15 04:22:57 +00:00
|
|
|
""" Forces a download of fresh media information from the internet.
|
|
|
|
This can take a long time. Any locked fields are not modified.
|
|
|
|
"""
|
2017-02-14 22:36:21 +00:00
|
|
|
key = '/library/sections/%s/refresh?force=1' % self.key
|
2017-02-09 04:29:17 +00:00
|
|
|
self._server.query(key)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2017-02-20 03:51:17 +00:00
|
|
|
def deleteMediaPreviews(self):
|
|
|
|
""" Delete the preview thumbnails for items in this library. This cannot
|
|
|
|
be undone. Recreating media preview files can take hours or even days.
|
2017-02-18 21:12:43 +00:00
|
|
|
"""
|
|
|
|
key = '/library/sections/%s/indexes' % self.key
|
|
|
|
self._server.query(key, method=self._server._session.delete)
|
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def listChoices(self, category, libtype=None, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of :class:`~plexapi.library.FilterChoice` objects for the
|
|
|
|
specified category and libtype. kwargs can be any of the same kwargs in
|
|
|
|
:func:`plexapi.library.LibraySection.search()` to help narrow down the choices
|
|
|
|
to only those that matter in your current context.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
category (str): Category to list choices for (genre, contentRating, etc).
|
|
|
|
libtype (int): Library type of item filter.
|
|
|
|
**kwargs (dict): Additional kwargs to narrow down the choices.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
:class:`~plexapi.exceptions.BadRequest`: Cannot include kwarg equal to specified category.
|
2014-12-29 03:21:58 +00:00
|
|
|
"""
|
2017-02-07 06:20:49 +00:00
|
|
|
# TODO: Should this be moved to base?
|
2016-03-31 20:52:48 +00:00
|
|
|
if category in kwargs:
|
2017-01-26 04:21:13 +00:00
|
|
|
raise BadRequest('Cannot include kwarg equal to specified category: %s' % category)
|
2014-12-29 03:21:58 +00:00
|
|
|
args = {}
|
2016-03-31 20:52:48 +00:00
|
|
|
for subcategory, value in kwargs.items():
|
|
|
|
args[category] = self._cleanSearchFilter(subcategory, value)
|
2016-12-15 23:06:12 +00:00
|
|
|
if libtype is not None:
|
|
|
|
args['type'] = utils.searchType(libtype)
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/%s%s' % (self.key, category, utils.joinArgs(args))
|
2017-02-13 02:55:55 +00:00
|
|
|
return self.fetchItems(key, cls=FilterChoice)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-03-06 22:18:10 +00:00
|
|
|
def share(self, user, **kwargs):
|
2017-03-22 03:04:23 +00:00
|
|
|
""" Share this library with the user.
|
2017-03-06 22:18:10 +00:00
|
|
|
|
2017-03-22 03:04:23 +00:00
|
|
|
Parameters:
|
|
|
|
user (str): username as a string or :class:`~plexapi.myplex.MyPlexUser`
|
|
|
|
kwargs (dict): Shared settings should be passed as kwargs.
|
|
|
|
# TODO: So im not really sure where is belongs but it works. still need docs for kwargs.
|
2017-03-06 22:18:10 +00:00
|
|
|
"""
|
|
|
|
# Allow passing a User
|
|
|
|
if isinstance(user, type):
|
|
|
|
user = user.username
|
|
|
|
# Grab the section ids, note this is NOT the same as the regular that the library has.
|
|
|
|
uri = 'https://plex.tv/api/servers/%s?X-Plex-Token=%s' % (self._server.machineIdentifier, self._server._token)
|
|
|
|
server = self._server.query(uri)
|
|
|
|
library_section_ids = [section.attrib.get('id') for section in server
|
2017-03-22 03:04:23 +00:00
|
|
|
if section.attrib.get('title') == self.title]
|
|
|
|
cmd = {
|
|
|
|
'shared_id': self._server.machineIdentifier,
|
|
|
|
'shared_server': {
|
|
|
|
'library_section_ids': library_section_ids,
|
|
|
|
'invited_email': user
|
|
|
|
},
|
|
|
|
'sharing_settings': kwargs # empty means none
|
|
|
|
}
|
2017-03-06 22:18:10 +00:00
|
|
|
# Json content type seems to be req.
|
2017-03-22 03:04:23 +00:00
|
|
|
headers = {"Content-Type": "application/json"}
|
2017-03-06 22:18:10 +00:00
|
|
|
share_uri = 'https://plex.tv/api/servers/%s/shared_servers?X-Plex-Token=%s' % (
|
2017-03-22 03:04:23 +00:00
|
|
|
self._server.machineIdentifier, self._server._token)
|
|
|
|
self._server._session.post(share_uri, json=cmd, headers=headers)
|
2017-03-06 22:18:10 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def search(self, title=None, sort=None, maxresults=999999, libtype=None, **kwargs):
|
|
|
|
""" Search the library. If there are many results, they will be fetched from the server
|
|
|
|
in batches of X_PLEX_CONTAINER_SIZE amounts. If you're only looking for the first <num>
|
|
|
|
results, it would be wise to set the maxresults option to that amount so this functions
|
|
|
|
doesn't iterate over all results on the server.
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Parameters:
|
|
|
|
title (str): General string query to search for (optional).
|
|
|
|
sort (str): column:dir; column can be any of {addedAt, originallyAvailableAt, lastViewedAt,
|
|
|
|
titleSort, rating, mediaHeight, duration}. dir can be asc or desc (optional).
|
|
|
|
maxresults (int): Only return the specified number of results (optional).
|
2017-02-20 05:37:00 +00:00
|
|
|
libtype (str): Filter results to a spcifiec libtype (movie, show, episode, artist,
|
|
|
|
album, track; optional).
|
2017-01-26 04:21:13 +00:00
|
|
|
**kwargs (dict): Any of the available filters for the current library section. Partial string
|
2016-12-15 23:06:12 +00:00
|
|
|
matches allowed. Multiple matches OR together. All inputs will be compared with the
|
|
|
|
available options and a warning logged if the option does not appear valid.
|
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
* unwatched: Display or hide unwatched content (True, False). [all]
|
|
|
|
* duplicate: Display or hide duplicate items (True, False). [movie]
|
|
|
|
* actor: List of actors to search ([actor_or_id, ...]). [movie]
|
|
|
|
* collection: List of collections to search within ([collection_or_id, ...]). [all]
|
|
|
|
* contentRating: List of content ratings to search within ([rating_or_key, ...]). [movie,tv]
|
|
|
|
* country: List of countries to search within ([country_or_key, ...]). [movie,music]
|
|
|
|
* decade: List of decades to search within ([yyy0, ...]). [movie]
|
|
|
|
* director: List of directors to search ([director_or_id, ...]). [movie]
|
|
|
|
* genre: List Genres to search within ([genere_or_id, ...]). [all]
|
|
|
|
* network: List of TV networks to search within ([resolution_or_key, ...]). [tv]
|
|
|
|
* resolution: List of video resolutions to search within ([resolution_or_key, ...]). [movie]
|
|
|
|
* studio: List of studios to search within ([studio_or_key, ...]). [music]
|
|
|
|
* year: List of years to search within ([yyyy, ...]). [all]
|
2016-03-31 20:52:48 +00:00
|
|
|
"""
|
2017-02-07 06:20:49 +00:00
|
|
|
# cleanup the core arguments
|
2016-03-31 20:52:48 +00:00
|
|
|
args = {}
|
|
|
|
for category, value in kwargs.items():
|
|
|
|
args[category] = self._cleanSearchFilter(category, value, libtype)
|
2016-12-15 23:06:12 +00:00
|
|
|
if title is not None:
|
|
|
|
args['title'] = title
|
|
|
|
if sort is not None:
|
|
|
|
args['sort'] = self._cleanSearchSort(sort)
|
|
|
|
if libtype is not None:
|
|
|
|
args['type'] = utils.searchType(libtype)
|
2017-02-07 06:20:49 +00:00
|
|
|
# iterate over the results
|
2016-03-31 20:52:48 +00:00
|
|
|
results, subresults = [], '_init'
|
|
|
|
args['X-Plex-Container-Start'] = 0
|
|
|
|
args['X-Plex-Container-Size'] = min(X_PLEX_CONTAINER_SIZE, maxresults)
|
|
|
|
while subresults and maxresults > len(results):
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/all%s' % (self.key, utils.joinArgs(args))
|
|
|
|
subresults = self.fetchItems(key)
|
2016-12-15 23:06:12 +00:00
|
|
|
results += subresults[:maxresults - len(results)]
|
2016-03-31 20:52:48 +00:00
|
|
|
args['X-Plex-Container-Start'] += args['X-Plex-Container-Size']
|
|
|
|
return results
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def _cleanSearchFilter(self, category, value, libtype=None):
|
2016-03-31 22:36:54 +00:00
|
|
|
# check a few things before we begin
|
2016-03-31 20:52:48 +00:00
|
|
|
if category not in self.ALLOWED_FILTERS:
|
|
|
|
raise BadRequest('Unknown filter category: %s' % category)
|
|
|
|
if category in self.BOOLEAN_FILTERS:
|
|
|
|
return '1' if value else '0'
|
|
|
|
if not isinstance(value, (list, tuple)):
|
|
|
|
value = [value]
|
2017-02-08 07:00:43 +00:00
|
|
|
|
2016-03-31 22:36:54 +00:00
|
|
|
# convert list of values to list of keys or ids
|
|
|
|
result = set()
|
2016-03-31 20:52:48 +00:00
|
|
|
choices = self.listChoices(category, libtype)
|
2016-12-15 23:06:12 +00:00
|
|
|
lookup = {c.title.lower(): unquote(unquote(c.key)) for c in choices}
|
2016-03-31 20:52:48 +00:00
|
|
|
allowed = set(c.key for c in choices)
|
2016-03-31 22:36:54 +00:00
|
|
|
for item in value:
|
2017-02-08 07:00:43 +00:00
|
|
|
item = str((item.id or item.tag) if isinstance(item, MediaTag) else item).lower()
|
2016-03-31 22:36:54 +00:00
|
|
|
# find most logical choice(s) to use in url
|
2017-02-07 06:20:49 +00:00
|
|
|
if item in allowed: result.add(item); continue
|
|
|
|
if item in lookup: result.add(lookup[item]); continue
|
2016-12-15 23:06:12 +00:00
|
|
|
matches = [k for t, k in lookup.items() if item in t]
|
2017-02-07 06:20:49 +00:00
|
|
|
if matches: map(result.add, matches); continue
|
2016-03-31 22:36:54 +00:00
|
|
|
# nothing matched; use raw item value
|
2017-01-26 04:21:13 +00:00
|
|
|
log.warning('Filter value not listed, using raw item value: %s' % item)
|
2016-05-24 01:41:02 +00:00
|
|
|
result.add(item)
|
2016-03-31 20:52:48 +00:00
|
|
|
return ','.join(result)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def _cleanSearchSort(self, sort):
|
|
|
|
sort = '%s:asc' % sort if ':' not in sort else sort
|
|
|
|
scol, sdir = sort.lower().split(':')
|
2016-12-15 23:06:12 +00:00
|
|
|
lookup = {s.lower(): s for s in self.ALLOWED_SORT}
|
2016-03-31 20:52:48 +00:00
|
|
|
if scol not in lookup:
|
|
|
|
raise BadRequest('Unknown sort column: %s' % scol)
|
|
|
|
if sdir not in ('asc', 'desc'):
|
|
|
|
raise BadRequest('Unknown sort dir: %s' % sdir)
|
|
|
|
return '%s:%s' % (lookup[scol], sdir)
|
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
class MovieSection(LibrarySection):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Represents a :class:`~plexapi.library.LibrarySection` section containing movies.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Attributes:
|
|
|
|
ALLOWED_FILTERS (list<str>): List of allowed search filters. ('unwatched',
|
|
|
|
'duplicate', 'year', 'decade', 'genre', 'contentRating', 'collection',
|
|
|
|
'director', 'actor', 'country', 'studio', 'resolution')
|
|
|
|
ALLOWED_SORT (list<str>): List of allowed sorting keys. ('addedAt',
|
|
|
|
'originallyAvailableAt', 'lastViewedAt', 'titleSort', 'rating',
|
|
|
|
'mediaHeight', 'duration')
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG (str): 'Directory'
|
2017-01-26 04:21:13 +00:00
|
|
|
TYPE (str): 'movie'
|
|
|
|
"""
|
|
|
|
ALLOWED_FILTERS = ('unwatched', 'duplicate', 'year', 'decade', 'genre', 'contentRating',
|
2017-03-06 22:18:10 +00:00
|
|
|
'collection', 'director', 'actor', 'country', 'studio', 'resolution')
|
2016-03-31 20:52:48 +00:00
|
|
|
ALLOWED_SORT = ('addedAt', 'originallyAvailableAt', 'lastViewedAt', 'titleSort', 'rating',
|
2017-03-06 22:18:10 +00:00
|
|
|
'mediaHeight', 'duration')
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Directory'
|
2014-12-29 03:21:58 +00:00
|
|
|
TYPE = 'movie'
|
|
|
|
|
|
|
|
|
|
|
|
class ShowSection(LibrarySection):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Represents a :class:`~plexapi.library.LibrarySection` section containing tv shows.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Attributes:
|
|
|
|
ALLOWED_FILTERS (list<str>): List of allowed search filters. ('unwatched',
|
|
|
|
'year', 'genre', 'contentRating', 'network', 'collection')
|
|
|
|
ALLOWED_SORT (list<str>): List of allowed sorting keys. ('addedAt', 'lastViewedAt',
|
|
|
|
'originallyAvailableAt', 'titleSort', 'rating', 'unwatched')
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG (str): 'Directory'
|
2017-01-26 04:21:13 +00:00
|
|
|
TYPE (str): 'show'
|
|
|
|
"""
|
|
|
|
ALLOWED_FILTERS = ('unwatched', 'year', 'genre', 'contentRating', 'network', 'collection')
|
|
|
|
ALLOWED_SORT = ('addedAt', 'lastViewedAt', 'originallyAvailableAt', 'titleSort',
|
2017-03-06 22:18:10 +00:00
|
|
|
'rating', 'unwatched')
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Directory'
|
2014-12-29 03:21:58 +00:00
|
|
|
TYPE = 'show'
|
2015-06-08 16:41:47 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def searchShows(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for a show. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2016-03-31 20:52:48 +00:00
|
|
|
return self.search(libtype='show', **kwargs)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def searchEpisodes(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for an episode. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2016-03-31 20:52:48 +00:00
|
|
|
return self.search(libtype='episode', **kwargs)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2016-05-24 01:41:02 +00:00
|
|
|
def recentlyAdded(self, libtype='episode', maxresults=50):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of recently added episodes from this library section.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Parameters:
|
|
|
|
maxresults (int): Max number of items to return (default 50).
|
|
|
|
"""
|
2016-05-24 01:41:02 +00:00
|
|
|
return self.search(sort='addedAt:desc', libtype=libtype, maxresults=maxresults)
|
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2016-01-19 09:41:12 +00:00
|
|
|
class MusicSection(LibrarySection):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Represents a :class:`~plexapi.library.LibrarySection` section containing music artists.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Attributes:
|
|
|
|
ALLOWED_FILTERS (list<str>): List of allowed search filters. ('genre',
|
|
|
|
'country', 'collection')
|
|
|
|
ALLOWED_SORT (list<str>): List of allowed sorting keys. ('addedAt',
|
|
|
|
'lastViewedAt', 'viewCount', 'titleSort')
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG (str): 'Directory'
|
2017-01-26 04:21:13 +00:00
|
|
|
TYPE (str): 'artist'
|
|
|
|
"""
|
2016-03-31 20:52:48 +00:00
|
|
|
ALLOWED_FILTERS = ('genre', 'country', 'collection')
|
|
|
|
ALLOWED_SORT = ('addedAt', 'lastViewedAt', 'viewCount', 'titleSort')
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Directory'
|
2016-01-19 09:41:12 +00:00
|
|
|
TYPE = 'artist'
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-04-13 02:47:46 +00:00
|
|
|
def albums(self):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Returns a list of :class:`~plexapi.audio.Album` objects in this section. """
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/albums' % self.key
|
|
|
|
return self.fetchItems(key)
|
2016-04-13 02:47:46 +00:00
|
|
|
|
2016-04-10 03:59:47 +00:00
|
|
|
def searchArtists(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for an artist. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2016-03-31 20:52:48 +00:00
|
|
|
return self.search(libtype='artist', **kwargs)
|
2016-01-19 09:41:12 +00:00
|
|
|
|
2016-04-10 03:59:47 +00:00
|
|
|
def searchAlbums(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for an album. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2016-03-31 20:52:48 +00:00
|
|
|
return self.search(libtype='album', **kwargs)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2016-03-31 20:52:48 +00:00
|
|
|
def searchTracks(self, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for a track. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2016-03-31 20:52:48 +00:00
|
|
|
return self.search(libtype='track', **kwargs)
|
2016-01-19 09:41:12 +00:00
|
|
|
|
|
|
|
|
2016-04-10 03:59:47 +00:00
|
|
|
class PhotoSection(LibrarySection):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Represents a :class:`~plexapi.library.LibrarySection` section containing photos.
|
2017-01-31 00:02:22 +00:00
|
|
|
|
2017-01-26 04:21:13 +00:00
|
|
|
Attributes:
|
2017-02-13 02:55:55 +00:00
|
|
|
ALLOWED_FILTERS (list<str>): List of allowed search filters. ('all', 'iso',
|
|
|
|
'make', 'lens', 'aperture', 'exposure')
|
|
|
|
ALLOWED_SORT (list<str>): List of allowed sorting keys. ('addedAt')
|
|
|
|
TAG (str): 'Directory'
|
2017-01-26 04:21:13 +00:00
|
|
|
TYPE (str): 'photo'
|
|
|
|
"""
|
2017-01-31 00:02:22 +00:00
|
|
|
ALLOWED_FILTERS = ('all', 'iso', 'make', 'lens', 'aperture', 'exposure')
|
2017-02-13 02:55:55 +00:00
|
|
|
ALLOWED_SORT = ('addedAt',)
|
|
|
|
TAG = 'Directory'
|
2016-04-10 03:59:47 +00:00
|
|
|
TYPE = 'photo'
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2017-02-07 06:20:49 +00:00
|
|
|
def searchAlbums(self, title, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for an album. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/all?type=14' % self.key
|
|
|
|
return self.fetchItems(key, title=title)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
2017-01-31 00:02:22 +00:00
|
|
|
def searchPhotos(self, title, **kwargs):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Search for a photo. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
|
2017-02-07 06:20:49 +00:00
|
|
|
key = '/library/sections/%s/all?type=13' % self.key
|
|
|
|
return self.fetchItems(key, title=title)
|
2017-01-03 22:58:35 +00:00
|
|
|
|
|
|
|
|
2017-02-07 06:20:49 +00:00
|
|
|
class FilterChoice(PlexObject):
|
2017-01-26 04:21:13 +00:00
|
|
|
""" Represents a single filter choice. These objects are gathered when using filters
|
|
|
|
while searching for library items and is the object returned in the result set of
|
|
|
|
:func:`~plexapi.library.LibrarySection.listChoices()`.
|
|
|
|
|
|
|
|
Attributes:
|
2017-02-14 04:32:27 +00:00
|
|
|
TAG (str): 'Directory'
|
2017-01-26 04:21:13 +00:00
|
|
|
server (:class:`~plexapi.server.PlexServer`): PlexServer this client is connected to.
|
|
|
|
initpath (str): Relative path requested when retrieving specified `data` (optional).
|
|
|
|
fastKey (str): API path to quickly list all items in this filter
|
|
|
|
(/library/sections/<section>/all?genre=<key>)
|
|
|
|
key (str): Short key (id) of this filter option (used ad <key> in fastKey above).
|
2017-01-31 00:02:22 +00:00
|
|
|
thumb (str): Thumbnail used to represent this filter option.
|
2017-01-26 04:21:13 +00:00
|
|
|
title (str): Human readable name for this filter option.
|
|
|
|
type (str): Filter type (genre, contentRating, etc).
|
|
|
|
"""
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Directory'
|
2016-01-19 09:41:12 +00:00
|
|
|
|
2017-02-07 06:20:49 +00:00
|
|
|
def _loadData(self, data):
|
2017-02-14 04:32:27 +00:00
|
|
|
""" Load attribute values from Plex XML response. """
|
2017-02-04 08:08:47 +00:00
|
|
|
self._data = data
|
2016-03-31 20:52:48 +00:00
|
|
|
self.fastKey = data.attrib.get('fastKey')
|
|
|
|
self.key = data.attrib.get('key')
|
2016-03-31 22:36:54 +00:00
|
|
|
self.thumb = data.attrib.get('thumb')
|
2016-03-31 20:52:48 +00:00
|
|
|
self.title = data.attrib.get('title')
|
2016-03-31 22:36:54 +00:00
|
|
|
self.type = data.attrib.get('type')
|
2016-01-19 09:41:12 +00:00
|
|
|
|
2017-02-07 06:20:49 +00:00
|
|
|
|
2017-02-13 02:55:55 +00:00
|
|
|
@utils.registerPlexObject
|
2017-02-07 06:20:49 +00:00
|
|
|
class Hub(PlexObject):
|
2017-02-14 04:32:27 +00:00
|
|
|
""" Represents a single Hub (or category) in the PlexServer search.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
TAG (str): 'Hub'
|
|
|
|
hubIdentifier (str): Unknown.
|
|
|
|
size (int): Number of items found.
|
|
|
|
title (str): Title of this Hub.
|
|
|
|
type (str): Type of items in the Hub.
|
|
|
|
items (str): List of items in the Hub.
|
|
|
|
"""
|
2017-02-13 02:55:55 +00:00
|
|
|
TAG = 'Hub'
|
2017-02-07 06:20:49 +00:00
|
|
|
|
|
|
|
def _loadData(self, data):
|
2017-02-14 04:32:27 +00:00
|
|
|
""" Load attribute values from Plex XML response. """
|
2017-02-07 06:20:49 +00:00
|
|
|
self._data = data
|
|
|
|
self.hubIdentifier = data.attrib.get('hubIdentifier')
|
|
|
|
self.size = utils.cast(int, data.attrib.get('size'))
|
|
|
|
self.title = data.attrib.get('title')
|
|
|
|
self.type = data.attrib.get('type')
|
2017-02-13 02:55:55 +00:00
|
|
|
self.items = self.findItems(data)
|
2017-02-07 06:20:49 +00:00
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.size
|