public override bool AssociateMetaData() { if (metaData != null) { return(true); } if (Matches == null || Matches.Length == 0) { return(false); } GD3.AlbumCode match = Matches[SelectedMatch ?? 0]; var albumCode = Math.Abs(match.AlbumCode1); return(metaDataGD3.cdCodeToMetaData.TryGetValue(albumCode, out metaData)); }
public override async Task <bool> RetrieveMetaData() { if (Matches == null || Matches.Length == 0 || metaData != null) { return(false); } GD3.AlbumCode match = Matches[SelectedMatch ?? 0]; var albumCode1 = match.AlbumCode1; if (AssociateMetaData() || metaDataGD3.authCD == null) { return(false); } var task = metaDataGD3.SoapClientCD.RetrieveAlbumAsync(metaDataGD3.authCD, albumCode1, 0); if (await Task.WhenAny(task, Task.Delay(30000)) != task) { throw new Exception("GD3 RetrieveAlbumAsync timeout: " + albumCode1); } var retrieveAlbumResponse = await task; var albumMeta = retrieveAlbumResponse?.RetrieveAlbumResult; if (albumMeta == null) { return(false); } var albumCode = albumMeta.AlbumID; if (albumCode == 0) { albumCode = albumMeta.AlbumCode; } if (albumCode == 0) { albumCode = Math.Abs(albumCode1); } string fileNameArtist = MetaDataProvider.RemoveBlacklistedCharacters(albumMeta.Artist ?? "ArtistUnk", 40); string fileNameAlbum = MetaDataProvider.RemoveBlacklistedCharacters(albumMeta.Album ?? "AlbumUnk", 80); string fileNameBase = $"Meta_CD_{fileNameArtist}_{fileNameAlbum}_{albumCode}"; string albumImageFileName = null; var ai = albumMeta.AlbumImage; if (ai != null) { if (ai.Length > 0) { albumImageFileName = await WriteImage(ai, metaDataGD3.GD3CDPath, fileNameBase); } albumMeta.AlbumImage = null; } var m = new MetaDataCD { AlbumCode = albumCode, AlbumMeta = albumMeta, ImageFileName = albumImageFileName }; using (var f = File.Create(Path.Combine(metaDataGD3.GD3CDPath, Path.ChangeExtension(fileNameBase, "json")))) { var w = new Utf8JsonWriter(f, new JsonWriterOptions { Indented = true }); JsonSerializer.Serialize(w, m); f.Close(); } metaDataGD3.cdCodeToMetaData[albumCode] = m; metaData = m; return(true); }