Refactor the artworks urls code so we don't have to update three different arrays each time.

This commit is contained in:
Damiano Galassi committed 2017-05-27 19:01:04 +02:00
1 parent daa7fc3604
commit 0d3b0ea3ec
12 files changed
+155 -120

No files matched your search

+9 -9
View File
@@ -140,7 +140,7 @@
return nil;
}
- (NSInteger)indexOfPreferredArtworkForType:(SBQueueMetadataActionPreferredArtwork)preferredType provider:(NSString *)provider artworks:(NSArray<NSString *> *)artworkProviderNames
- (NSInteger)indexOfPreferredArtworkForType:(SBQueueMetadataActionPreferredArtwork)preferredType provider:(NSString *)provider artworks:(NSArray<SBRemoteImage *> *)artworks
{
NSString *preferredTypeName = nil;
@@ -160,14 +160,14 @@
}
NSUInteger index = 0;
for (NSString *name in artworkProviderNames) {
if ([name hasPrefix:preferredTypeName]) {
for (SBRemoteImage *image in artworks) {
if ([image.providerName hasPrefix:preferredTypeName]) {
break;
}
index += 1;
}
return index == artworkProviderNames.count ? -1 : index;
return index == artworks.count ? -1 : index;
}
- (MP42Metadata *)searchMetadataForFile:(NSURL *)url {
@@ -199,24 +199,24 @@
}
}
if (metadata.artworkFullsizeURLs.count) {
if (metadata.remoteArtworks.count) {
NSURL *artworkURL = nil;
NSInteger index = [self indexOfPreferredArtworkForType:_preferredArtwork
provider:provider
artworks:metadata.artworkProviderNames];
artworks:metadata.remoteArtworks];
// Fallback to the poster if type is tv
if (index == -1 && [@"tv" isEqualToString:type]) {
index = [self indexOfPreferredArtworkForType:SBQueueMetadataActionPreferredArtworkDefault
provider:provider
artworks:metadata.artworkProviderNames];
artworks:metadata.remoteArtworks];
}
if (index > -1) {
artworkURL = metadata.artworkFullsizeURLs[index];
artworkURL = metadata.remoteArtworks[index].URL;
}
else {
artworkURL = metadata.artworkFullsizeURLs.firstObject;
artworkURL = metadata.remoteArtworks.firstObject.URL;
}
MP42Image *artwork = [self loadArtwork:artworkURL];