Add GenreSubstitution option

This commit is contained in:
xjasonlyu
2022-06-28 13:48:50 +08:00
parent 7f04b239d6
commit 6ab4f8a31d
3 changed files with 26 additions and 12 deletions

View File

@@ -59,6 +59,8 @@ public class PluginConfiguration : BasePluginConfiguration
#endregion
#region Genre
public bool EnableGenreSubstitution { get; set; } = true;
public string GenreSubstitutionTable { get; set; } = DefaultGenreSubstitutionTable;

View File

@@ -94,6 +94,13 @@
</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescripton">
<label class="emby-checkbox-label">
<input id="chkEnableGenreSubstitution" is="emby-checkbox" name="chkEnableGenreSubstitution" type="checkbox"/>
<span>Enable Genre Substitution</span>
</label>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabel-float inputLabelUnfocused" for="txtGenreSubstitutionTable">Genre substitution table:</label>
<textarea class="emby-input" id="txtGenreSubstitutionTable" is="emby-input" name="txtGenreSubstitutionTable" rows="10" type="text"></textarea>
@@ -148,6 +155,7 @@
$('#txtBaiduAppId', page).val(config.BaiduAppId).change();
$('#txtBaiduAppKey', page).val(config.BaiduAppKey).change();
$('#txtGoogleApiKey', page).val(config.GoogleApiKey).change();
page.querySelector('#chkEnableGenreSubstitution').checked = config.EnableGenreSubstitution;
$('#txtGenreSubstitutionTable', page).val(config.GenreSubstitutionTable).change();
Dashboard.hideLoadingMsg();
});
@@ -167,6 +175,7 @@
config.BaiduAppId = $('#txtBaiduAppId', form).val();
config.BaiduAppKey = $('#txtBaiduAppKey', form).val();
config.GoogleApiKey = $('#txtGoogleApiKey', form).val();
config.EnableGenreSubstitution = $('#chkEnableGenreSubstitution').prop('checked');
config.GenreSubstitutionTable = $('#txtGenreSubstitutionTable', form).val();
ApiClient.updatePluginConfiguration(JavTubePluginConfig.pluginUniqueId, config).then(
Dashboard.processPluginConfigurationUpdateResult);

View File

@@ -80,19 +80,22 @@ public class OrganizeGenresTask : IScheduledTask
var genres = item.Genres?.ToList() ?? new List<string>();
// Deserialize Text to Substitution Table.
var substitutionTable = GenreHelper.DeserializeSubstitutionTable(
Plugin.Instance.Configuration.GenreSubstitutionTable);
// Replace Genres.
foreach (var genre in genres.Where(genre =>
substitutionTable.ContainsKey(genre)).ToArray())
if (Plugin.Instance.Configuration.EnableGenreSubstitution)
{
var value = substitutionTable[genre];
if (string.IsNullOrWhiteSpace(value))
genres.Remove(genre); // should just be removed.
else
genres[genres.IndexOf(genre)] = value; // replace.
// Deserialize Text to Substitution Table.
var substitutionTable = GenreHelper.DeserializeSubstitutionTable(
Plugin.Instance.Configuration.GenreSubstitutionTable);
// Replace Genres.
foreach (var genre in genres.Where(genre =>
substitutionTable.ContainsKey(genre)).ToArray())
{
var value = substitutionTable[genre];
if (string.IsNullOrWhiteSpace(value))
genres.Remove(genre); // should just be removed.
else
genres[genres.IndexOf(genre)] = value; // replace.
}
}
try