From b8481006932e904c93f46182ec4d91030d1461e1 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 15 Jan 2023 20:09:34 -0800 Subject: [PATCH] Fixed: Images for some series not downloading Closes #5376 --- .../MetadataSource/SkyHook/SkyHookProxyFixture.cs | 4 ++-- .../Migration/183_update_images_remote_url.cs | 15 +++++++++++++++ .../Metadata/Consumers/Roksbox/RoksboxMetadata.cs | 4 ++-- .../Metadata/Consumers/Wdtv/WdtvMetadata.cs | 6 +++--- .../Metadata/Consumers/Xbmc/XbmcMetadata.cs | 8 ++++---- src/NzbDrone.Core/MediaCover/MediaCover.cs | 4 ++-- src/NzbDrone.Core/MediaCover/MediaCoverService.cs | 8 +++----- .../MetadataSource/SkyHook/SkyHookProxy.cs | 2 +- .../Notifications/Discord/Discord.cs | 8 ++++---- src/NzbDrone.Core/Notifications/Gotify/Gotify.cs | 2 +- src/Sonarr.Api.V3/Series/SeriesResource.cs | 5 ++++- 11 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/183_update_images_remote_url.cs diff --git a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs index 6b4faa5cb..31cd23057 100644 --- a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs +++ b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using FluentAssertions; @@ -102,7 +102,7 @@ private void ValidateEpisode(Episode episode) episode.AirDateUtc.Value.Kind.Should().Be(DateTimeKind.Utc); } - episode.Images.Any(i => i.CoverType == MediaCoverTypes.Screenshot && i.Url.Contains("-940.")) + episode.Images.Any(i => i.CoverType == MediaCoverTypes.Screenshot && i.RemoteUrl.Contains("-940.")) .Should() .BeFalse(); } diff --git a/src/NzbDrone.Core/Datastore/Migration/183_update_images_remote_url.cs b/src/NzbDrone.Core/Datastore/Migration/183_update_images_remote_url.cs new file mode 100644 index 000000000..e100657e0 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/183_update_images_remote_url.cs @@ -0,0 +1,15 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(183)] + public class update_images_remote_url : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("UPDATE Episodes SET Images = REPLACE(Images, '\"url\"', '\"remoteUrl\"')"); + Execute.Sql("UPDATE Series SET Images = REPLACE(Images, '\"url\"', '\"remoteUrl\"'), Actors = REPLACE(Actors, '\"url\"', '\"remoteUrl\"'), Seasons = REPLACE(Seasons, '\"url\"', '\"remoteUrl\"')"); + } + } +} diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/Roksbox/RoksboxMetadata.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/Roksbox/RoksboxMetadata.cs index 343873072..b8e717392 100644 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/Roksbox/RoksboxMetadata.cs +++ b/src/NzbDrone.Core/Extras/Metadata/Consumers/Roksbox/RoksboxMetadata.cs @@ -227,7 +227,7 @@ public override List SeasonImages(Series series, Season season) var filename = Path.GetFileName(seasonFolder) + ".jpg"; var path = series.Path.GetRelativePath(Path.Combine(series.Path, seasonFolder, filename)); - return new List { new ImageFileResult(path, image.Url) }; + return new List { new ImageFileResult(path, image.RemoteUrl) }; } public override List EpisodeImages(Series series, EpisodeFile episodeFile) @@ -245,7 +245,7 @@ public override List EpisodeImages(Series series, EpisodeFile e return new List(); } - return new List { new ImageFileResult(GetEpisodeImageFilename(episodeFile.RelativePath), screenshot.Url) }; + return new List { new ImageFileResult(GetEpisodeImageFilename(episodeFile.RelativePath), screenshot.RemoteUrl) }; } private string GetEpisodeMetadataFilename(string episodeFilePath) diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/Wdtv/WdtvMetadata.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/Wdtv/WdtvMetadata.cs index ef0a6b9b8..d9f052799 100644 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/Wdtv/WdtvMetadata.cs +++ b/src/NzbDrone.Core/Extras/Metadata/Consumers/Wdtv/WdtvMetadata.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -220,7 +220,7 @@ public override List SeasonImages(Series series, Season season) var path = Path.Combine(seasonFolder, "folder.jpg"); - return new List { new ImageFileResult(path, image.Url) }; + return new List { new ImageFileResult(path, image.RemoteUrl) }; } public override List EpisodeImages(Series series, EpisodeFile episodeFile) @@ -238,7 +238,7 @@ public override List EpisodeImages(Series series, EpisodeFile e return new List(); } - return new List { new ImageFileResult(GetEpisodeImageFilename(episodeFile.RelativePath), screenshot.Url) }; + return new List { new ImageFileResult(GetEpisodeImageFilename(episodeFile.RelativePath), screenshot.RemoteUrl) }; } private string GetEpisodeMetadataFilename(string episodeFilePath) diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs index 5ac8e5eff..78a90804e 100644 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs +++ b/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs @@ -205,7 +205,7 @@ public override MetadataFileResult SeriesMetadata(Series series) if (actor.Images.Any()) { - xmlActor.Add(new XElement("thumb", actor.Images.First().Url)); + xmlActor.Add(new XElement("thumb", actor.Images.First().RemoteUrl)); } tvShow.Add(xmlActor); @@ -287,7 +287,7 @@ public override MetadataFileResult EpisodeMetadata(Series series, EpisodeFile ep } else { - details.Add(new XElement("thumb", image.Url)); + details.Add(new XElement("thumb", image.RemoteUrl)); } details.Add(new XElement("watched", watched)); @@ -394,7 +394,7 @@ public override List EpisodeImages(Series series, EpisodeFile e return new List { - new ImageFileResult(GetEpisodeImageFilename(episodeFile.RelativePath), screenshot.Url) + new ImageFileResult(GetEpisodeImageFilename(episodeFile.RelativePath), screenshot.RemoteUrl) }; } catch (Exception ex) @@ -427,7 +427,7 @@ private IEnumerable ProcessSeasonImages(Series series, Season s filename = string.Format("season-specials-{0}.jpg", image.CoverType.ToString().ToLower()); } - yield return new ImageFileResult(filename, image.Url); + yield return new ImageFileResult(filename, image.RemoteUrl); } } diff --git a/src/NzbDrone.Core/MediaCover/MediaCover.cs b/src/NzbDrone.Core/MediaCover/MediaCover.cs index acea3ab42..d98f50e18 100644 --- a/src/NzbDrone.Core/MediaCover/MediaCover.cs +++ b/src/NzbDrone.Core/MediaCover/MediaCover.cs @@ -22,10 +22,10 @@ public MediaCover() { } - public MediaCover(MediaCoverTypes coverType, string url) + public MediaCover(MediaCoverTypes coverType, string remoteUrl) { CoverType = coverType; - Url = url; + RemoteUrl = remoteUrl; } } } diff --git a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs index d45ab6161..b4c6f0022 100644 --- a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -77,7 +77,6 @@ public void ConvertToLocalUrls(int seriesId, IEnumerable covers) // Series isn't in Sonarr yet, map via a proxy to circument referrer issues foreach (var mediaCover in covers) { - mediaCover.RemoteUrl = mediaCover.Url; mediaCover.Url = _mediaCoverProxy.RegisterUrl(mediaCover.RemoteUrl); } } @@ -87,7 +86,6 @@ public void ConvertToLocalUrls(int seriesId, IEnumerable covers) { var filePath = GetCoverPath(seriesId, mediaCover.CoverType); - mediaCover.RemoteUrl = mediaCover.Url; mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + seriesId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg"; if (_diskProvider.FileExists(filePath)) @@ -115,7 +113,7 @@ private bool EnsureCovers(Series series) var alreadyExists = false; try { - alreadyExists = _coverExistsSpecification.AlreadyExists(cover.Url, fileName); + alreadyExists = _coverExistsSpecification.AlreadyExists(cover.RemoteUrl, fileName); if (!alreadyExists) { DownloadCover(series, cover); @@ -159,8 +157,8 @@ private void DownloadCover(Series series, MediaCover cover) { var fileName = GetCoverPath(series.Id, cover.CoverType); - _logger.Info("Downloading {0} for {1} {2}", cover.CoverType, series, cover.Url); - _httpClient.DownloadFile(cover.Url, fileName); + _logger.Info("Downloading {0} for {1} {2}", cover.CoverType, series, cover.RemoteUrl); + _httpClient.DownloadFile(cover.RemoteUrl, fileName); } private void EnsureResizedCovers(Series series, MediaCover cover, bool forceResize) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index c5ff70ddb..97c91ed56 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -310,7 +310,7 @@ private static MediaCover.MediaCover MapImage(ImageResource arg) { return new MediaCover.MediaCover { - Url = arg.Url, + RemoteUrl = arg.Url, CoverType = MapCoverType(arg.CoverType) }; } diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index d7f3479cd..f6e22ecb7 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -48,7 +48,7 @@ public override void OnGrab(GrabMessage message) { embed.Thumbnail = new DiscordImage { - Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url + Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl }; } @@ -56,7 +56,7 @@ public override void OnGrab(GrabMessage message) { embed.Image = new DiscordImage { - Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url + Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.RemoteUrl }; } @@ -139,7 +139,7 @@ public override void OnDownload(DownloadMessage message) { embed.Thumbnail = new DiscordImage { - Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url + Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl }; } @@ -147,7 +147,7 @@ public override void OnDownload(DownloadMessage message) { embed.Image = new DiscordImage { - Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url + Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.RemoteUrl }; } diff --git a/src/NzbDrone.Core/Notifications/Gotify/Gotify.cs b/src/NzbDrone.Core/Notifications/Gotify/Gotify.cs index 4c6b9ad22..53e175fa3 100644 --- a/src/NzbDrone.Core/Notifications/Gotify/Gotify.cs +++ b/src/NzbDrone.Core/Notifications/Gotify/Gotify.cs @@ -101,7 +101,7 @@ private void SendNotification(string title, string message, Series series) if (Settings.IncludeSeriesPoster && series != null) { - var poster = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url; + var poster = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl; if (poster != null) { diff --git a/src/Sonarr.Api.V3/Series/SeriesResource.cs b/src/Sonarr.Api.V3/Series/SeriesResource.cs index 1bdf58ae3..c57e52af5 100644 --- a/src/Sonarr.Api.V3/Series/SeriesResource.cs +++ b/src/Sonarr.Api.V3/Series/SeriesResource.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Languages; using NzbDrone.Core.MediaCover; using NzbDrone.Core.Tv; @@ -100,7 +101,9 @@ public static SeriesResource ToResource(this NzbDrone.Core.Tv.Series model, bool // PreviousAiring Network = model.Network, AirTime = model.AirTime, - Images = model.Images, + + // JsonClone + Images = model.Images.JsonClone(), Seasons = model.Seasons.ToResource(includeSeasonImages), Year = model.Year,