From 928d40a642ff6395645dc77614cab75d36d525d3 Mon Sep 17 00:00:00 2001 From: Collin Heist Date: Tue, 27 Aug 2024 19:32:51 -0600 Subject: [PATCH] [133] Create Sonarr webhook to add Series Also add to docs --- app/routers/webhooks.py | 40 +++++++++++++++++++++++++++++- docs/index.md | 4 --- docs/user_guide/integrations.md | 44 ++++++++++++++++++++++----------- modules/ref/version_webui | 2 +- 4 files changed, 70 insertions(+), 20 deletions(-) diff --git a/app/routers/webhooks.py b/app/routers/webhooks.py index afe97199..8357884e 100755 --- a/app/routers/webhooks.py +++ b/app/routers/webhooks.py @@ -4,6 +4,7 @@ from fastapi import ( APIRouter, + BackgroundTasks, Body, Depends, Query, @@ -17,7 +18,11 @@ from app.dependencies import get_database, require_plex_interface, PlexInterface from app.internal.cards import create_episode_cards, delete_cards from app.internal.episodes import refresh_episode_data -from app.internal.series import delete_series, load_episode_title_card +from app.internal.series import ( + add_series, + delete_series, + load_episode_title_card, +) from app.internal.sources import download_episode_source_images from app.internal.translate import translate_episode from app.internal.webhooks import process_rating_key @@ -25,6 +30,7 @@ from app.models.episode import Episode from app.models.loaded import Loaded from app.models.series import Series +from app.schemas.series import NewSeries from app.schemas.webhooks import PlexWebhook, SonarrWebhook from modules.EpisodeInfo2 import EpisodeInfo from modules.SeriesInfo2 import SeriesInfo @@ -264,3 +270,35 @@ def delete_series_via_sonarr_webhook( ) delete_series(db, series, log=request.state.log) return None + + +@webhook_router.post('/sonarr/series/add', tags=['Sonarr']) +def add_series_via_sonarr_webhook( + background_tasks: BackgroundTasks, + request: Request, + webhook: SonarrWebhook, + db: Session = Depends(get_database), + ) -> None: + """ + Add the Series defined in the given Webhook. + + - webhook: Webhook payload containing the details of the Series to + add. + """ + + if webhook.eventType != 'SeriesAdd': + request.state.log.debug(f'Skipping Webhook type "{webhook.eventType}"') + return None + + add_series( + NewSeries( + name=webhook.series.title, + year=webhook.series.year, + imdb_id=webhook.series.imdbId, + tvdb_id=webhook.series.tvdbId, + tvrage_id=webhook.series.tvRageId, + ), + background_tasks=background_tasks, + db=db, + log=request.state.log + ) diff --git a/docs/index.md b/docs/index.md index d3658a0e..bc09bb24 100755 --- a/docs/index.md +++ b/docs/index.md @@ -11,10 +11,6 @@ hide: # Welcome to TitleCardMaker -!!! warning "Under Construction" - - This documentation is actively being developed. - TitleCardMaker (TCM) is a program and Docker container written in Python that automates the creation of customized Title Cards for use in personal media server services like Plex, Jellyfin, or Emby. This is a self-hosted tool - diff --git a/docs/user_guide/integrations.md b/docs/user_guide/integrations.md index e951c8ae..b336ebe9 100755 --- a/docs/user_guide/integrations.md +++ b/docs/user_guide/integrations.md @@ -84,7 +84,7 @@ only be able to _actually_ trigger on `library.on.deck`, `media.pause`, The Webhook utilized by TCM was reworked in Sonarr v4; meaning this is required for the integration. -Sonarr can be configured to create new Cards, or delete Series in TCM via +Sonarr can be configured to create new Cards, or add/delete Series in TCM via Webhooks. ### Enabling @@ -101,33 +101,49 @@ click _Webhook_. 5. Leave the Tags field blank (unless you'd like to filter by tag). +Depending on the type of integration you would like to enable, do the following: + +=== "New Series" + + 1. To configure Sonarr to instruct TCM to add Series as they're added to + Sonarr, de-select all triggeres except `On Series Add`. + + 2. Enter the URL of your TCM server (including the port), followed by + `/api/webhooks/sonarr/series/add`. + + 3. Ensure the Method is `POST`. + + 4. Click Save. + === "Series Deletion" - 6. To configure Sonarr to instruct TCM to remove Series as they're deleted - from Sonarr, de-select all triggers _except_ `On Series Delete`. + 1. To configure Sonarr to instruct TCM to remove Series as they're deleted + from Sonarr, de-select all triggers except `On Series Delete`. - 7. Enter the URL of your TCM server (including the port), followed by + 2. Enter the URL of your TCM server (including the port), followed by `/api/webhooks/sonarr/series/delete`. - 8. If you would like TCM to _not_ delete the Title Card files themselves, + 3. If you would like TCM to _not_ delete the Title Card files themselves, add `?delete_title_cards=false` to the end of the URL. - 9. Ensure the Method is `POST`. + 4. Ensure the Method is `POST`. - 10. Click Save. + 5. Click Save. -=== "New Episodes" +=== "New Episode(s)" - 6. To configure Sonarr to instruct TCM to create Cards for new Episodes as - they're added to Sonarr, de-select all triggers _except_ - `On Import Complete` and `On File Upgrade`. + 1. To configure Sonarr to instruct TCM to create Cards for new Episodes as + they're added to Sonarr, de-select all triggers except `On Import Complete` + and `On File Upgrade`. - 7. Enter the URL of your TCM server (including the port), followed by + 2. Enter the URL of your TCM server (including the port), followed by `/api/webhooks/sonarr/cards`. - 8. Ensure the Method is `POST`. + 3. Ensure the Method is `POST`. + + 4. Click Save. - 9. Click Save. +Multiple of the above integrations may be enabled at once, if desired. ## Tautulli diff --git a/modules/ref/version_webui b/modules/ref/version_webui index 89904fc5..5bb6a6fa 100755 --- a/modules/ref/version_webui +++ b/modules/ref/version_webui @@ -1 +1 @@ -v2.0-alpha.11.0-webui132 \ No newline at end of file +v2.0-alpha.11.0-webui133 \ No newline at end of file