Skip to content

Commit

Permalink
[103] Allow integration with Plex Webhooks
Browse files Browse the repository at this point in the history
Create POST /api/webhooks/plex endpoint which can be triggered directly by Plex to immediately cause Card creation
  • Loading branch information
CollinHeist committed Aug 22, 2024
1 parent b1f8f2c commit 83f8713
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions app/routers/webhooks.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,41 @@ def create_cards_for_plex_rating_key(
)


@webhook_router.post('/plex', tags=['Plex'])
async def process_plex_webhook(
request: Request,
# FastAPI cannot parse the payload, for some reason, so this needs to
# be parsed from the request.form() directly
# webhook: PlexWebhook = Form(...),
snapshot: bool = Query(default=True),
trigger_on: Optional[str] = Query(default=None),
db: Session = Depends(get_database),
plex_interface: PlexInterface = Depends(require_plex_interface),
) -> None:
"""
"""

# Get contextual logger
log: Logger = request.state.log

webhook = PlexWebhook.parse_raw((await request.form()).get('payload'))

# Only process new or watched content
if (webhook.event not in ('library.new', 'media.scrobble')
and (not trigger_on
or (trigger_on and webhook.event not in trigger_on))):
log.debug(f'Skipping Webhook of type "{webhook.event}"')
return None

return process_rating_key(
db,
plex_interface,
webhook.Metadata.ratingKey,
snapshot=snapshot,
log=log,
)


@webhook_router.post('/sonarr/cards', tags=['Sonarr'])
def create_cards_for_sonarr_webhook(
request: Request,
Expand Down
2 changes: 1 addition & 1 deletion modules/ref/version_webui
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0-alpha.11.0-webui102
v2.0-alpha.11.0-webui103

0 comments on commit 83f8713

Please sign in to comment.