Commit c791cd03 authored by Evan Blackstone's avatar Evan Blackstone

Fix issue #279 -- Missing Album Art

Add offline (id3) art scanning via StorageItemThumbnail as a backup for online album art downloader in cases where no artwork is found online.

Add MusicTagReader fetcher to VLC.MediaMetaFetcher.
parent da818ef8
......@@ -83,5 +83,12 @@ namespace VLC.Helpers.MusicLibrary
// LogHelper.Log(StringsHelper.ExceptionToString(e));
//}
}
public TrackItem GetAlbumFirstTrack(int albumId)
{
MusicDatabase musicDb = new MusicDatabase();
TrackItem track = musicDb.LoadTracksFromAlbumId(albumId).FirstOrDefault();
return track;
}
}
}
......@@ -18,7 +18,7 @@ namespace VLC.Services.RunTime
public sealed class MusicMetaService
{
readonly MusicMDFetcher musicMdFetcher = new MusicMDFetcher(App.DeezerAppID, App.ApiKeyLastFm);
public async Task GetSimilarArtists(ArtistItem artist)
{
var artists = await musicMdFetcher.GetArtistSimilarsArtist(artist.Name);
......@@ -68,6 +68,19 @@ namespace VLC.Services.RunTime
return true;
}
}
//If no art is found online, use embedded art
Helpers.MusicLibrary.MusicLibrary musicLib = new Helpers.MusicLibrary.MusicLibrary();
TrackItem firstTrack = musicLib.GetAlbumFirstTrack(album.Id);
if (firstTrack != null)
{
var bytes = await musicMdFetcher.GetAlbumPictureFromTag(firstTrack.Path);
var tagReadSuccess = bytes != null && await SaveAlbumImageAsync(album, bytes);
if (tagReadSuccess)
{
Locator.MediaLibrary.Update(album);
return true;
}
}
return false;
}
......
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using VLC.Database;
using Windows.Storage.FileProperties;
using Windows.Storage;
using System.IO;
namespace VLC.MusicMetaFetcher.Fetchers
{
public static class MusicTagReader
{
public static async Task<byte[]> ReadAlbumCoverFromTag(string filePath)
{
StorageFile musicFile = await StorageFile.GetFileFromPathAsync(filePath);
StorageItemThumbnail img = await musicFile.GetThumbnailAsync(ThumbnailMode.MusicView,600);
if(img != null && img.Type == ThumbnailType.Image)
{
byte[] imgBytes = new byte[img.Size];
Stream imgStream = img.AsStream();
imgStream.Position = 0;
await imgStream.ReadAsync(imgBytes, 0, Convert.ToInt32(img.Size));
return imgBytes;
}
return null;
}
}
}
......@@ -16,7 +16,6 @@ using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using VLC.MusicMetaFetcher.Fetchers;
using VLC.MusicMetaFetcher.Models.MusicEntities;
namespace VLC.MusicMetaFetcher
{
public class MusicMDFetcher
......@@ -156,6 +155,13 @@ namespace VLC.MusicMetaFetcher
return gotArt;
}
public async Task<byte[]> GetAlbumPictureFromTag(string filePath)
{
byte[] tagArt = null;
tagArt = await MusicTagReader.ReadAlbumCoverFromTag(filePath);
return tagArt;
}
public async Task<List<Album>> GetArtistTopAlbums(string artistName)
{
try
......
......@@ -14,6 +14,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Fetchers\IMusicMetaFetcher.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fetchers\LastFmClient.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fetchers\MovieDbClient.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fetchers\MusicTagReader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Fetchers\OpenSubtitleClient.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Deezer\Albums.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\Deezer\Artists.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment