-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use ignore patterns during media folder search and in the ignore…
… rule Use a copy of the ignore patterns taken from the Jellyfin core (since they're not exposed through the abstraction used by plugins) to ignore paths we shouldn't check in the media folder mapping check and in the ignore rule check. The latter check is redundant since the core also has such a check, but in the off-case that the shoko ignore rule is ran before the core ignore rule then we won't attempt to check the paths that would otherwise had been checked because of the run order.
- Loading branch information
Showing
4 changed files
with
189 additions
and
4 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
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
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,134 @@ | ||
using System; | ||
using DotNet.Globbing; | ||
|
||
namespace Shokofin.Utils; | ||
|
||
/// <summary> | ||
/// Glob patterns for files to ignore. | ||
/// </summary> | ||
/// <remarks> | ||
/// A one-to-one copy of <see href="https://github.com/jellyfin/jellyfin/blob/b92fc7ea9dbf86437a981c3f0477a7b457977b9a/Emby.Server.Implementations/Library/IgnorePatterns.cs"/> | ||
/// since it's not exposed through the abstraction used by plugins and I don't | ||
/// care enough to rise a PR to expose it. | ||
/// </remarks> | ||
public static class IgnorePatterns | ||
{ | ||
/// <summary> | ||
/// Files matching these glob patterns will be ignored. | ||
/// </summary> | ||
private static readonly string[] _patterns = | ||
{ | ||
"**/small.jpg", | ||
"**/albumart.jpg", | ||
|
||
// We have neither non-greedy matching or character group repetitions, working around that here. | ||
// https://github.com/dazinator/DotNet.Glob#patterns | ||
// .*/sample\..{1,5} | ||
"**/sample.?", | ||
"**/sample.??", | ||
"**/sample.???", // Matches sample.mkv | ||
"**/sample.????", // Matches sample.webm | ||
"**/sample.?????", | ||
"**/*.sample.?", | ||
"**/*.sample.??", | ||
"**/*.sample.???", | ||
"**/*.sample.????", | ||
"**/*.sample.?????", | ||
"**/sample/*", | ||
|
||
// Directories | ||
"**/metadata/**", | ||
"**/metadata", | ||
"**/ps3_update/**", | ||
"**/ps3_update", | ||
"**/ps3_vprm/**", | ||
"**/ps3_vprm", | ||
"**/extrafanart/**", | ||
"**/extrafanart", | ||
"**/extrathumbs/**", | ||
"**/extrathumbs", | ||
"**/.actors/**", | ||
"**/.actors", | ||
"**/.wd_tv/**", | ||
"**/.wd_tv", | ||
"**/lost+found/**", | ||
"**/lost+found", | ||
|
||
// Trickplay files | ||
"**/*.trickplay", | ||
"**/*.trickplay/**", | ||
|
||
// WMC temp recording directories that will constantly be written to | ||
"**/TempRec/**", | ||
"**/TempRec", | ||
"**/TempSBE/**", | ||
"**/TempSBE", | ||
|
||
// Synology | ||
"**/eaDir/**", | ||
"**/eaDir", | ||
"**/@eaDir/**", | ||
"**/@eaDir", | ||
"**/#recycle/**", | ||
"**/#recycle", | ||
|
||
// Qnap | ||
"**/@Recycle/**", | ||
"**/@Recycle", | ||
"**/.@__thumb/**", | ||
"**/.@__thumb", | ||
"**/$RECYCLE.BIN/**", | ||
"**/$RECYCLE.BIN", | ||
"**/System Volume Information/**", | ||
"**/System Volume Information", | ||
"**/.grab/**", | ||
"**/.grab", | ||
|
||
// Unix hidden files | ||
"**/.*", | ||
|
||
// Mac - if you ever remove the above. | ||
// "**/._*", | ||
// "**/.DS_Store", | ||
|
||
// thumbs.db | ||
"**/thumbs.db", | ||
|
||
// bts sync files | ||
"**/*.bts", | ||
"**/*.sync", | ||
|
||
// zfs | ||
"**/.zfs/**", | ||
"**/.zfs" | ||
}; | ||
|
||
private static readonly GlobOptions _globOptions = new GlobOptions | ||
{ | ||
Evaluation = | ||
{ | ||
CaseInsensitive = true | ||
} | ||
}; | ||
|
||
private static readonly Glob[] _globs = Array.ConvertAll(_patterns, p => Glob.Parse(p, _globOptions)); | ||
|
||
/// <summary> | ||
/// Returns true if the supplied path should be ignored. | ||
/// </summary> | ||
/// <param name="path">The path to test.</param> | ||
/// <returns>Whether to ignore the path.</returns> | ||
public static bool ShouldIgnore(ReadOnlySpan<char> path) | ||
{ | ||
int len = _globs.Length; | ||
for (int i = 0; i < len; i++) | ||
{ | ||
if (_globs[i].IsMatch(path)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |