Skip to content

Commit

Permalink
feat(sponsorblock/chapters): Add SponsorBlock chapters model
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Feb 26, 2024
1 parent dfebcff commit 5de0473
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
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);
}
}
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());
}
}
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);
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
{
}

0 comments on commit 5de0473

Please sign in to comment.