Skip to content

Commit 5caf3fc

Browse files
author
MKR
authored
Merge pull request #11 from fredrike/patch-1
Add support to configure sections.
2 parents 9d3de88 + 9dc3603 commit 5caf3fc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This component does not require, nor conflict with, the default Plex components.
2828
| download_images | true | no | Setting this to false will turn off downloading of images, but will require certain Plex settings to work. See below.
2929
| img_dir | '/custom-lovelace/upcoming-media-card/images/plex/' | no | This option allows you to choose a custom directory to store images in if you enable download_images.
3030
| ssl_cert | false | no | If you provide your own SSL certificate in Plex's network settings set this to true.
31+
| section_types | movie, show | no | Allows you to specify which section types to consider [movie, show].
3132

3233
#### By default this addon automatically downloads images from Plex to your /www/custom-lovelace/upcoming-media-card/ directory. The directory is automatically created & only images reported in the upcoming list are downloaded. Images are small in size and are removed automatically when no longer needed. Currently & unfortunately, this may not work on all systems.
3334

@@ -45,6 +46,9 @@ This component does not require, nor conflict with, the default Plex components.
4546
ssl_cert: false
4647
download_images: false
4748
max: 5
49+
section_types:
50+
- movie
51+
- show
4852

4953
### Sample for ui-lovelace.yaml:
5054

custom_components/sensor/plex_recently_added.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CONF_TOKEN = 'token'
2929
CONF_MAX = 'max'
3030
CONF_IMG_CACHE = 'img_dir'
31+
CONF_SECTION_TYPES = 'section_types'
3132

3233
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
3334
vol.Optional(CONF_SSL, default=False): cv.boolean,
@@ -38,6 +39,8 @@
3839
vol.Optional(CONF_DL_IMAGES, default=True): cv.boolean,
3940
vol.Optional(CONF_HOST, default='localhost'): cv.string,
4041
vol.Optional(CONF_PORT, default=32400): cv.port,
42+
vol.Optional(CONF_SECTION_TYPES,
43+
default=['movie', 'show']): vol.All(cv.ensure_list, [cv.string]),
4144
vol.Optional(CONF_IMG_CACHE,
4245
default='/custom-lovelace/upcoming-media-card/images/plex/'): cv.string
4346
})
@@ -63,6 +66,7 @@ def __init__(self, hass, conf):
6366
self.server_name = conf.get(CONF_SERVER)
6467
self.max_items = int(conf.get(CONF_MAX))
6568
self.dl_images = conf.get(CONF_DL_IMAGES)
69+
self.sections = conf.get(CONF_SECTION_TYPES)
6670
if self.server_name:
6771
self.server_ip, self.local_ip, self.port = get_server_ip(
6872
self.server_name, self.token)
@@ -197,7 +201,8 @@ def update(self):
197201
try:
198202
libraries = plex.get(all_libraries, headers=headers, timeout=10)
199203
for lib_section in libraries.json()['MediaContainer']['Directory']:
200-
sections.append(lib_section['key'])
204+
if lib_section['type'] in self.sections:
205+
sections.append(lib_section['key'])
201206
except OSError:
202207
_LOGGER.warning("Host %s is not available", self.server_ip)
203208
self._state = '%s cannot be reached' % self.server_ip
@@ -254,6 +259,9 @@ def update(self):
254259
elif media['type'] == 'episode':
255260
poster = media.get('grandparentThumb', '')
256261
fanart = media.get('grandparentArt', '')
262+
else:
263+
_LOGGER.error("Media type: %s", media['type'])
264+
continue
257265
poster_jpg = '{}p{}.jpg'.format(directory,
258266
media['ratingKey'])
259267
fanart_jpg = '{}f{}.jpg'.format(directory,

0 commit comments

Comments
 (0)