Fixed: Don't force images to JPG and fix Kodi album art filenames

pull/6/head
ta264 5 years ago
parent 8b860bcb82
commit 8d780f4057

@ -41,12 +41,17 @@ namespace NzbDrone.Core.Test.MediaCoverTests
Mocker.GetMock<IHttpClient>().Setup(c => c.Head(It.IsAny<HttpRequest>())).Returns(_httpResponse);
}
[Test]
public void should_convert_cover_urls_to_local()
[TestCase(".png")]
[TestCase(".jpg")]
public void should_convert_cover_urls_to_local(string extension)
{
var covers = new List<MediaCover.MediaCover>
{
new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner}
new MediaCover.MediaCover
{
Url = "http://dummy.com/test" + extension,
CoverType = MediaCoverTypes.Banner
}
};
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileGetLastWrite(It.IsAny<string>()))
@ -58,15 +63,20 @@ namespace NzbDrone.Core.Test.MediaCoverTests
Subject.ConvertToLocalUrls(12, MediaCoverEntity.Artist, covers);
covers.Single().Url.Should().Be("/MediaCover/12/banner.jpg?lastWrite=1234");
covers.Single().Url.Should().Be("/MediaCover/12/banner" + extension + "?lastWrite=1234");
}
[Test]
public void should_convert_album_cover_urls_to_local()
[TestCase(".png")]
[TestCase(".jpg")]
public void should_convert_album_cover_urls_to_local(string extension)
{
var covers = new List<MediaCover.MediaCover>
{
new MediaCover.MediaCover {CoverType = MediaCoverTypes.Disc}
new MediaCover.MediaCover
{
Url = "http://dummy.com/test" + extension,
CoverType = MediaCoverTypes.Disc
}
};
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileGetLastWrite(It.IsAny<string>()))
@ -78,22 +88,27 @@ namespace NzbDrone.Core.Test.MediaCoverTests
Subject.ConvertToLocalUrls(6, MediaCoverEntity.Album, covers);
covers.Single().Url.Should().Be("/MediaCover/Albums/6/disc.jpg?lastWrite=1234");
covers.Single().Url.Should().Be("/MediaCover/Albums/6/disc" + extension + "?lastWrite=1234");
}
[Test]
public void should_convert_media_urls_to_local_without_time_if_file_doesnt_exist()
[TestCase(".png")]
[TestCase(".jpg")]
public void should_convert_media_urls_to_local_without_time_if_file_doesnt_exist(string extension)
{
var covers = new List<MediaCover.MediaCover>
{
new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner}
new MediaCover.MediaCover
{
Url = "http://dummy.com/test" + extension,
CoverType = MediaCoverTypes.Banner
}
};
Subject.ConvertToLocalUrls(12, MediaCoverEntity.Artist, covers);
covers.Single().Url.Should().Be("/MediaCover/12/banner.jpg");
covers.Single().Url.Should().Be("/MediaCover/12/banner" + extension);
}
[Test]

@ -165,7 +165,7 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Roksbox
return new List<ImageFileResult>(); ;
}
var source = _mediaCoverService.GetCoverPath(artist.Id, MediaCoverEntity.Artist, image.CoverType);
var source = _mediaCoverService.GetCoverPath(artist.Id, MediaCoverEntity.Artist, image.CoverType, image.Extension);
var destination = Path.GetFileName(artist.Path) + Path.GetExtension(source);
return new List<ImageFileResult>{ new ImageFileResult(destination, source) };

@ -205,11 +205,11 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
{
foreach (var image in artist.Metadata.Value.Images)
{
var source = _mediaCoverService.GetCoverPath(artist.Id, MediaCoverEntity.Artist, image.CoverType);
var destination = image.CoverType.ToString().ToLowerInvariant() + Path.GetExtension(image.Url);
var source = _mediaCoverService.GetCoverPath(artist.Id, MediaCoverEntity.Artist, image.CoverType, image.Extension);
var destination = image.CoverType.ToString().ToLowerInvariant() + image.Extension;
if (image.CoverType == MediaCoverTypes.Poster)
{
destination = "folder" + Path.GetExtension(image.Url);
destination = "folder" + image.Extension;
}
yield return new ImageFileResult(destination, source);
@ -222,7 +222,21 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
{
// TODO: Make Source fallback to URL if local does not exist
// var source = _mediaCoverService.GetCoverPath(album.ArtistId, image.CoverType, null, album.Id);
var destination = Path.Combine(albumPath, image.CoverType.ToString().ToLowerInvariant() + Path.GetExtension(image.Url));
string filename;
switch(image.CoverType)
{
case MediaCoverTypes.Cover:
filename = "folder";
break;
case MediaCoverTypes.Disc:
filename = "discart";
break;
default:
continue;
}
var destination = Path.Combine(albumPath, filename + image.Extension);
yield return new ImageFileResult(destination, image.Url);
}

@ -1,3 +1,4 @@
using System.IO;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.MediaCover
@ -26,6 +27,7 @@ namespace NzbDrone.Core.MediaCover
{
public MediaCoverTypes CoverType { get; set; }
public string Url { get; set; }
public string Extension => Path.GetExtension(Url);
public MediaCover()
{

@ -18,7 +18,7 @@ namespace NzbDrone.Core.MediaCover
public interface IMapCoversToLocal
{
void ConvertToLocalUrls(int entityId, MediaCoverEntity coverEntity, IEnumerable<MediaCover> covers);
string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes mediaCoverTypes, int? height = null);
string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes mediaCoverTypes, string extension, int? height = null);
}
public class MediaCoverService :
@ -59,17 +59,17 @@ namespace NzbDrone.Core.MediaCover
_coverRootFolder = appFolderInfo.GetMediaCoverPath();
}
public string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes coverTypes, int? height = null)
public string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes coverTypes, string extension, int? height = null)
{
var heightSuffix = height.HasValue ? "-" + height.ToString() : "";
if (coverEntity == MediaCoverEntity.Album)
{
return Path.Combine(GetAlbumCoverPath(entityId), coverTypes.ToString().ToLower() + heightSuffix + ".jpg");
return Path.Combine(GetAlbumCoverPath(entityId), coverTypes.ToString().ToLower() + heightSuffix + extension);
}
else
{
return Path.Combine(GetArtistCoverPath(entityId), coverTypes.ToString().ToLower() + heightSuffix + ".jpg");
return Path.Combine(GetArtistCoverPath(entityId), coverTypes.ToString().ToLower() + heightSuffix + extension);
}
}
@ -77,15 +77,15 @@ namespace NzbDrone.Core.MediaCover
{
foreach (var mediaCover in covers)
{
var filePath = GetCoverPath(entityId, coverEntity, mediaCover.CoverType, null);
var filePath = GetCoverPath(entityId, coverEntity, mediaCover.CoverType, mediaCover.Extension, null);
if (coverEntity == MediaCoverEntity.Album)
{
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/Albums/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg";
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/Albums/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + mediaCover.Extension;
}
else
{
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + ".jpg";
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + mediaCover.Extension;
}
if (_diskProvider.FileExists(filePath))
@ -110,7 +110,7 @@ namespace NzbDrone.Core.MediaCover
{
foreach (var cover in artist.Metadata.Value.Images)
{
var fileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType);
var fileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType, cover.Extension);
var alreadyExists = false;
try
@ -141,7 +141,7 @@ namespace NzbDrone.Core.MediaCover
{
foreach (var cover in album.Images.Where(e => e.CoverType == MediaCoverTypes.Cover))
{
var fileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, null);
var fileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, null);
var alreadyExists = false;
try
{
@ -169,7 +169,7 @@ namespace NzbDrone.Core.MediaCover
private void DownloadCover(Artist artist, MediaCover cover, DateTime lastModified)
{
var fileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType);
var fileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType, cover.Extension);
_logger.Info("Downloading {0} for {1} {2}", cover.CoverType, artist, cover.Url);
_httpClient.DownloadFile(cover.Url, fileName);
@ -186,7 +186,7 @@ namespace NzbDrone.Core.MediaCover
private void DownloadAlbumCover(Album album, MediaCover cover, DateTime lastModified)
{
var fileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, null);
var fileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, null);
_logger.Info("Downloading {0} for {1} {2}", cover.CoverType, album, cover.Url);
_httpClient.DownloadFile(cover.Url, fileName);
@ -207,8 +207,8 @@ namespace NzbDrone.Core.MediaCover
foreach (var height in heights)
{
var mainFileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType);
var resizeFileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType, height);
var mainFileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType, cover.Extension);
var resizeFileName = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType, cover.Extension, height);
if (forceResize || !_diskProvider.FileExists(resizeFileName) || _diskProvider.GetFileSize(resizeFileName) == 0)
{
@ -232,8 +232,8 @@ namespace NzbDrone.Core.MediaCover
foreach (var height in heights)
{
var mainFileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, null);
var resizeFileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, height);
var mainFileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, null);
var resizeFileName = GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, height);
if (forceResize || !_diskProvider.FileExists(resizeFileName) || _diskProvider.GetFileSize(resizeFileName) == 0)
{

Loading…
Cancel
Save