Fixed several issues with Artist updating.

This commit is contained in:
Steven Hildreth 2019-07-21 17:07:37 -05:00
parent a738b89a3a
commit 247502408a
6 changed files with 74 additions and 45 deletions

View file

@ -81,13 +81,11 @@ namespace Roadie.Library.Engines
artist.Thumbnail = firstImageWithNotNullBytes.Bytes;
if (artist.Thumbnail != null)
{
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail,
Configuration.ThumbnailImageSize.Width, Configuration.ThumbnailImageSize.Height);
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
artist.Thumbnail = ImageHelper.ConvertToJpegFormat(artist.Thumbnail);
if (artist.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning(
$"Artist Thumbnail larger than maximum size after resizing to [{Configuration.ThumbnailImageSize.Width}x{Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{artist.Thumbnail.Length}]");
Logger.LogWarning($"Artist Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{artist.Thumbnail.Length}]");
artist.Thumbnail = null;
}
}
@ -546,20 +544,25 @@ namespace Roadie.Library.Engines
if (WikipediaArtistSearchEngine.IsEnabled)
{
var wikiName = result.Name;
// Help get better results for bands with proper nouns (e.g. "Poison")
// Help get better results for bands with proper nouns (e.g. "Poison" vs "Poison Band")
if (!result.ArtistType.Equals("Person", StringComparison.OrdinalIgnoreCase))
wikiName = wikiName + " band";
{
wikiName += " band";
}
var wikipediaResult = await WikipediaArtistSearchEngine.PerformArtistSearch(wikiName, 1);
if (wikipediaResult != null)
{
if (wikipediaResult.IsSuccess)
{
var w = wikipediaResult.Data.First();
var w = wikipediaResult?.Data?.FirstOrDefault();
if (w != null)
{
result.CopyTo(new Artist
{
BioContext = HttpEncoder.HtmlEncode(w.Bio)
});
}
}
if (wikipediaResult.Errors != null) resultsExceptions.AddRange(wikipediaResult.Errors);
}
@ -620,8 +623,7 @@ namespace Roadie.Library.Engines
if (result.Thumbnail != null)
{
result.Thumbnail = ImageHelper.ResizeImage(result.Thumbnail, Configuration.ThumbnailImageSize.Width,
Configuration.ThumbnailImageSize.Height);
result.Thumbnail = ImageHelper.ResizeImage(result.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
result.Thumbnail = ImageHelper.ConvertToJpegFormat(result.Thumbnail);
}
}

View file

@ -841,13 +841,12 @@ namespace Roadie.Library.Engines
if (result.Thumbnail != null)
{
result.Thumbnail = ImageHelper.ResizeImage(result.Thumbnail, Configuration.ThumbnailImageSize.Width,
Configuration.ThumbnailImageSize.Height);
result.Thumbnail = ImageHelper.ResizeImage(result.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
result.Thumbnail = ImageHelper.ConvertToJpegFormat(result.Thumbnail);
if (result.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning(
$"Release Thumbnail larger than maximum size after resizing to [{Configuration.ThumbnailImageSize.Width}x{Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{result.Thumbnail.Length}]");
$"Release Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{result.Thumbnail.Length}]");
result.Thumbnail = null;
}
}

View file

@ -21,7 +21,7 @@ namespace Roadie.Library.Imaging
public static string ArtistImageFilename = "artist.jpg";
public static string ArtistSecondaryImageFilename = "artist {0}.jpg";
public static string LabelImageFilename = "label.jpg";
public static int MaximumThumbnailByteSize = 65535;
public static int MaximumThumbnailByteSize = 65000;
// Replace with counter of image
public static string ReleaseCoverFilename = "cover.jpg";

View file

@ -692,11 +692,13 @@ namespace Roadie.Api.Services
if (!newArtistFolder.Equals(originalArtistFolder, StringComparison.OrdinalIgnoreCase))
{
didRenameArtist = true;
if (Directory.Exists(originalArtistFolder))
{
// Rename artist folder to reflect new artist name
Logger.LogTrace("Moving Artist From Folder [{0}] To [{1}]", originalArtistFolder, newArtistFolder);
Directory.Move(originalArtistFolder, newArtistFolder);
}
}
var artistImage = ImageHelper.ImageDataFromUrl(model.NewThumbnailData);
if (artistImage != null)
@ -710,6 +712,11 @@ namespace Roadie.Api.Services
// Resize to store in database as thumbnail
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
if (artist.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning($"Artist Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{artist.Thumbnail.Length}]");
artist.Thumbnail = null;
}
didChangeThumbnail = true;
}
@ -852,6 +859,9 @@ namespace Roadie.Api.Services
artist.LastUpdated = now;
await DbContext.SaveChangesAsync();
if (didRenameArtist)
{
// Many contributing artists do not have releases and will not have an empty Artist folder
if (Directory.Exists(newArtistFolder))
{
// Update artist tracks to have new artist name in ID3 metadata
foreach (var mp3 in Directory.GetFiles(newArtistFolder, "*.mp3", SearchOption.AllDirectories))
@ -867,6 +877,7 @@ namespace Roadie.Api.Services
await ScanArtistReleasesFolders(user, artist.RoadieId, Configuration.LibraryFolder, false);
}
}
CacheManager.ClearRegion(artist.CacheRegion);
Logger.LogInformation(
@ -1295,8 +1306,12 @@ namespace Roadie.Api.Services
File.WriteAllBytes(artistImage, artist.Thumbnail);
// Resize to store in database as thumbnail
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, Configuration.MediumImageSize.Width,
Configuration.MediumImageSize.Height);
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
if (artist.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning($"Artist Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{artist.Thumbnail.Length}]");
artist.Thumbnail = null;
}
}
artist.LastUpdated = now;
@ -1384,9 +1399,13 @@ namespace Roadie.Api.Services
{
// Read image and convert to jpeg
artist.Thumbnail = File.ReadAllBytes(i.FullName);
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail,
Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail,Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
artist.Thumbnail = ImageHelper.ConvertToJpegFormat(artist.Thumbnail);
if (artist.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning($"Artist Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{artist.Thumbnail.Length}]");
artist.Thumbnail = null;
}
artist.LastUpdated = DateTime.UtcNow;
await DbContext.SaveChangesAsync();
CacheManager.ClearRegion(artist.CacheRegion);

View file

@ -1289,20 +1289,17 @@ namespace Roadie.Api.Services
if (release.Thumbnail == null)
{
var imageFiles = ImageHelper.FindImageTypeInDirectory(new DirectoryInfo(releasePath),
ImageType.Release, SearchOption.TopDirectoryOnly);
var imageFiles = ImageHelper.FindImageTypeInDirectory(new DirectoryInfo(releasePath), ImageType.Release, SearchOption.TopDirectoryOnly);
if (imageFiles != null && imageFiles.Any())
{
// Read image and convert to jpeg
var i = imageFiles.First();
release.Thumbnail = File.ReadAllBytes(i.FullName);
release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail,
Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
release.Thumbnail = ImageHelper.ConvertToJpegFormat(release.Thumbnail);
if (release.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning(
$"Release Thumbnail larger than maximum size after resizing to [{Configuration.ThumbnailImageSize.Width}x{Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{release.Thumbnail.Length}]");
Logger.LogWarning($"Release Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{release.Thumbnail.Length}]");
release.Thumbnail = null;
}
@ -1415,8 +1412,12 @@ namespace Roadie.Api.Services
File.WriteAllBytes(coverFileName, release.Thumbnail);
// Resize to store in database as thumbnail
release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail, Configuration.MediumImageSize.Width,
Configuration.MediumImageSize.Height);
release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
if (release.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning($"Release Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{release.Thumbnail.Length}]");
release.Thumbnail = null;
}
didChangeThumbnail = true;
}
@ -1888,8 +1889,12 @@ namespace Roadie.Api.Services
File.WriteAllBytes(coverFileName, release.Thumbnail);
// Resize to store in database as thumbnail
release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail, Configuration.MediumImageSize.Width,
Configuration.MediumImageSize.Height);
release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
if (release.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning($"Release Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{release.Thumbnail.Length}]");
release.Thumbnail = null;
}
}
release.LastUpdated = now;

View file

@ -845,8 +845,12 @@ namespace Roadie.Api.Services
File.WriteAllBytes(trackThumbnailName, track.Thumbnail);
// Resize to store in database as thumbnail
track.Thumbnail = ImageHelper.ResizeImage(track.Thumbnail, Configuration.MediumImageSize.Width,
Configuration.MediumImageSize.Height);
track.Thumbnail = ImageHelper.ResizeImage(track.Thumbnail, Configuration.MediumImageSize.Width, Configuration.MediumImageSize.Height);
if (track.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize)
{
Logger.LogWarning($"Track Thumbnail larger than maximum size after resizing to [{Configuration.MediumImageSize.Width}x{Configuration.MediumImageSize.Height}] Thumbnail Size [{track.Thumbnail.Length}]");
track.Thumbnail = null;
}
didChangeThumbnail = true;
}