iharosi / homebridge-plex-webhooks

Plex Webhooks Server plugin for Homebridge
GNU Affero General Public License v3.0
48 stars 5 forks source link

Matching Genres #30

Open Identifier opened 1 year ago

Identifier commented 1 year ago

Is your feature request related to a problem? Please describe. Currently I don't see a way to easily filter a sensor based on Genres. Plex provides the payload (see example below) but it provides multiple Genres instead of just a single one, but there's no way to filter on nested JSON elements in the payload.

Describe the solution you'd like I'd like to be able to specify nested keys in the filter rules, or wildcards such as Metadata.Genre[*].tag === Comedy You should be able to support this pretty easily by using 'jsonpath' instead of 'lodash'

Describe alternatives you've considered This is currently what I'm using (pretty cumbersome):

        {
            "name": "Plex Webhooks Platform",
            "sensors": [
                {
                    "name": "Horror on Living Room TV",
                    "filters": [
                        [
                            {
                                "path": "Player.title",
                                "operator": "===",
                                "value": "Living Room TV"
                            },
                            {
                                "path": "Metadata.Genre[0].tag",
                                "operator": "===",
                                "value": "Horror"
                            }
                        ],
                        [
                            {
                                "path": "Player.title",
                                "operator": "===",
                                "value": "Living Room TV"
                            },
                            {
                                "path": "Metadata.Genre[1].tag",
                                "operator": "===",
                                "value": "Horror"
                            }
                        ],
                        [
                            {
                                "path": "Player.title",
                                "operator": "===",
                                "value": "Living Room TV"
                            },
                            {
                                "path": "Metadata.Genre[2].tag",
                                "operator": "===",
                                "value": "Horror"
                            }
                        ]
                    ]
                },
                {
                    "name": "Fantasy on Living Room TV",
                    "filters": [
                        [
                            {
                                "path": "Player.title",
                                "operator": "===",
                                "value": "Living Room TV"
                            },
                            {
                                "path": "Metadata.Genre[0].tag",
                                "operator": "===",
                                "value": "Fantasy"
                            }
                        ],
                        [
                            {
                                "path": "Player.title",
                                "operator": "===",
                                "value": "Living Room TV"
                            },
                            {
                                "path": "Metadata.Genre[1].tag",
                                "operator": "===",
                                "value": "Fantasy"
                            }
                        ],
                        [
                            {
                                "path": "Player.title",
                                "operator": "===",
                                "value": "Living Room TV"
                            },
                            {
                                "path": "Metadata.Genre[2].tag",
                                "operator": "===",
                                "value": "Fantasy"
                            }
                        ]
                    ]
                }
            ],
            "server": {
                "address": "192.168.50.2"
            },
            "verbose": true,
            "platform": "PlexWebhooks"
        }

Additional context Here's an example payload coming from Plex:

{
  "event": "media.play",
  "user": false,
  "owner": true,
  "Server": {
    "title": "TS-253B",
  },
  "Player": {
    "local": true,
    "title": "Living Room TV",
  },
  "Metadata": {
    "librarySectionType": "movie",
    "ratingKey": "2066",
    "key": "/library/metadata/2066",
    "guid": "plex://movie/5d776836f54112001f5bda0d",
    "studio": "Universal Pictures",
    "type": "movie",
    "title": "Child's Play 3",
    "librarySectionTitle": "Movies",
    "librarySectionID": 1,
    "librarySectionKey": "/library/sections/1",
    "contentRating": "R",
    "summary": "Chucky returns for revenge against Andy, the young boy who defeated him, and now a teenager living in a military academy.",
    "rating": 2.3,
    "audienceRating": 3.4,
    "year": 1991,
    "tagline": "There comes a time to put away childhood things. But some things won't stay put!",
    "thumb": "/library/metadata/2066/thumb/1669952119",
    "art": "/library/metadata/2066/art/1669952119",
    "duration": 5400000,
    "originallyAvailableAt": "1991-08-30",
    "addedAt": 1635923794,
    "updatedAt": 1669952119,
    "audienceRatingImage": "rottentomatoes://image.rating.spilled",
    "chapterSource": "media",
    "primaryExtraKey": "/library/metadata/2067",
    "ratingImage": "rottentomatoes://image.rating.rotten",
    "Genre": [
      {
        "id": 335,
        "filter": "genre=335",
        "tag": "Horror",
        "count": 29
      },
      {
        "id": 253,
        "filter": "genre=253",
        "tag": "Thriller",
        "count": 62
      },
      {
        "id": 251,
        "filter": "genre=251",
        "tag": "Action",
        "count": 101
      }
    ],
    "Director": [
      {
        "id": 16303,
        "filter": "director=16303",
        "tag": "Jack Bender"
      }
    ],
    "Writer": [
      {
        "id": 24056,
        "filter": "writer=24056",
        "tag": "Don Mancini",
        "count": 7
      }
    ],
    "Producer": [
      {
        "id": 24083,
        "filter": "producer=24083",
        "tag": "Robert Latham Brown"
      }
    ],
    "Country": [
      {
        "id": 255,
        "filter": "country=255",
        "tag": "United States of America",
        "count": 191
      }
    ],
    "Guid": [
      {
        "id": "imdb://tt0103956"
      },
      {
        "id": "tmdb://11187"
      },
      {
        "id": "tvdb://2455"
      }
    ],
    "Rating": [
      {
        "image": "imdb://image.rating",
        "value": 5.1,
        "type": "audience",
        "count": 198
      },
      {
        "image": "rottentomatoes://image.rating.rotten",
        "value": 2.3,
        "type": "critic",
        "count": 63
      }
    ],
    "Role": [
      {
        "id": 14352,
        "filter": "actor=14352",
        "tag": "Brad Dourif",
        "count": 9,
        "role": "Chucky (voice)",
        "thumb": "https://metadata-static.plex.tv/5/people/5380402f608f587833f0e1f596396543.jpg"
      },
      {
        "id": 24057,
        "filter": "actor=24057",
        "tag": "Justin Whalin",
        "role": "Andy Barclay",
        "thumb": "https://metadata-static.plex.tv/5/people/54232bd3629b642b670981458ad81a1d.jpg"
      },
    ]
  }
}

JSON Pretty Print - Privacy Policy

iharosi commented 1 year ago

@Identifier Yeah I can see it could be pretty cumbersome however I don't have the time to maintain this project. Feel free to create a PR if you have a good solution for this.