Skip to content

Commit

Permalink
fix -1 bug in tvshow.nfo
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Dec 27, 2022
1 parent 13d93da commit ac4d1fd
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions TVRename/ItemsAndActions/ActionNfoShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,11 @@ protected override ActionOutcome UpdateFile()
CachedSeriesInfo? cachedSeries = SelectedShow!.CachedShow;
root.UpdateElement("title", SelectedShow.ShowName);

float? showRating = cachedSeries?.SiteRating;
if (showRating.HasValue)
{
UpdateRatings(root, showRating.Value.ToString(CultureInfo.InvariantCulture), cachedSeries!.SiteRatingVotes);
}

if (cachedSeries is not null)
{
root.UpdateElement("originaltitle", SelectedShow!.ShowName);
root.UpdateElement("sorttitle", UI.GenerateShowUiName(SelectedShow));
root.ReplaceElements("studio", cachedSeries.Networks);
root.UpdateElement("id", cachedSeries.TvdbCode);
root.UpdateElement("episodeguide", GenerateEpisdeGuideJson(cachedSeries));
root.UpdateElement("episodeguide", GenerateEpisodeGuideJson(cachedSeries));
root.UpdateElement("runtime", cachedSeries.Runtime, true);
root.UpdateElement("mpaa", cachedSeries.ContentRating, true);
root.UpdateElement("premiered", cachedSeries.FirstAired);
Expand All @@ -54,13 +46,14 @@ protected override ActionOutcome UpdateFile()
root.UpdateElement("plot", cachedSeries.Overview);
root.UpdateElement("trailer", cachedSeries.TrailerUrl);

root.ReplaceElements("studio", cachedSeries.Networks);
root.ReplaceElements("genre", SelectedShow.Genres);

UpdateId(root, "tvdb", SelectedShow.Provider == TVDoc.ProviderType.TheTVDB ? "true" : "false", SelectedShow.TvdbCode);
UpdateId(root, "tmdb", SelectedShow.Provider == TVDoc.ProviderType.TMDB ? "true" : "false", SelectedShow.TmdbCode);
UpdateId(root, "tvmaze", SelectedShow.Provider == TVDoc.ProviderType.TVmaze ? "true" : "false", SelectedShow.TvMazeId);
UpdateId(root, "imdb", "false", SelectedShow.ImdbCode);

root.ReplaceElements("genre", SelectedShow.Genres);

ReplaceActors(root, SelectedShow.Actors);

ReplaceThumbs(root, "poster", cachedSeries.Images(MediaImage.ImageType.poster));
Expand All @@ -69,12 +62,18 @@ protected override ActionOutcome UpdateFile()
ReplaceThumbs(root, "clearlogo", cachedSeries.Images(MediaImage.ImageType.clearLogo));

ReplaceFanart(root, cachedSeries.Images(MediaImage.ImageType.background));

float showRating = cachedSeries.SiteRating;
if (showRating > 0)
{
UpdateRatings(root, showRating.ToString(CultureInfo.InvariantCulture), cachedSeries.SiteRatingVotes);
}
}
doc.Save(Where.FullName);
return ActionOutcome.Success();
}

private string GenerateEpisdeGuideJson(CachedSeriesInfo cachedSeries)
private static string GenerateEpisodeGuideJson(CachedMediaInfo cachedSeries)
{
JObject ids = new();
AddId(ids, "tvmaze", cachedSeries.TvMazeCode);
Expand All @@ -85,7 +84,7 @@ private string GenerateEpisdeGuideJson(CachedSeriesInfo cachedSeries)
return ids.ToString();
}

private void AddId(JObject json, string key, string? id)
private static void AddId(JObject json, string key, string? id)
{
if (id is null || !id.HasValue())
{
Expand All @@ -94,9 +93,9 @@ private void AddId(JObject json, string key, string? id)
json.Add(key,id);
}

private void AddId(JObject json, string key, int? id)
private static void AddId(JObject json, string key, int? id)
{
if (id is null or 0)
if (id is null or 0 or -1)
{
return;
}
Expand Down

0 comments on commit ac4d1fd

Please sign in to comment.