Skip to content

Commit

Permalink
Add option to fallback to original language (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
scampower3 authored Jun 24, 2024
1 parent f247a33 commit a3e485a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Jellyfin.Plugin.Tvdb/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,10 @@ public int MetadataUpdateInHours
/// Gets or sets a value indicating whether to include missing specials.
/// </summary>
public bool IncludeMissingSpecials { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether to fallback to original language.
/// </summary>
public bool FallbackToOriginalLanguage { get; set; } = false;
}
}
6 changes: 6 additions & 0 deletions Jellyfin.Plugin.Tvdb/Configuration/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ <h2 class="sectionTitle">TheTVDB Settings:</h2>
<input is="emby-checkbox" type="checkbox" id="includeMissingSpecials" />
<span>Include missing specials</span>
</label>
<label class="checkboxContainer">
<input is="emby-checkbox" type="checkbox" id="fallbackToOriginalLanguage" />
<span>Fallback to Original Language (Last resort if other fallback languages fails)</span>
</label>
<br />
<div>
<button is="emby-button" type="submit" data-theme="b" class="raised button-submit block">
Expand All @@ -77,6 +81,7 @@ <h2 class="sectionTitle">TheTVDB Settings:</h2>
document.getElementById('metadataUpdateInHours').value = config.MetadataUpdateInHours;
document.getElementById('fallbackLanguages').value = config.FallbackLanguages;
document.getElementById('includeMissingSpecials').checked = config.IncludeMissingSpecials;
document.getElementById('fallbackToOriginalLanguage').checked = config.FallbackToOriginalLanguage;
Dashboard.hideLoadingMsg();
});
},
Expand All @@ -91,6 +96,7 @@ <h2 class="sectionTitle">TheTVDB Settings:</h2>
config.MetadataUpdateInHours = document.getElementById('metadataUpdateInHours').value;
config.FallbackLanguages = document.getElementById('fallbackLanguages').value;
config.IncludeMissingSpecials = document.getElementById('includeMissingSpecials').checked;
config.FallbackToOriginalLanguage = document.getElementById('fallbackToOriginalLanguage').checked;
ApiClient.updatePluginConfiguration(TvdbPluginConfiguration.uniquePluginId, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
Expand Down
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbEpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ private async Task<MetadataResult<Episode>> MapEpisodeToResult(EpisodeInfo id, E
IndexNumberEnd = id.IndexNumberEnd,
// Tvdb uses 3 letter code for language (prob ISO 639-2)
// Reverts to OriginalName if no translation is found
Name = episode.Translations.GetTranslatedNamedOrDefault(id.MetadataLanguage) ?? episode.Name,
Overview = episode.Translations.GetTranslatedOverviewOrDefault(id.MetadataLanguage) ?? episode.Overview,
Name = episode.Translations.GetTranslatedNamedOrDefault(id.MetadataLanguage) ?? TvdbUtils.ReturnOriginalLanguageOrDefault(episode.Name),
Overview = episode.Translations.GetTranslatedOverviewOrDefault(id.MetadataLanguage) ?? TvdbUtils.ReturnOriginalLanguageOrDefault(episode.Overview),
OriginalTitle = episode.Name,
}
};
Expand Down
8 changes: 4 additions & 4 deletions Jellyfin.Plugin.Tvdb/Providers/TvdbSeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ private RemoteSearchResult MapSeriesToRemoteSearchResult(SeriesExtendedRecord se
{
var remoteResult = new RemoteSearchResult
{
Name = series.Translations.GetTranslatedNamedOrDefault(language) ?? series.Name,
Overview = series.Translations.GetTranslatedOverviewOrDefault(language)?.Trim() ?? series.Overview?.Trim(),
Name = series.Translations.GetTranslatedNamedOrDefault(language) ?? TvdbUtils.ReturnOriginalLanguageOrDefault(series.Name),
Overview = series.Translations.GetTranslatedOverviewOrDefault(language)?.Trim() ?? TvdbUtils.ReturnOriginalLanguageOrDefault(series.Overview?.Trim()),
SearchProviderName = Name,
ImageUrl = series.Image
};
Expand Down Expand Up @@ -446,8 +446,8 @@ private static void MapSeriesToResult(MetadataResult<Series> result, SeriesExten
series.SetTvdbId(tvdbSeries.Id);
// Tvdb uses 3 letter code for language (prob ISO 639-2)
// Reverts to OriginalName if no translation is found
series.Name = tvdbSeries.Translations.GetTranslatedNamedOrDefault(info.MetadataLanguage) ?? tvdbSeries.Name;
series.Overview = tvdbSeries.Translations.GetTranslatedOverviewOrDefault(info.MetadataLanguage) ?? tvdbSeries.Overview;
series.Name = tvdbSeries.Translations.GetTranslatedNamedOrDefault(info.MetadataLanguage) ?? TvdbUtils.ReturnOriginalLanguageOrDefault(tvdbSeries.Name);
series.Overview = tvdbSeries.Translations.GetTranslatedOverviewOrDefault(info.MetadataLanguage) ?? TvdbUtils.ReturnOriginalLanguageOrDefault(tvdbSeries.Overview);
series.OriginalTitle = tvdbSeries.Name;
result.ResultLanguage = info.MetadataLanguage;
series.AirDays = TvdbUtils.GetAirDays(tvdbSeries.AirsDays).ToArray();
Expand Down
12 changes: 12 additions & 0 deletions Jellyfin.Plugin.Tvdb/TvdbUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static class TvdbUtils
/// </summary>
public const string TvdbBaseUrl = "https://www.thetvdb.com/";

private static bool FallbackToOriginalLanguage => TvdbPlugin.Instance?.Configuration.FallbackToOriginalLanguage ?? false;

/// <summary>
/// Converts SeriesAirsDays to DayOfWeek array.
/// </summary>
Expand Down Expand Up @@ -57,5 +59,15 @@ public static IEnumerable<DayOfWeek> GetAirDays(SeriesAirsDays seriesAirsDays)
yield return DayOfWeek.Saturday;
}
}

/// <summary>
/// Returns the original language if fallback is enabled.
/// </summary>
/// <param name="text">String to return if fallback is enabled.</param>
/// <returns>string or null.</returns>
public static string? ReturnOriginalLanguageOrDefault(string? text)
{
return FallbackToOriginalLanguage ? text : null;
}
}
}

0 comments on commit a3e485a

Please sign in to comment.