Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
fdett committed Mar 23, 2023
1 parent 56f8532 commit 8afb767
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Template", "Jellyfin.Plugin.Template\Jellyfin.Plugin.Template.csproj", "{D921B930-CF91-406F-ACBC-08914DCD0D34}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Ignore", "Jellyfin.Plugin.Ignore\Jellyfin.Plugin.Ignore.csproj", "{D921B930-CF91-406F-ACBC-08914DCD0D34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
23 changes: 23 additions & 0 deletions Jellyfin.Plugin.Ignore/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using MediaBrowser.Model.Plugins;

namespace Jellyfin.Plugin.Ignore.Configuration;

/// <summary>
/// Plugin configuration.
/// </summary>
public class PluginConfiguration : BasePluginConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginConfiguration"/> class.
/// </summary>
public PluginConfiguration()
{
// set default options here
IgnoreString = string.Empty;
}

/// <summary>
/// Gets or sets a value of the patterns we want to ignore.
/// </summary>
public string IgnoreString { get; set; }
}
59 changes: 59 additions & 0 deletions Jellyfin.Plugin.Ignore/Configuration/configPage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Jellyfin Ignore Options Page</title>
</head>
<body>
<div id="TemplateConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
<div data-role="content">
<div class="content-primary">
<form id="TemplateConfigForm">
<div class="inputContainer">
<div><label class="inputLabel inputLabelUnfocused" for="IgnoreString">Ignore patterns</label></div>
<textarea id="IgnoreString" name="IgnoreString" is="emby-textarea" rows="10" style="width: 100%" class="emby-textarea"></textarea>
<div class="fieldDescription">
<p>List of patterns to ignore (one per line). Pattern matching is using the DotNet.Glob library. You can find examples <a href="https://github.com/dazinator/DotNet.Glob">here</a>.</p>

<p>Matching is done on the entire path. If you want to ignore a specific file extension, the pattern would be (using mp3 as an example): <code>/**/*.mp3</code></p>
</div>
</div>
<div>
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
<span>Save</span>
</button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
var PluginConfig = {
pluginUniqueId: '277cd84e-44c3-45a1-8f3c-2537ddac0ccf'
};

document.querySelector('#TemplateConfigPage')
.addEventListener('pageshow', function() {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(PluginConfig.pluginUniqueId).then(function (config) {
document.querySelector('#IgnoreString').value = config.IgnoreString;
Dashboard.hideLoadingMsg();
});
});

document.querySelector('#TemplateConfigForm')
.addEventListener('submit', function(e) {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(PluginConfig.pluginUniqueId).then(function (config) {
config.IgnoreString = document.querySelector('#IgnoreString').value;
ApiClient.updatePluginConfiguration(PluginConfig.pluginUniqueId, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
});

e.preventDefault();
return false;
});
</script>
</div>
</body>
</html>
74 changes: 74 additions & 0 deletions Jellyfin.Plugin.Ignore/IgnoreRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using DotNet.Globbing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.IO;

namespace Jellyfin.Plugin.Ignore;

/// <summary>
/// Ignore rules for the Jellyfin Ignore plugin.
/// </summary>
public class IgnoreRule : IResolverIgnoreRule
{
private static readonly GlobOptions _globOptions = new GlobOptions
{
Evaluation =
{
CaseInsensitive = true
}
};

private static Glob[]? _globs;

/// <summary>
/// Update the patterns to ignore.
/// </summary>
public static void UpdateGlobs()
{
if (Plugin.Instance == null)
{
return;
}

var patternsString = Plugin.Instance.Configuration.IgnoreString;
var patterns = patternsString.Split("\n").Select(p => Regex.Unescape(p).Trim()).Where(p => p.Length > 0);

_globs = patterns.Select(p => Glob.Parse(p, _globOptions)).ToArray();
}

/// <summary>
/// The logic for whether we should ignore a path.
/// </summary>
/// <param name="fileInfo">The file we are looking at to decide if we should ignore it.</param>
/// <param name="parent">The BaseItem.</param>
/// <returns>Whether the file should be ignored.</returns>
public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
{
if (_globs == null)
{
UpdateGlobs();
}

if (_globs == null)
{
return false;
}

var path = Path.Join(parent.Path, fileInfo.Name);

int len = _globs.Length;
for (int i = 0; i < len; i++)
{
if (_globs[i].IsMatch(path))
{
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.Template</RootNamespace>
<RootNamespace>Jellyfin.Plugin.Ignore</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
Expand All @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="Jellyfin.Controller" Version="10.8.0" />
<PackageReference Include="Jellyfin.Model" Version="10.8.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Jellyfin.Plugin.Template.Configuration;
using Jellyfin.Plugin.Ignore.Configuration;
using MediaBrowser.Common.Configuration;

using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;

namespace Jellyfin.Plugin.Template;
namespace Jellyfin.Plugin.Ignore;

/// <summary>
/// The main plugin.
Expand All @@ -23,19 +24,31 @@ public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
this.ConfigurationChanged = this.ConfigurationChangedEventHandler;
IgnoreRule.UpdateGlobs();
}

/// <inheritdoc />
public override string Name => "Template";
public override string Name => "Jellyfin Ignore";

/// <inheritdoc />
public override Guid Id => Guid.Parse("eb5d7894-8eef-4b36-aa6f-5d124e828ce1");
public override Guid Id => Guid.Parse("277cd84e-44c3-45a1-8f3c-2537ddac0ccf");

/// <summary>
/// Gets the current plugin instance.
/// </summary>
public static Plugin? Instance { get; private set; }

/// <summary>
/// When the configuration is updated by the user, we also update the ignore patterns.
/// </summary>
/// <param name="sender">The object triggering the configuration change.</param>
/// <param name="c">The configuration object.</param>
public void ConfigurationChangedEventHandler(object? sender, BasePluginConfiguration c)
{
IgnoreRule.UpdateGlobs();
}

/// <inheritdoc />
public IEnumerable<PluginPageInfo> GetPages()
{
Expand Down
57 changes: 0 additions & 57 deletions Jellyfin.Plugin.Template/Configuration/PluginConfiguration.cs

This file was deleted.

79 changes: 0 additions & 79 deletions Jellyfin.Plugin.Template/Configuration/configPage.html

This file was deleted.

Empty file added build_pugin.sh
Empty file.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 8afb767

Please sign in to comment.