Fixed: Embedding album art on import

On import the album release is adjusted, which triggers an
AlbumEditedEvent which in turn coverts media cover urls to local
urls.  The addition of ?lastWrite=xxx broke the calculation of
extenions from the URL.  To fix, only set the extension and don't
update the extension if url is changed.
pull/893/head
ta264 5 years ago
parent c898a18d31
commit 1ab8c5a7bb

@ -66,6 +66,30 @@ namespace NzbDrone.Core.Test.MediaCoverTests
covers.Single().Url.Should().Be("/MediaCover/12/banner" + extension + "?lastWrite=1234"); covers.Single().Url.Should().Be("/MediaCover/12/banner" + extension + "?lastWrite=1234");
} }
[TestCase(".png")]
[TestCase(".jpg")]
public void convert_to_local_url_should_not_change_extension(string extension)
{
var covers = new List<MediaCover.MediaCover>
{
new MediaCover.MediaCover
{
Url = "http://dummy.com/test" + extension,
CoverType = MediaCoverTypes.Banner
}
};
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileGetLastWrite(It.IsAny<string>()))
.Returns(new DateTime(1234));
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(It.IsAny<string>()))
.Returns(true);
Subject.ConvertToLocalUrls(12, MediaCoverEntity.Artist, covers);
covers.Single().Extension.Should().Be(extension);
}
[TestCase(".png")] [TestCase(".png")]
[TestCase(".jpg")] [TestCase(".jpg")]
public void should_convert_album_cover_urls_to_local(string extension) public void should_convert_album_cover_urls_to_local(string extension)

@ -1,4 +1,5 @@
using System.IO; using System.IO;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.MediaCover namespace NzbDrone.Core.MediaCover
@ -25,9 +26,25 @@ namespace NzbDrone.Core.MediaCover
public class MediaCover : IEmbeddedDocument public class MediaCover : IEmbeddedDocument
{ {
private string _url;
public string Url
{
get
{
return _url;
}
set
{
_url = value;
if (Extension.IsNullOrWhiteSpace())
{
Extension = Path.GetExtension(value);
}
}
}
public MediaCoverTypes CoverType { get; set; } public MediaCoverTypes CoverType { get; set; }
public string Url { get; set; } public string Extension { get; private set; }
public string Extension => Path.GetExtension(Url);
public MediaCover() public MediaCover()
{ {

@ -86,6 +86,7 @@ namespace NzbDrone.Core.MediaFiles
if (cover != null) if (cover != null)
{ {
imageFile = _mediaCoverService.GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, null); imageFile = _mediaCoverService.GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, null);
_logger.Trace($"Embedding: {imageFile}");
var fileInfo = _diskProvider.GetFileInfo(imageFile); var fileInfo = _diskProvider.GetFileInfo(imageFile);
if (fileInfo.Exists) if (fileInfo.Exists)
{ {

Loading…
Cancel
Save