-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RichardDorian
committed
Nov 2, 2023
0 parents
commit f21cb9c
Showing
10 changed files
with
211 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/ | ||
obj/ |
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Jellyfin.Controller" Version="10.8.11" /> | ||
<PackageReference Include="Jellyfin.Model" Version="10.8.11" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 RICHARD Dorian | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
35 changes: 35 additions & 0 deletions
35
RichardDorian.Plugin.Skippers/Controllers/SkipsController.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,35 @@ | ||
using System.Net.Mime; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using RichardDorian.Plugin.Skippers.Data; | ||
|
||
namespace RichardDorian.Plugin.Skippers.Controllers; | ||
|
||
[Authorize] | ||
[ApiController] | ||
[Produces(MediaTypeNames.Application.Json)] | ||
public class SkipsController : ControllerBase | ||
{ | ||
public SkipsController() | ||
{ | ||
} | ||
|
||
[HttpGet("Item/{id}/Skips")] | ||
public ActionResult<List<Skip>> GetSkips([FromRoute] Guid id) | ||
{ | ||
var skips = GetSkipsFromGuid(id); | ||
|
||
if (skips is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return skips; | ||
} | ||
|
||
private static List<Skip>? GetSkipsFromGuid(Guid id) | ||
{ | ||
Plugin.Instance!.Skippers.TryGetValue(id, out var skips); | ||
return skips; | ||
} | ||
} |
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,29 @@ | ||
namespace RichardDorian.Plugin.Skippers.Data; | ||
|
||
public class Skip | ||
{ | ||
public SkipType Type { get; set; } | ||
public double Start { get; set; } | ||
public double End { get; set; } | ||
|
||
public Skip(SkipType type, double start, double end) | ||
{ | ||
Type = type; | ||
Start = start; | ||
End = end; | ||
} | ||
|
||
internal Skip() | ||
{ | ||
} | ||
|
||
public double ShowPromptAt | ||
{ | ||
get => Start + .5f; | ||
} | ||
|
||
public double HidePromptAt | ||
{ | ||
get => Math.Round(Start + (End - Start) / 3, 1); | ||
} | ||
} |
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,8 @@ | ||
namespace RichardDorian.Plugin.Skippers.Data; | ||
|
||
public enum SkipType : ushort | ||
{ | ||
Other = 0, | ||
Intro = 1, | ||
PostCreditScene = 2 | ||
} |
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,19 @@ | ||
namespace RichardDorian.Plugin.Skippers.Data; | ||
|
||
public class Skipper | ||
{ | ||
public Guid Id; | ||
public List<Skip> Skips; | ||
|
||
public Skipper(Guid id, List<Skip> skips) | ||
{ | ||
Id = id; | ||
Skips = skips; | ||
} | ||
|
||
internal Skipper() | ||
{ | ||
Id = Guid.Empty; | ||
Skips = new(); | ||
} | ||
} |
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,48 @@ | ||
using MediaBrowser.Common.Configuration; | ||
using MediaBrowser.Common.Plugins; | ||
using MediaBrowser.Model.Serialization; | ||
using RichardDorian.Plugin.Skippers.Data; | ||
|
||
namespace RichardDorian.Plugin.Skippers; | ||
|
||
public class Plugin : BasePlugin<PluginConfiguration> | ||
{ | ||
private readonly string SkippersPath; | ||
|
||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) : base(applicationPaths, xmlSerializer) | ||
{ | ||
Instance = this; | ||
|
||
SkippersPath = Path.Join(applicationPaths.PluginConfigurationsPath, "RichardDorian.Plugin.Skippers.xml"); | ||
RestoreSkippersFromDisk(); | ||
} | ||
|
||
public override string Name => "Skippers"; | ||
public override Guid Id => Guid.Parse("b9650cbc-83f5-4e1f-bb54-4dffc66c2033"); | ||
public Dictionary<Guid, List<Skip>> Skippers { get; set; } = new(); | ||
|
||
public static Plugin? Instance { get; private set; } | ||
|
||
public void RestoreSkippersFromDisk() | ||
{ | ||
if (File.Exists(SkippersPath)) | ||
{ | ||
var skipsList = (List<Skipper>)XmlSerializer.DeserializeFromFile( | ||
typeof(List<Skipper>), | ||
SkippersPath | ||
); | ||
|
||
foreach (var skips in skipsList) | ||
{ | ||
Skippers[skips.Id] = skips.Skips; | ||
} | ||
} | ||
else | ||
{ | ||
XmlSerializer.SerializeToFile( | ||
new List<Skipper>(), | ||
SkippersPath | ||
); | ||
} | ||
} | ||
} |
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 @@ | ||
using MediaBrowser.Model.Plugins; | ||
|
||
namespace RichardDorian.Plugin.Skippers; | ||
|
||
public class PluginConfiguration : BasePluginConfiguration | ||
{ | ||
public PluginConfiguration() | ||
{ | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
RichardDorian.Plugin.Skippers/ScheduledTasks/UpdateSkippers.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,25 @@ | ||
using MediaBrowser.Model.Tasks; | ||
|
||
namespace RichardDorian.Plugin.Skippers.ScheduledTasks; | ||
|
||
public class UpdateSkippersTask : IScheduledTask | ||
{ | ||
public string Name => "Update Skippers"; | ||
public string Category => "Skippers"; | ||
public string Description => "Update skippers from disk"; | ||
public string Key => "RichardDorianSkippersUpdate"; | ||
|
||
public Task ExecuteAsync( | ||
IProgress<double> progress, | ||
CancellationToken cancellationToken | ||
) | ||
{ | ||
Plugin.Instance!.RestoreSkippersFromDisk(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() | ||
{ | ||
return Array.Empty<TaskTriggerInfo>(); | ||
} | ||
} |