Skip to content

Commit

Permalink
Added MB error reporting for non-interactive queries
Browse files Browse the repository at this point in the history
  • Loading branch information
sbooth committed Feb 29, 2020
1 parent a7dbbd9 commit 42b8636
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 38 deletions.
67 changes: 45 additions & 22 deletions CompactDisc/CompactDiscDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ - (void) discEjected { [self setDisc:nil]; }
#pragma mark State

- (BOOL) encodeAllowed { return ([self discInDrive] && NO == [self emptySelection] && NO == [self ripInProgress] && NO == [self encodeInProgress]); }
- (BOOL) queryMusicBrainzAllowed { return [self discInDrive]; }
- (BOOL) queryMusicBrainzAllowed { return YES; }
- (BOOL) ejectDiscAllowed { return [self discInDrive]; }
- (BOOL) submitDiscIdAllowed { return [self discInDrive]; }
- (BOOL) emptySelection { return (0 == [[self selectedTracks] count]); }
Expand Down Expand Up @@ -506,32 +506,24 @@ - (IBAction) queryMusicBrainz:(id)sender
return;
}

PerformMusicBrainzQuery([[self disc] discID], ^(NSArray *results, NSError *error) {
PerformMusicBrainzQuery([self discID], ^(NSArray *results, NSError *error) {
if(nil == results) {
if(nil != error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
return;
}
else if(0 == [results count]) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No matches found.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No matching releases were found in MusicBrainz.", @"CompactDisc", @"")];
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No matches.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No releases matching this disc were found in MusicBrainz.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];

return;
}
// If only match was found, update ourselves
else if(1 == [results count]) {
NSDictionary *release = [results firstObject];
[self updateMetadataFromMusicBrainz:release];
NSString *releaseID = [release objectForKey:@"albumId"];
PerformCoverArtArchiveQuery(releaseID, ^(NSImage *image, NSError *error) {
if(nil != image) {
[self setAlbumArt:image];
}
});
[self downloadAlbumArt:sender];
}
else {
MusicBrainzMatchSheet *sheet = [[MusicBrainzMatchSheet alloc] init];
Expand All @@ -540,12 +532,7 @@ - (IBAction) queryMusicBrainz:(id)sender
if(NSOKButton == returnCode) {
NSDictionary *release = [sheet selectedRelease];
[self updateMetadataFromMusicBrainz:release];
NSString *releaseID = [release objectForKey:@"albumId"];
PerformCoverArtArchiveQuery(releaseID, ^(NSImage *image, NSError *error) {
if(nil != image) {
[self setAlbumArt:image];
}
});
[self downloadAlbumArt:sender];
}
}];
[sheet release];
Expand Down Expand Up @@ -588,13 +575,39 @@ - (IBAction) selectPreviousTrack:(id)sender { [_trackController selectPrevio

- (IBAction) downloadAlbumArt:(id)sender
{
if(NULL == _musicbrainzAlbumId) {
if(![self queryMusicBrainzAllowed]) {
return;
}

if(nil == _musicbrainzAlbumId) {
PerformMusicBrainzQuery([self discID], ^(NSArray *results, NSError *error) {
if(0 < [results count]) {
if(nil == results) {
if(nil != error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
}
else if(0 == [results count]) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No matches.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No releases matching this disc were found in MusicBrainz.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else {
NSDictionary *release = [results firstObject];
NSString *releaseID = [release objectForKey:@"albumId"];
PerformCoverArtArchiveQuery(releaseID, ^(NSImage *image, NSError *error) {
if(nil != image) {
if(nil != error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else if(nil == image) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No album art.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No front cover art matching this disc was found.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else {
[self setAlbumArt:image];
}
});
Expand All @@ -603,7 +616,17 @@ - (IBAction) downloadAlbumArt:(id)sender
}
else {
PerformCoverArtArchiveQuery(_musicbrainzAlbumId, ^(NSImage *image, NSError *error) {
if(nil != image) {
if(nil != error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else if(nil == image) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No album art.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No front cover art matching this disc was found.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else {
[self setAlbumArt:image];
}
});
Expand Down
57 changes: 41 additions & 16 deletions CueSheet/CueSheetDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -596,25 +596,17 @@ - (IBAction) queryMusicBrainz:(id)sender
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
return;
}
else if(0 == [results count]) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No matches found.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No matching releases were found in MusicBrainz.", @"CompactDisc", @"")];
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No matches.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No releases matching this disc were found in MusicBrainz.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];

return;
}
// If only match was found, update ourselves
else if(1 == [results count]) {
NSDictionary *release = [results firstObject];
[self updateMetadataFromMusicBrainz:release];
NSString *releaseID = [release objectForKey:@"albumId"];
PerformCoverArtArchiveQuery(releaseID, ^(NSImage *image, NSError *error) {
if(nil != image) {
[self setAlbumArt:image];
}
});
[self downloadAlbumArt:sender];
}
else {
MusicBrainzMatchSheet *sheet = [[MusicBrainzMatchSheet alloc] init];
Expand All @@ -623,12 +615,7 @@ - (IBAction) queryMusicBrainz:(id)sender
if(NSOKButton == returnCode) {
NSDictionary *release = [sheet selectedRelease];
[self updateMetadataFromMusicBrainz:release];
NSString *releaseID = [release objectForKey:@"albumId"];
PerformCoverArtArchiveQuery(releaseID, ^(NSImage *image, NSError *error) {
if(nil != image) {
[self setAlbumArt:image];
}
});
[self downloadAlbumArt:sender];
}
}];
[sheet release];
Expand Down Expand Up @@ -671,6 +658,44 @@ - (IBAction) selectPreviousTrack:(id)sender { [_trackController selectPrevio

- (IBAction) downloadAlbumArt:(id)sender
{
if(![self queryMusicBrainzAllowed]) {
return;
}

PerformMusicBrainzQuery([self discID], ^(NSArray *results, NSError *error) {
if(nil == results) {
if(nil != error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
}
else if(0 == [results count]) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No matches.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No releases matching this disc were found in MusicBrainz.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else {
NSDictionary *release = [results firstObject];
[self updateMetadataFromMusicBrainz:release];
NSString *releaseID = [release objectForKey:@"albumId"];
PerformCoverArtArchiveQuery(releaseID, ^(NSImage *image, NSError *error) {
if(nil != error) {
NSAlert *alert = [NSAlert alertWithError:error];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else if(nil == image) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedStringFromTable(@"No album art.", @"CompactDisc", @"") defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedStringFromTable(@"No front cover art matching this disc was found.", @"CompactDisc", @"")];
[alert beginSheetModalForWindow:[self windowForSheet] completionHandler:^(NSModalResponse returnCode) {
}];
}
else {
[self setAlbumArt:image];
}
});
}
});
}

- (IBAction) selectAlbumArt:(id) sender
Expand Down

0 comments on commit 42b8636

Please sign in to comment.