Skip to content

Commit

Permalink
refactor: more changes to the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Mar 26, 2024
1 parent 59e5b76 commit fd4df1f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 91 deletions.
3 changes: 0 additions & 3 deletions Shokofin/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public virtual string PrettyHost

public UserConfiguration[] UserList { get; set; }

public string[] IgnoredFileExtensions { get; set; }

public string[] IgnoredFolders { get; set; }

public bool? LibraryFilteringMode { get; set; }
Expand Down Expand Up @@ -133,7 +131,6 @@ public PluginConfiguration()
CollectionGrouping = CollectionCreationType.None;
MovieOrdering = OrderType.Default;
UserList = Array.Empty<UserConfiguration>();
IgnoredFileExtensions = new [] { ".nfo", ".jpg", ".jpeg", ".png" };
IgnoredFolders = new [] { ".streams", "@recently-snapshot" };
LibraryFilteringMode = null;
EXPERIMENTAL_AutoMergeVersions = false;
Expand Down
45 changes: 6 additions & 39 deletions Shokofin/Configuration/configController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,6 @@ const Messages = {
UnableToRender: "There was an error loading the page, please refresh once to see if that will fix it.",
};

/**
* Filter out duplicate values and sanitize list.
* @param {string} value - Stringified list of values to filter.
* @returns {string[]} An array of sanitized and filtered values.
*/
function filterIgnoredExtensions(value) {
// We convert to a set to filter out duplicate values.
const filteredSet = new Set(
value
// Split the values at every space, tab, comma.
.split(/[\s,]+/g)
// Sanitize inputs.
.map(str => {
// Trim the start and end and convert to lower-case.
str = str.trim().toLowerCase();

// Add a dot if it's missing.
if (str[0] !== ".")
str = "." + str;

return str;
}),
);

// Filter out empty values.
if (filteredSet.has(""))
filteredSet.delete("");

// Convert it back into an array.
return Array.from(filteredSet);
}

/**
* Filter out duplicate values and sanitize list.
* @param {string} value - Stringified list of values to filter.
Expand Down Expand Up @@ -137,7 +105,6 @@ async function defaultSubmit(form) {
publicHost = publicHost.slice(0, -1);
form.querySelector("#PublicHost").value = publicHost;
}
const ignoredFileExtensions = filterIgnoredExtensions(form.querySelector("#IgnoredFileExtensions").value);
const ignoredFolders = filterIgnoredFolders(form.querySelector("#IgnoredFolders").value);
const filteringModeRaw = form.querySelector("#LibraryFilteringMode").value;
const filteringMode = filteringModeRaw === "true" ? true : filteringModeRaw === "false" ? false : null;
Expand Down Expand Up @@ -176,8 +143,6 @@ async function defaultSubmit(form) {

// Advanced settings
config.PublicHost = publicHost;
config.IgnoredFileExtensions = ignoredFileExtensions;
form.querySelector("#IgnoredFileExtensions").value = ignoredFileExtensions.join(" ");
config.IgnoredFolders = ignoredFolders;
form.querySelector("#IgnoredFolders").value = ignoredFolders.join();

Expand Down Expand Up @@ -300,7 +265,6 @@ async function syncSettings(form) {
publicHost = publicHost.slice(0, -1);
form.querySelector("#PublicHost").value = publicHost;
}
const ignoredFileExtensions = filterIgnoredExtensions(form.querySelector("#IgnoredFileExtensions").value);
const ignoredFolders = filterIgnoredFolders(form.querySelector("#IgnoredFolders").value);
const filteringModeRaw = form.querySelector("#LibraryFilteringMode").value;
const filteringMode = filteringModeRaw === "true" ? true : filteringModeRaw === "false" ? false : null;
Expand Down Expand Up @@ -339,8 +303,6 @@ async function syncSettings(form) {

// Advanced settings
config.PublicHost = publicHost;
config.IgnoredFileExtensions = ignoredFileExtensions;
form.querySelector("#IgnoredFileExtensions").value = ignoredFileExtensions.join(" ");
config.IgnoredFolders = ignoredFolders;
form.querySelector("#IgnoredFolders").value = ignoredFolders.join();

Expand Down Expand Up @@ -477,6 +439,12 @@ export default function (page) {

form.querySelector("#VirtualFileSystem").addEventListener("change", function () {
form.querySelector("#LibraryFilteringMode").disabled = this.checked;
if (this.checked) {
form.querySelector("#LibraryFilteringModeContainer").setAttribute("hidden", "");
}
else {
form.querySelector("#LibraryFilteringModeContainer").removeAttribute("hidden");
}
});

page.addEventListener("viewshow", async function () {
Expand Down Expand Up @@ -525,7 +493,6 @@ export default function (page) {

// Advanced settings
form.querySelector("#PublicHost").value = config.PublicHost;
form.querySelector("#IgnoredFileExtensions").value = config.IgnoredFileExtensions.join(" ");
form.querySelector("#IgnoredFolders").value = config.IgnoredFolders.join();

// Experimental settings
Expand Down
64 changes: 28 additions & 36 deletions Shokofin/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,41 @@ <h3>Plugin Compatibility Settings</h3>
<legend>
<h3>Library Settings</h3>
</legend>
<div class="fieldDescription verticalSection-extrabottompadding">If you wish to set the Series/Grouping setting below to "Don't group Series into Seasons", you must disable "Automatically merge series that are spread across multiple folders" in the settings for all Libraries that depend on Shokofin for their metadata.<br>On the other hand, if you want to have Series and Grouping be determined by Shoko, or TvDB/TMDB - you must enable the "Automatically merge series that are spread across multiple folders" setting for all Libraries that use Shokofin for their metadata.<br>See the settings under each individual Library here: <a href="#!/library.html">Library Settings</a></div>
<div class="fieldDescription verticalSection-extrabottompadding">Everything related to how the plugin manages the library.</div>
<div class="selectContainer selectContainer-withDescription">
<label class="selectLabel" for="CollectionGrouping">Create collections:</label>
<select is="emby-select" id="CollectionGrouping" name="CollectionGrouping" class="emby-select-withcolor emby-select">
<option value="None" selected>Do not create Collections</option>
<option value="ShokoSeries">Create Collections for Movies based upon Shoko's Series entries</option>
<option value="ShokoGroup">Create Collections for Movies and Series based upon Shoko's Groups</option>
</select>
<div class="fieldDescription">Determines how to group entities into Collections.</div>
</div>
<div class="selectContainer selectContainer-withDescription">
<label class="selectLabel" for="SpecialsPlacement">Specials placement within seasons:</label>
<select is="emby-select" id="SpecialsPlacement" name="SpecialsPlacement" class="emby-select-withcolor emby-select">
<option value="AfterSeason">Always place Specials after the normal Episodes (Default)</option>
<option value="InBetweenSeasonByAirDate">Use release dates to place Specials</option>
<option value="InBetweenSeasonByOtherData">Loosely use the TvDB/TMDB data available in Shoko to place Specials</option>
<option value="InBetweenSeasonMixed">Either loosely use the TvDB/TMDB data available in Shoko or fallback to using release dates to place Specials</option>
<option value="Excluded">Exclude Specials from the Seasons</option>
</select>
<div class="fieldDescription selectFieldDescription">Determines how Specials are placed within Seasons. <strong>Warning:</strong> Modifying this setting requires a recreation (read as; delete existing then create a new) of any libraries using this plugin — otherwise you <strong>will</strong> have mixed metadata.</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input is="emby-checkbox" type="checkbox" id="VirtualFileSystem" />
<span>Virtual File System (VFS)</span>
<span>Virtual File System&trade; (VFS)</span>
</label>
<div class="fieldDescription checkboxFieldDescription">
<div>Enables the use of the Virtual File System for any media libraries managed by the plugin.</div>
<div>Enables the use of the Virtual File System&trade; for any media libraries managed by the plugin.</div>
<details style="margin-top: 0.5em">
<summary style="margin-bottom: 0.25em">What does it do?</summary>
<summary style="margin-bottom: 0.25em">What does this mean?</summary>
Enabling this setting should in theory make it so you won't have to think about file structure imcompatibilities, since it will override your existing file structure and replace it with a layer of symbolic links managed by the plugin instead of your actual file structure.<strong>Do not enable this for an existing library. If you do, then delete and re-create your library from scratch.</strong>
</details>
</div>
</div>
<div class="selectContainer selectContainer-withDescription">
<div id="LibraryFilteringModeContainer" class="selectContainer selectContainer-withDescription" hidden>
<label class="selectLabel" for="LibraryFilteringMode">Filtering mode:</label>
<select is="emby-select" id="LibraryFilteringMode" name="LibraryFilteringMode" class="emby-select-withcolor emby-select" disabled>
<option value="true" selected>Strict</option>
Expand All @@ -158,10 +178,6 @@ <h3>Library Settings</h3>
<summary style="margin-bottom: 0.25em">What does strict filtering entail?</summary>
Strict filtering means the plugin will filter out any and all unrecognized videos from the active library.
</details>
<details style="margin-top: 0.5em">
<summary style="margin-bottom: 0.25em">What does strict filtering entail?</summary>
Strict filtering means the plugin will filter out any and all unrecognized videos from the active library.
</details>
<details style="margin-top: 0.5em">
<summary style="margin-bottom: 0.25em">What does auto filtering entail?</summary>
Auto filtering means the plugin will only filter out unrecognized videos if no other metadata provider is enabled, otherwise it will leave them in the library.
Expand All @@ -175,34 +191,14 @@ <h3>Library Settings</h3>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input is="emby-checkbox" type="checkbox" id="SeparateMovies" />
<span>Separate Movies From Shows</span>
<span>Separate movies from shows</span>
</label>
<div class="fieldDescription checkboxFieldDescription">This filters out Movies from the Shows in your library.</div>
</div>
<div class="selectContainer selectContainer-withDescription">
<label class="selectLabel" for="CollectionGrouping">Collections:</label>
<select is="emby-select" id="CollectionGrouping" name="CollectionGrouping" class="emby-select-withcolor emby-select">
<option value="None" selected>Do not create Collections</option>
<option value="ShokoSeries">Create Collections for Movies based upon Shoko's Series entries</option>
<option value="ShokoGroup">Create Collections for Movies and Series based upon Shoko's Groups</option>
</select>
<div class="fieldDescription">Determines how to group entities into Collections.</div>
</div>
<div class="selectContainer selectContainer-withDescription">
<label class="selectLabel" for="SpecialsPlacement">Specials placement within seasons:</label>
<select is="emby-select" id="SpecialsPlacement" name="SpecialsPlacement" class="emby-select-withcolor emby-select">
<option value="AfterSeason">Always place Specials after the normal Episodes (Default)</option>
<option value="InBetweenSeasonByAirDate">Use release dates to place Specials</option>
<option value="InBetweenSeasonByOtherData">Loosely use the TvDB/TMDB data available in Shoko to place Specials</option>
<option value="InBetweenSeasonMixed">Either loosely use the TvDB/TMDB data available in Shoko or fallback to using release dates to place Specials</option>
<option value="Excluded">Exclude Specials from the Seasons</option>
</select>
<div class="fieldDescription selectFieldDescription">Determines how Specials are placed within Seasons. <strong>Warning:</strong> Modifying this setting requires a recreation (read as; delete existing then create a new) of any libraries using this plugin — otherwise you <strong>will</strong> have mixed metadata.</div>
<div class="fieldDescription checkboxFieldDescription">This filters out movies from the shows in your library. Disable this if you want your movies to show up as episodes within seasons of your shows instead.</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input is="emby-checkbox" type="checkbox" id="MarkSpecialsWhenGrouped" />
<span>Mark Specials</span>
<span>Mark specials</span>
</label>
<div class="fieldDescription checkboxFieldDescription">Add a number to the title of each Special episode</div>
</div>
Expand Down Expand Up @@ -348,10 +344,6 @@ <h3>Advanced Settings</h3>
<input is="emby-input" type="text" id="PublicHost" label="Public Shoko host URL:" />
<div class="fieldDescription">This is the public URL leading to where Shoko is running. It is used to redirect to Shoko if you click on a Shoko ID in the UI if Shoko and/or Jellyfin is running within a container. It should include both the protocol and the IP/DNS name.</div>
</div>
<div class="inputContainer inputContainer-withDescription">
<input is="emby-input" type="text" id="IgnoredFileExtensions" label="Ignored file extensions:" />
<div class="fieldDescription">A space separated list of file extensions which will be ignored during the library scan.</div>
</div>
<div class="inputContainer inputContainer-withDescription">
<input is="emby-input" type="text" id="IgnoredFolders" label="Ignored folder names:" />
<div class="fieldDescription">A comma separated list of folder names which will be ignored during the library scan.</div>
Expand Down
6 changes: 1 addition & 5 deletions Shokofin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
{
Instance = this;
ConfigurationChanged += OnConfigChanged;
IgnoredFileExtensions = this.Configuration.IgnoredFileExtensions.ToHashSet();
IgnoredFolders = this.Configuration.IgnoredFolders.ToHashSet();
IgnoredFolders = Configuration.IgnoredFolders.ToHashSet();
}

public void OnConfigChanged(object? sender, BasePluginConfiguration e)
{
if (e is not PluginConfiguration config)
return;
IgnoredFileExtensions = config.IgnoredFileExtensions.ToHashSet();
IgnoredFolders = config.IgnoredFolders.ToHashSet();
}

public HashSet<string> IgnoredFileExtensions;

public HashSet<string> IgnoredFolders;

#pragma warning disable 8618
Expand Down
Loading

0 comments on commit fd4df1f

Please sign in to comment.