Skip to content

Commit e2b43ca

Browse files
Add ability to exclude keywords from what the sensor adds to itself (#45)
* Add exclude keywords * Add exclude_keywords to readme
1 parent 67def37 commit e2b43ca

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Read through these two resources before posting issues to GitHub or the forums.
3838
| ssl_cert | false | no | If you provide your own SSL certificate in Plex's network settings set this to true.
3939
| section_types | movie, show | no | Allows you to specify which section types to consider [movie, show].
4040
| image_resolution | 200 | no | Allows you to change the resolution of the generated images (in px), useful to display higher quality images as a background somewhere.
41+
| exclude_keywords | | no | Allows you to specify a list of keywords to be exclude from the sensor if in the title.
4142

4243
#### 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.
4344

@@ -67,15 +68,18 @@ Read through these two resources before posting issues to GitHub or the forums.
6768
host: !secret host
6869
port: 32400
6970
section_types:
70-
- movie
71+
- movie
7172

7273
- platform: plex_recently_added
7374
name: Recently Added TV # will create sensor.recently_added_tv
7475
token: !secret token
7576
host: !secret host
7677
port: 32400
7778
section_types:
78-
- show
79+
- show
80+
exclude_keywords:
81+
- Walking dead
82+
- kardashians
7983
```
8084
8185
## \*Currently genres, rating, and studio only work for Movies

custom_components/plex_recently_added/sensor.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async def request(url, self, content=False, ssl=False):
5252
CONF_MAX = 'max'
5353
CONF_IMG_CACHE = 'img_dir'
5454
CONF_SECTION_TYPES = 'section_types'
55+
CONF_EXCLUDE_KEYWORDS = 'exclude_keywords'
5556
CONF_RESOLUTION = 'image_resolution'
5657
CONF_ON_DECK = 'on_deck'
5758

@@ -68,6 +69,8 @@ async def request(url, self, content=False, ssl=False):
6869
vol.Optional(CONF_PORT, default=32400): cv.port,
6970
vol.Optional(CONF_SECTION_TYPES,
7071
default=['movie', 'show']): vol.All(cv.ensure_list, [cv.string]),
72+
vol.Optional(CONF_EXCLUDE_KEYWORDS):
73+
vol.All(cv.ensure_list, [cv.string]),
7174
vol.Optional(CONF_RESOLUTION, default=200): cv.positive_int,
7275
vol.Optional(CONF_IMG_CACHE,
7376
default='/upcoming-media-card-images/plex/'): cv.string
@@ -100,6 +103,7 @@ def __init__(self, hass, conf, name):
100103
self.dl_images = conf.get(CONF_DL_IMAGES)
101104
self.on_deck = conf.get(CONF_ON_DECK)
102105
self.sections = conf.get(CONF_SECTION_TYPES)
106+
self.excludes = conf.get(CONF_EXCLUDE_KEYWORDS)
103107
self.resolution = conf.get(CONF_RESOLUTION)
104108
if self.server_name:
105109
_LOGGER.warning(
@@ -215,7 +219,13 @@ def device_state_attributes(self):
215219
False, poster, self.resolution)
216220
card_item['fanart'] = image_url(self,
217221
False, fanart, self.resolution)
218-
self.card_json.append(card_item)
222+
should_add = True
223+
if self.excludes:
224+
for exclude in self.excludes:
225+
if exclude.lower() in card_item['title'].lower():
226+
should_add = False
227+
if should_add:
228+
self.card_json.append(card_item)
219229
self.change_detected = False
220230
attributes['data'] = self.card_json
221231
return attributes

0 commit comments

Comments
 (0)