Skip to content

Commit

Permalink
[133] Create Sonarr webhook to add Series
Browse files Browse the repository at this point in the history
Also add to docs
  • Loading branch information
CollinHeist committed Aug 28, 2024
1 parent 8c6ce13 commit 928d40a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
40 changes: 39 additions & 1 deletion app/routers/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import (
APIRouter,
BackgroundTasks,
Body,
Depends,
Query,
Expand All @@ -17,14 +18,19 @@
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
from app.models.card import Card
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
Expand Down Expand Up @@ -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
)
4 changes: 0 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
44 changes: 30 additions & 14 deletions docs/user_guide/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <span class="example md-button">Save</span>.

=== "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 <span class="example md-button">Save</span>.
5. Click <span class="example md-button">Save</span>.

=== "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 <span class="example md-button">Save</span>.

9. Click <span class="example md-button">Save</span>.
Multiple of the above integrations may be enabled at once, if desired.

## Tautulli

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-webui132
v2.0-alpha.11.0-webui133

0 comments on commit 928d40a

Please sign in to comment.