Skip to content

Commit

Permalink
Add events log
Browse files Browse the repository at this point in the history
  • Loading branch information
shemanaev committed Jan 27, 2024
1 parent 3cff2e3 commit 20e3b44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Plugin

on:
push:
branches: [ master, main ]
branches: [ master, main, "dev/**" ]
paths-ignore:
- '**/*.md'
pull_request:
Expand Down
16 changes: 16 additions & 0 deletions Jellyfin.Webhooks/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ public Task RunAsync()

private async void OnPlaybackStart(object sender, PlaybackProgressEventArgs e)
{
_logger.LogInformation("OnPlaybackStart");
SetDeviceState(e.DeviceId, DeviceState.Playing);
await PlaybackEvent(HookEvent.Play, e.Item, e.Session, e.Users);
}

private async void OnPlaybackStopped(object sender, PlaybackStopEventArgs e)
{
_logger.LogInformation("OnPlaybackStopped");
SetDeviceState(e.DeviceId, DeviceState.Stopped);
await PlaybackEvent(HookEvent.Stop, e.Item, e.Session, e.Users);
}
Expand Down Expand Up @@ -165,27 +167,32 @@ private async void OnUserDataSaved(object sender, UserDataSaveEventArgs e)
return;
}

_logger.LogInformation("OnUserDataSaved");
var user = _userManager.GetUserById(e.UserId);
await PlaybackEvent(evt, e.Item, null, user);
}

private async void OnItemAdded(object sender, ItemChangeEventArgs e)
{
_logger.LogInformation("OnItemAdded");
await LibraryEvent(HookEvent.ItemAdded, e.Item, e.UpdateReason);
}

private async void OnItemRemoved(object sender, ItemChangeEventArgs e)
{
_logger.LogInformation("OnItemRemoved");
await LibraryEvent(HookEvent.ItemRemoved, e.Item, e.UpdateReason);
}

private async void OnItemUpdated(object sender, ItemChangeEventArgs e)
{
_logger.LogInformation("OnItemUpdated");
await LibraryEvent(HookEvent.ItemUpdated, e.Item, e.UpdateReason);
}

private async void OnAuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e)
{
_logger.LogInformation("OnAuthenticationSucceeded");
var user = _userManager.GetUserById(e.Argument.User.Id);
await ExecuteWebhook(new EventInfo
{
Expand All @@ -203,6 +210,7 @@ await ExecuteWebhook(new EventInfo

private async void OnAuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e)
{
_logger.LogInformation("OnAuthenticationFailed");
await ExecuteWebhook(new EventInfo
{
Event = HookEvent.AuthenticationFailed,
Expand All @@ -218,11 +226,13 @@ await ExecuteWebhook(new EventInfo

private async void OnSessionStarted(object sender, SessionEventArgs e)
{
_logger.LogInformation("OnSessionStarted");
await SessionEvent(HookEvent.SessionStarted, e.SessionInfo);
}

private async void OnSessionEnded(object sender, SessionEventArgs e)
{
_logger.LogInformation("OnSessionEnded");
if (GetDeviceState(e.SessionInfo.DeviceId) != DeviceState.Stopped)
{
var user = _userManager.GetUserById(e.SessionInfo.UserId);
Expand All @@ -235,6 +245,7 @@ private async void OnSessionEnded(object sender, SessionEventArgs e)

private async void OnSubtitleDownloadFailure(object sender, SubtitleDownloadFailureEventArgs e)
{
_logger.LogInformation("OnSubtitleDownloadFailure");
await ExecuteWebhook(new EventInfo
{
Event = HookEvent.SubtitleDownloadFailure,
Expand All @@ -251,6 +262,7 @@ await ExecuteWebhook(new EventInfo

private async void HasPendingRestartChanged(object sender, EventArgs e)
{
_logger.LogInformation("HasPendingRestartChanged");
await ExecuteWebhook(new EventInfo
{
Event = HookEvent.HasPendingRestartChanged,
Expand All @@ -273,6 +285,7 @@ private async Task SessionEvent(HookEvent evt, SessionInfo session)
user = _userManager.GetUserById(session.UserId);
}

_logger.LogInformation("SessionEvent");
await ExecuteWebhook(new EventInfo
{
Event = evt,
Expand All @@ -292,6 +305,7 @@ private async Task LibraryEvent(HookEvent evt, BaseItem item, ItemUpdateType upd
if (item == null) return;
if (item.IsVirtualItem) return;

_logger.LogInformation("LibraryEvent");
await ExecuteWebhook(new EventInfo
{
Event = evt,
Expand All @@ -311,6 +325,7 @@ private async Task PlaybackEvent(HookEvent evt, BaseItem item, SessionInfo sessi
if (user == null) return;
if (item == null) return;

_logger.LogInformation("PlaybackEvent");
await ExecuteWebhook(new EventInfo
{
Event = evt,
Expand Down Expand Up @@ -349,6 +364,7 @@ private async Task ExecuteWebhook(EventInfo request)
var formatter = _formatFactory.CreateFormat(hook.Format);
try
{
_logger.LogInformation("ExecuteWebhook: {id}", hook.Id);
await formatter.Format(new Uri(hook.Url), request);
}
catch (Exception e)
Expand Down

0 comments on commit 20e3b44

Please sign in to comment.