-
Notifications
You must be signed in to change notification settings - Fork 3
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
fdett
committed
Mar 23, 2023
1 parent
56f8532
commit 8afb767
Showing
10 changed files
with
177 additions
and
142 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
23 changes: 23 additions & 0 deletions
23
Jellyfin.Plugin.Ignore/Configuration/PluginConfiguration.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,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; } | ||
} |
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,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> |
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,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; | ||
} | ||
} |
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
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
57 changes: 0 additions & 57 deletions
57
Jellyfin.Plugin.Template/Configuration/PluginConfiguration.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
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 @@ | ||
[] |