|
|
|
@ -19,7 +19,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, string extension, int? height = null);
|
|
|
|
|
string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes coverType, string extension, int? height = null);
|
|
|
|
|
void EnsureBookCovers(Book book);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -68,33 +68,36 @@ namespace NzbDrone.Core.MediaCover
|
|
|
|
|
_coverRootFolder = appFolderInfo.GetMediaCoverPath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes coverTypes, string extension, int? height = null)
|
|
|
|
|
public string GetCoverPath(int entityId, MediaCoverEntity coverEntity, MediaCoverTypes coverType, string extension, int? height = null)
|
|
|
|
|
{
|
|
|
|
|
var heightSuffix = height.HasValue ? "-" + height.ToString() : "";
|
|
|
|
|
|
|
|
|
|
if (coverEntity == MediaCoverEntity.Book)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(GetBookCoverPath(entityId), coverTypes.ToString().ToLower() + heightSuffix + extension);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(GetAuthorCoverPath(entityId), coverTypes.ToString().ToLower() + heightSuffix + extension);
|
|
|
|
|
return Path.Combine(GetBookCoverPath(entityId), coverType.ToString().ToLower() + heightSuffix + GetExtension(coverType, extension));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Path.Combine(GetAuthorCoverPath(entityId), coverType.ToString().ToLower() + heightSuffix + GetExtension(coverType, extension));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConvertToLocalUrls(int entityId, MediaCoverEntity coverEntity, IEnumerable<MediaCover> covers)
|
|
|
|
|
{
|
|
|
|
|
foreach (var mediaCover in covers)
|
|
|
|
|
{
|
|
|
|
|
if (mediaCover.CoverType == MediaCoverTypes.Unknown)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filePath = GetCoverPath(entityId, coverEntity, mediaCover.CoverType, mediaCover.Extension, null);
|
|
|
|
|
|
|
|
|
|
if (coverEntity == MediaCoverEntity.Book)
|
|
|
|
|
{
|
|
|
|
|
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/Books/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + mediaCover.Extension;
|
|
|
|
|
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/Books/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + GetExtension(mediaCover.CoverType, mediaCover.Extension);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + mediaCover.Extension;
|
|
|
|
|
mediaCover.Url = _configFileProvider.UrlBase + @"/MediaCover/" + entityId + "/" + mediaCover.CoverType.ToString().ToLower() + GetExtension(mediaCover.CoverType, mediaCover.Extension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_diskProvider.FileExists(filePath))
|
|
|
|
@ -283,6 +286,15 @@ namespace NzbDrone.Core.MediaCover
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetExtension(MediaCoverTypes coverType, string defaultExtension)
|
|
|
|
|
{
|
|
|
|
|
return coverType switch
|
|
|
|
|
{
|
|
|
|
|
MediaCoverTypes.Clearlogo => ".png",
|
|
|
|
|
_ => defaultExtension
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HttpHeader GetServerHeaders(string url)
|
|
|
|
|
{
|
|
|
|
|
// Goodreads doesn't allow a HEAD, so request a zero byte range instead
|
|
|
|
|