Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardDorian committed Nov 2, 2023
0 parents commit f21cb9c
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
14 changes: 14 additions & 0 deletions JellyfinSkippers.csproj
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>
21 changes: 21 additions & 0 deletions LICENSE
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 RichardDorian.Plugin.Skippers/Controllers/SkipsController.cs
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;
}
}
29 changes: 29 additions & 0 deletions RichardDorian.Plugin.Skippers/Data/Skip.cs
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);
}
}
8 changes: 8 additions & 0 deletions RichardDorian.Plugin.Skippers/Data/SkipType.cs
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
}
19 changes: 19 additions & 0 deletions RichardDorian.Plugin.Skippers/Data/Skipper.cs
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();
}
}
48 changes: 48 additions & 0 deletions RichardDorian.Plugin.Skippers/Plugin.cs
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
);
}
}
}
10 changes: 10 additions & 0 deletions RichardDorian.Plugin.Skippers/PluginConfiguration.cs
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 RichardDorian.Plugin.Skippers/ScheduledTasks/UpdateSkippers.cs
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>();
}
}

0 comments on commit f21cb9c

Please sign in to comment.