diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8550222a16..ed0598a9b8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -82,6 +82,7 @@ - [Matt07211](https://github.com/Matt07211) - [Maxr1998](https://github.com/Maxr1998) - [mcarlton00](https://github.com/mcarlton00) + - [MisterGenius0](https://github.com/MisterGenius0) - [mitchfizz05](https://github.com/mitchfizz05) - [mohd-akram](https://github.com/mohd-akram) - [MrTimscampi](https://github.com/MrTimscampi) diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index d1c0ddb375..1f104111c9 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -76,29 +76,28 @@ namespace MediaBrowser.Providers.MediaInfo private async Task GetImage(Audio item, List imageStreams, CancellationToken cancellationToken) { - var path = GetAudioImagePath(item); - - if (!File.Exists(path)) - { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).Contains("front", StringComparison.OrdinalIgnoreCase)) ?? + var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).Contains("front", StringComparison.OrdinalIgnoreCase)) ?? imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).Contains("cover", StringComparison.OrdinalIgnoreCase)) ?? imageStreams.FirstOrDefault(); - var imageStreamIndex = imageStream?.Index; + var imageStreamIndex = imageStream?.Index; - var tempFile = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false); + var tempFile = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false); + var path = GetAudioImagePath(item, tempFile); + + if (!File.Exists(path)) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); File.Copy(tempFile, path, true); + } - try - { - _fileSystem.DeleteFile(tempFile); - } - catch - { - } + try + { + _fileSystem.DeleteFile(tempFile); + } + catch + { } return new DynamicImageResponse @@ -108,21 +107,19 @@ namespace MediaBrowser.Providers.MediaInfo }; } - private string GetAudioImagePath(Audio item) + private string GetAudioImagePath(Audio item, string newImagePath) { string filename; - + long newImageLength = _fileSystem.GetFileInfo(newImagePath).Length; if (item.GetType() == typeof(Audio)) { - if (item.AlbumArtists.Count > 0 - && !string.IsNullOrWhiteSpace(item.Album) - && !string.IsNullOrWhiteSpace(item.AlbumArtists[0])) + if (!string.IsNullOrWhiteSpace(item.Album)) { - filename = (item.Album + "-" + item.AlbumArtists[0]).GetMD5().ToString("N", CultureInfo.InvariantCulture); + filename = (item.Album + newImageLength).GetMD5().ToString("N", CultureInfo.InvariantCulture); } else { - filename = item.Id.ToString("N", CultureInfo.InvariantCulture); + filename = newImageLength.ToString("N", CultureInfo.InvariantCulture); } filename += ".jpg";