-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sponsorblock/chapters): Add SponsorBlock chapters model
- Loading branch information
1 parent
dfebcff
commit 5de0473
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/Lavalink4NET.Integrations.SponsorBlock/Converters/NumberTimeSpanJsonConverter.cs
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,18 @@ | ||
namespace Lavalink4NET.Integrations.SponsorBlock.Converters; | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
public sealed class NumberTimeSpanJsonConverter : JsonConverter<TimeSpan> | ||
{ | ||
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return TimeSpan.FromMilliseconds(reader.GetInt64()); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteNumberValue((long)value.TotalMilliseconds); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Lavalink4NET.Integrations.SponsorBlock/Converters/StringTimeSpanJsonConverter.cs
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,18 @@ | ||
namespace Lavalink4NET.Integrations.SponsorBlock.Converters; | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
public sealed class StringTimeSpanJsonConverter : JsonConverter<TimeSpan> | ||
{ | ||
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return TimeSpan.FromMilliseconds(long.Parse(reader.GetString()!)); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(((long)value.TotalMilliseconds).ToString()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Lavalink4NET.Integrations.SponsorBlock/Payloads/ChapterModel.cs
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,33 @@ | ||
namespace Lavalink4NET.Integrations.SponsorBlock.Payloads; | ||
|
||
using System; | ||
using System.Text.Json.Serialization; | ||
using Lavalink4NET.Integrations.SponsorBlock.Converters; | ||
|
||
public sealed record class ChapterModel( | ||
#if NET7_0_OR_GREATER | ||
[property: JsonRequired] | ||
#endif | ||
[property: JsonPropertyName("name")] | ||
string Name, | ||
|
||
#if NET7_0_OR_GREATER | ||
[property: JsonRequired] | ||
#endif | ||
[property: JsonConverter(typeof(NumberTimeSpanJsonConverter))] | ||
[property: JsonPropertyName("start")] | ||
TimeSpan Start, | ||
|
||
#if NET7_0_OR_GREATER | ||
[property: JsonRequired] | ||
#endif | ||
[property: JsonConverter(typeof(NumberTimeSpanJsonConverter))] | ||
[property: JsonPropertyName("end")] | ||
TimeSpan End, | ||
|
||
#if NET7_0_OR_GREATER | ||
[property: JsonRequired] | ||
#endif | ||
[property: JsonConverter(typeof(NumberTimeSpanJsonConverter))] | ||
[property: JsonPropertyName("duration")] | ||
TimeSpan Duration); |
10 changes: 10 additions & 0 deletions
10
src/Lavalink4NET.Integrations.SponsorBlock/Payloads/ChaptersLoadedEventPayload.cs
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,10 @@ | ||
namespace Lavalink4NET.Integrations.SponsorBlock.Payloads; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
internal class ChaptersLoadedEventPayload | ||
{ | ||
} |