Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2018 Hinni Solutions
Copyright 2021 Hinni Solutions

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
5 changes: 2 additions & 3 deletions Plex.Server.Webhooks.Tests/ParseDemoEventTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ public void ParseEvent()
// Arrange
var path = Path.Combine(Environment.CurrentDirectory, "Payloads", "MediaPlay.json");
var payload = File.ReadAllText(path);
var parser = new WebhookParser();

// Act
var plexEvent = parser.ParseEvent(payload);
var plexEvent = PlexWebhookParser.ParseEvent(payload);

// Assert
Assert.IsType<MediaPlay>(plexEvent);
Assert.IsType<PlexWebhookEvent>(plexEvent);
}
}
}
23 changes: 9 additions & 14 deletions Plex.Server.Webhooks.Tests/Plex.Server.Webhooks.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>

<Authors>Hinni</Authors>

<Company>Hinni Solutions</Company>

<Copyright>Copyright © 2017-2018 Hinni Solutions</Copyright>

<Copyright>Copyright © 2017-2021 Hinni Solutions</Copyright>
<PackageLicenseUrl></PackageLicenseUrl>

<PackageProjectUrl>https://github.com/Hinni/plex-server-webhooks</PackageProjectUrl>

<PackageTags>Plex MediaServer Webhooks Tests</PackageTags>

<Version>2.0.0</Version>
<Version>2.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions Plex.Server.Webhooks/Converters/EventTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Plex.Server.Webhooks.Extensions;

namespace Plex.Server.Webhooks.Converters
{
public class EventTypeConverter : StringEnumConverter
{
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.String) return base.ReadJson(reader, objectType, existingValue, serializer);

string enumText = reader.Value?.ToString();
var result = enumText.GetEventType();
if (result == null) throw new NotImplementedException($"Event {enumText} is not implemented yet.");

return base.ReadJson(reader, objectType, existingValue, serializer);
}
}
}
50 changes: 0 additions & 50 deletions Plex.Server.Webhooks/Converters/WebhookJsonConverter.cs

This file was deleted.

61 changes: 61 additions & 0 deletions Plex.Server.Webhooks/Enums/EventType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Runtime.Serialization;

namespace Plex.Server.Webhooks.Events
{
/// <summary>
/// Represents the event types for the Webhook being hit
/// </summary>
public enum EventType
{
#region New Content

/// <summary>A new item is added that appears in the user’s On Deck. A poster is also attached to this event.</summary>
[EnumMember(Value = "library.on.deck")]
LibraryOnDeck,
/// <summary>A new item is added to a library to which the user has access. A poster is also attached to this event.</summary>
[EnumMember(Value = "library.new")]
LibraryNew,

#endregion

#region Playback

/// <summary>Media playback pauses.</summary>
[EnumMember(Value = "media.pause")]
MediaPause,
/// <summary>Media starts playing. An appropriate poster is attached.</summary>
[EnumMember(Value = "media.play")]
MediaPlay,
/// <summary>Media is rated. A poster is also attached to this event.</summary>
[EnumMember(Value = "media.rate")]
MediaRate,
/// <summary>Media playback resumes.</summary>
[EnumMember(Value = "media.resume")]
MediaResume,
/// <summary>Media is viewed (played past the 90% mark).</summary>
[EnumMember(Value = "media.scrobble")]
MediaScrobble,
/// <summary>Media playback stops.</summary>
[EnumMember(Value = "media.stop")]
MediaStop,

#endregion

#region Server Owner

/// <summary>A database backup is completed successfully via Scheduled Tasks.</summary>
[EnumMember(Value = "admin.database.backup")]
AdminDatabaseBackup,
/// <summary>Corruption is detected in the server database.</summary>
[EnumMember(Value = "admin.database.corrupted")]
AdminDatabaseCorrupted,
/// <summary>A device accesses the owner’s server for any reason, which may come from background connection testing and doesn’t necessarily indicate active browsing or playback.</summary>
[EnumMember(Value = "device.new")]
DeviceNew,
/// <summary>Playback is started by a shared user for the server. A poster is also attached to this event.</summary>
[EnumMember(Value = "playback.started")]
PlaybackStarted

#endregion
}
}
8 changes: 7 additions & 1 deletion Plex.Server.Webhooks/Events/Core/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace Plex.Server.Webhooks.Events.Core
{
/// <summary>
/// Represents the User
/// </summary>
public class Account
{
/// <summary>The Id</summary>
[JsonProperty("id")]
public int Id { get; set; }

/// <summary>The Thumbnail</summary>
[JsonProperty("thumb")]
public string Thumb { get; set; }

/// <summary>The Username</summary>
[JsonProperty("title")]
public string Title { get; set; }
public string Name { get; set; }
}
}
29 changes: 28 additions & 1 deletion Plex.Server.Webhooks/Events/Core/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,104 @@

namespace Plex.Server.Webhooks.Events.Core
{
/// <summary>
/// Represents the Metadata
/// </summary>
public class Metadata
{
/// <summary>The Library Section Type</summary>
[JsonProperty("librarySectionType")]
public string LibrarySectionType { get; set; }

/// <summary>The Rating Key</summary>
[JsonProperty("ratingKey")]
public string RatingKey { get; set; }

/// <summary>The Key</summary>
[JsonProperty("key")]
public string Key { get; set; }

/// <summary>The Parent Rating Key</summary>
[JsonProperty("parentRatingKey")]
public string ParentRatingKey { get; set; }

/// <summary>The Grandparent Rating Key</summary>
[JsonProperty("grandparentRatingKey")]
public string GrandparentRatingKey { get; set; }

/// <summary>The Id</summary>
[JsonProperty("guid")]
public string Guid { get; set; }
public string Id { get; set; }

/// <summary>The Library Section ID</summary>
[JsonProperty("librarySectionID")]
public int LibrarySectionID { get; set; }

/// <summary>The Type</summary>
[JsonProperty("type")]
public string Type { get; set; }

/// <summary>The Title</summary>
[JsonProperty("title")]
public string Title { get; set; }

/// <summary>The Grandparent Key</summary>
[JsonProperty("grandparentKey")]
public string GrandparentKey { get; set; }

/// <summary>The Parent Key</summary>
[JsonProperty("parentKey")]
public string ParentKey { get; set; }

/// <summary>The Grandparent Title</summary>
[JsonProperty("grandparentTitle")]
public string GrandparentTitle { get; set; }

/// <summary>The Parent Title</summary>
[JsonProperty("parentTitle")]
public string ParentTitle { get; set; }

/// <summary>The Summary</summary>
[JsonProperty("summary")]
public string Summary { get; set; }

/// <summary>The Index</summary>
[JsonProperty("index")]
public int Index { get; set; }

/// <summary>The Parent Index</summary>
[JsonProperty("parentIndex")]
public int ParentIndex { get; set; }

/// <summary>The Rating Count</summary>
[JsonProperty("ratingCount")]
public int RatingCount { get; set; }

/// <summary>The Thumbnail</summary>
[JsonProperty("thumb")]
public string Thumb { get; set; }

/// <summary>The Art</summary>
[JsonProperty("art")]
public string Art { get; set; }

/// <summary>The Parent Thumb</summary>
[JsonProperty("parentThumb")]
public string ParentThumb { get; set; }

/// <summary>The Grandparent Thumbnail</summary>
[JsonProperty("grandparentThumb")]
public string GrandparentThumb { get; set; }

/// <summary>The Grandparent Art</summary>
[JsonProperty("grandparentArt")]
public string GrandparentArt { get; set; }

/// <summary>Added At</summary>
[JsonProperty("addedAt"), JsonConverter(typeof(EpochToDateTimeConverter))]
public DateTime AddedAt { get; set; }

/// <summary>Updated At</summary>
[JsonProperty("updatedAt"), JsonConverter(typeof(EpochToDateTimeConverter))]
public DateTime UpdatedAt { get; set; }
}
Expand Down
19 changes: 13 additions & 6 deletions Plex.Server.Webhooks/Events/Core/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

namespace Plex.Server.Webhooks.Events.Core
{
/// <summary>
/// Represents the Player (device)
/// </summary>
public class Player
{
/// <summary>The Id</summary>
[JsonProperty("uuid")]
public string Id { get; set; }

/// <summary>The Name</summary>
[JsonProperty("title")]
public string Name { get; set; }

/// <summary>Is Local</summary>
[JsonProperty("local")]
public bool Local { get; set; }

/// <summary>The Public Address</summary>
[JsonProperty("publicAddress")]
public string PublicAddress { get; set; }

[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("uuid")]
public string Uuid { get; set; }
}
}
Loading