-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Account for parsing different types of Tautulli Discord schemas (…
…#55)
- Loading branch information
Showing
4 changed files
with
249 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
from tautulli.tools.webhooks.discord import DiscordWebhookIngestor, DiscordWebhookData, DiscordWebhookAttachment | ||
from tautulli.tools.webhooks.base import ( | ||
TautulliWebhookTrigger, | ||
_TautulliWebhook, | ||
) | ||
from tautulli.tools.webhooks.discord import ( | ||
DiscordWebhook, | ||
_DiscordWebhookData, | ||
DiscordWebhookAttachment, | ||
PlaybackStateChangeDiscordWebhookData, | ||
RecentlyAddedDiscordWebhookData, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import enum | ||
from abc import abstractmethod, ABC | ||
from typing import Union, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class TautulliWebhookTrigger(enum.Enum): | ||
PLAYBACK_START = "on_play" | ||
PLAYBACK_STOP = "on_stop" | ||
PLAYBACK_PAUSE = "on_pause" | ||
PLAYBACK_RESUME = "on_resume" | ||
PLAYBACK_ERROR = "on_error" | ||
TRANSCODE_DECISION_CHANGE = "on_change" | ||
INTRO_MARKER = "on_intro" | ||
COMMERCIAL_MARKER = "on_commercial" | ||
CREDITS_MARKER = "on_credits" | ||
WATCHED = "on_watched" | ||
BUFFER_WARNING = "on_buffer" | ||
USER_CONCURRENT_STREAMS = "on_concurrent" | ||
USER_NEW_DEVICE = "on_newdevice" | ||
RECENTLY_ADDED = "on_created" | ||
PLEX_SERVER_DOWN = "on_intdown" | ||
PLEX_SERVER_UP = "on_intup" | ||
PLEX_REMOTE_ACCESS_DOWN = "on_extdown" | ||
PLEX_REMOTE_ACCESS_UP = "on_extup" | ||
PLEX_UPDATE_AVAILABLE = "on_pmsupdate" | ||
TAUTULLI_UPDATE_AVAILABLE = "on_plexpyupdate" | ||
TAUTULLI_DATABASE_CORRUPT = "on_plexpydbcorrupt" | ||
|
||
@classmethod | ||
def from_string(cls, trigger: str) -> Union["TautulliWebhookTrigger", None]: | ||
""" | ||
Get a Tautulli webhook trigger from a string. | ||
""" | ||
for t in cls: | ||
if t.value == trigger: | ||
return t | ||
return None | ||
|
||
def __str__(self): | ||
return self.value | ||
|
||
|
||
class _TautulliWebhook(BaseModel, ABC): | ||
""" | ||
A webhook from Tautulli | ||
""" | ||
_trigger: Optional[TautulliWebhookTrigger] = None | ||
|
||
def __init__(self, /, **data): | ||
super().__init__(**data) | ||
|
||
@property | ||
def trigger(self) -> Union[TautulliWebhookTrigger, None]: | ||
if not self._trigger: | ||
self._trigger = self.determine_trigger() | ||
|
||
return self._trigger | ||
|
||
@abstractmethod | ||
def _determine_trigger(self, **kwargs: dict) -> Union[TautulliWebhookTrigger, None]: | ||
""" | ||
Determine the trigger of a Tautulli webhook. | ||
""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters