Skip to content

Commit

Permalink
Fix missing Show Season Images
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Nov 1, 2021
1 parent c1496f1 commit a70bed6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TVRename/Sources/TheTVDB/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public static JObject GetMovieV4(int code, string requestedLanguageCode)
}

[NotNull]
public static JObject GetSeasonEpisodesV4(int showId, int seasonId, string requestedLanguageCode)
public static JObject GetSeasonEpisodesV4(int seasonId, string requestedLanguageCode)
{
string uri = $"{TokenProvider.TVDB_API_URL}/seasons/{seasonId}/extended";
return GetUrl(uri, requestedLanguageCode);
Expand Down
52 changes: 34 additions & 18 deletions TVRename/Sources/TheTVDB/LocalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public bool GetUpdates(bool showErrorMsgBox, CancellationToken cts, IEnumerable<
}

//If this date is in the last week then this needs to be the last call to the update
const int OFFSET =(24 * 60 * 60); //todo NOW Revert to 0
const int OFFSET =(0);

DateTime requestedTime = GetRequestedTime(updateFromEpochTime - OFFSET, numberofCallsMade);

Expand Down Expand Up @@ -1335,22 +1335,8 @@ private void AddShowImagesV4(JObject r, CachedSeriesInfo si)
{
foreach (var imageJson in r["data"]["artworks"])
{
int imageCodeType = (int)imageJson["type"];

ShowImage mi = new()
{
Id = (int)imageJson["id"],
ImageUrl = API.GetImageURL((string)imageJson["image"]),
ThumbnailUrl = API.GetImageURL((string)imageJson["thumbnail"]),
LanguageCode = (string)imageJson["language"],
Rating = (int)imageJson["score"],
SeriesId = si.TvdbCode,
ImageStyle = MapBannerTVDBV4APICode(imageCodeType),
Subject = MapSubjectTVDBV4APICode(imageCodeType),
SeriesSource = TVDoc.ProviderType.TheTVDB,
RatingCount = 1
};

ShowImage mi = ConvertJsonToImage(imageJson, si);

si.AddOrUpdateImage(mi);
}
}
Expand Down Expand Up @@ -2263,7 +2249,7 @@ public void ReloadEpisodesV4(int code, Locale locale, CachedSeriesInfo si, Proce
Thread.CurrentThread.Name ??= $"Download Season {s.SeasonNumber} for {si.Name}"; // Can only set it once
try
{
JObject seasonInfo = API.GetSeasonEpisodesV4(code, s.SeasonId,
JObject seasonInfo = API.GetSeasonEpisodesV4(s.SeasonId,
locale.LanguageToUse(TVDoc.ProviderType.TheTVDB).ThreeAbbreviation);

JToken episodeData = seasonInfo["data"]?["episodes"];
Expand All @@ -2277,6 +2263,17 @@ public void ReloadEpisodesV4(int code, Locale locale, CachedSeriesInfo si, Proce
GenerateAddEpisodeV4(code, locale, si, x,order);
});
}

JToken imageData = seasonInfo["data"]?["artwork"];
if (imageData != null)
{
foreach (ShowImage newImage in imageData.Select(im => ConvertJsonToImage(im,si)))
{
newImage.SeasonId = s.SeasonId;
newImage.SeasonNumber = s.SeasonNumber;
si.AddOrUpdateImage(newImage);
}
}
}
catch (SourceConnectivityException sce)
{
Expand All @@ -2289,6 +2286,25 @@ public void ReloadEpisodesV4(int code, Locale locale, CachedSeriesInfo si, Proce
});
}

private ShowImage ConvertJsonToImage(JToken imageJson,CachedSeriesInfo si)
{
int imageCodeType = (int)imageJson["type"];

return new ShowImage
{
Id = (int)imageJson["id"],
ImageUrl = API.GetImageURL((string)imageJson["image"]),
ThumbnailUrl = API.GetImageURL((string)imageJson["thumbnail"]),
LanguageCode = (string)imageJson["language"],
Rating = (int)imageJson["score"],
SeriesId = si.TvdbCode,
ImageStyle = MapBannerTVDBV4APICode(imageCodeType),
Subject = MapSubjectTVDBV4APICode(imageCodeType),
SeriesSource = TVDoc.ProviderType.TheTVDB,
RatingCount = 1
};
}

private void GenerateAddEpisodeV4(int code, Locale locale, CachedSeriesInfo si, JToken x, ProcessedSeason.SeasonType order)
{
try
Expand Down

0 comments on commit a70bed6

Please sign in to comment.