Skip to content

Commit

Permalink
Add ability to exclude keywords from what the sensor adds to itself (#45
Browse files Browse the repository at this point in the history
)

* Add exclude keywords

* Add exclude_keywords to readme
  • Loading branch information
isabellaalstrom authored Jul 3, 2020
1 parent 67def37 commit e2b43ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Read through these two resources before posting issues to GitHub or the forums.
| ssl_cert | false | no | If you provide your own SSL certificate in Plex's network settings set this to true.
| section_types | movie, show | no | Allows you to specify which section types to consider [movie, show].
| 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.
| exclude_keywords | | no | Allows you to specify a list of keywords to be exclude from the sensor if in the title.

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

Expand Down Expand Up @@ -67,15 +68,18 @@ Read through these two resources before posting issues to GitHub or the forums.
host: !secret host
port: 32400
section_types:
- movie
- movie

- platform: plex_recently_added
name: Recently Added TV # will create sensor.recently_added_tv
token: !secret token
host: !secret host
port: 32400
section_types:
- show
- show
exclude_keywords:
- Walking dead
- kardashians
```
## \*Currently genres, rating, and studio only work for Movies
Expand Down
12 changes: 11 additions & 1 deletion custom_components/plex_recently_added/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async def request(url, self, content=False, ssl=False):
CONF_MAX = 'max'
CONF_IMG_CACHE = 'img_dir'
CONF_SECTION_TYPES = 'section_types'
CONF_EXCLUDE_KEYWORDS = 'exclude_keywords'
CONF_RESOLUTION = 'image_resolution'
CONF_ON_DECK = 'on_deck'

Expand All @@ -68,6 +69,8 @@ async def request(url, self, content=False, ssl=False):
vol.Optional(CONF_PORT, default=32400): cv.port,
vol.Optional(CONF_SECTION_TYPES,
default=['movie', 'show']): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_EXCLUDE_KEYWORDS):
vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_RESOLUTION, default=200): cv.positive_int,
vol.Optional(CONF_IMG_CACHE,
default='/upcoming-media-card-images/plex/'): cv.string
Expand Down Expand Up @@ -100,6 +103,7 @@ def __init__(self, hass, conf, name):
self.dl_images = conf.get(CONF_DL_IMAGES)
self.on_deck = conf.get(CONF_ON_DECK)
self.sections = conf.get(CONF_SECTION_TYPES)
self.excludes = conf.get(CONF_EXCLUDE_KEYWORDS)
self.resolution = conf.get(CONF_RESOLUTION)
if self.server_name:
_LOGGER.warning(
Expand Down Expand Up @@ -215,7 +219,13 @@ def device_state_attributes(self):
False, poster, self.resolution)
card_item['fanart'] = image_url(self,
False, fanart, self.resolution)
self.card_json.append(card_item)
should_add = True
if self.excludes:
for exclude in self.excludes:
if exclude.lower() in card_item['title'].lower():
should_add = False
if should_add:
self.card_json.append(card_item)
self.change_detected = False
attributes['data'] = self.card_json
return attributes
Expand Down

0 comments on commit e2b43ca

Please sign in to comment.