Commit 891baf23 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Browsing artwork provider: add support audio artwork lookup

parent f8503248
......@@ -16,6 +16,7 @@
@interface VLCMDFBrowsingArtworkProvider : NSObject
@property (readwrite, weak) id<VLCRemoteBrowsingCell> artworkReceiver;
@property (readwrite, nonatomic) BOOL searchForAudioMetadata;
- (void)reset;
- (void)searchForArtworkForVideoRelatedString:(NSString *)string;
......
......@@ -12,9 +12,10 @@
#import "VLCMDFBrowsingArtworkProvider.h"
#import "MetaDataFetcherKit.h"
@interface VLCMDFBrowsingArtworkProvider () <MDFMovieDBFetcherDataRecipient>
@interface VLCMDFBrowsingArtworkProvider () <MDFMovieDBFetcherDataRecipient, MDFHatchetFetcherDataRecipient>
{
MDFMovieDBFetcher *_metadataFetcher;
MDFMovieDBFetcher *_tmdbFetcher;
MDFHatchetFetcher *_hatchetFetcher;
}
@end
......@@ -23,34 +24,52 @@
- (void)reset
{
if (_metadataFetcher) {
[_metadataFetcher cancelAllRequests];
if (_tmdbFetcher) {
[_tmdbFetcher cancelAllRequests];
if (_hatchetFetcher)
[_hatchetFetcher cancelAllRequests];
} else {
_metadataFetcher = [[MDFMovieDBFetcher alloc] init];
_metadataFetcher.dataRecipient = self;
_metadataFetcher.shouldDecrapifyInputStrings = YES;
_tmdbFetcher = [[MDFMovieDBFetcher alloc] init];
_tmdbFetcher.dataRecipient = self;
_tmdbFetcher.shouldDecrapifyInputStrings = YES;
if (_searchForAudioMetadata) {
_hatchetFetcher = [[MDFHatchetFetcher alloc] init];
_hatchetFetcher.dataRecipient = self;
}
}
}
- (void)setSearchForAudioMetadata:(BOOL)searchForAudioMetadata
{
if (searchForAudioMetadata) {
_hatchetFetcher = [[MDFHatchetFetcher alloc] init];
_hatchetFetcher.dataRecipient = self;
}
_searchForAudioMetadata = searchForAudioMetadata;
}
- (void)searchForArtworkForVideoRelatedString:(NSString *)string
{
[_metadataFetcher searchForMovie:string];
[_tmdbFetcher searchForMovie:string];
}
#pragma mark - MDFMovieDB
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindMovie:(MDFMovie *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
if (details == nil) {
return;
}
[aFetcher cancelAllRequests];
MDFMovieDBSessionManager *sessionManager = [MDFMovieDBSessionManager sharedInstance];
if (!sessionManager.hasFetchedProperties)
if (!sessionManager.hasFetchedProperties) {
return;
}
if (details.movieDBID == 0) {
/* we found nothing, let's see if it's a TV show */
[_metadataFetcher searchForTVShow:searchRequest];
[_tmdbFetcher searchForTVShow:searchRequest];
return;
}
......@@ -74,8 +93,9 @@
imageSize = sizes.firstObject;
}
}
if (!imagePath)
if (!imagePath) {
return;
}
NSString *thumbnailURLString = [NSString stringWithFormat:@"%@%@%@",
sessionManager.imageBaseURL,
......@@ -87,12 +107,21 @@
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFailToFindMovieForSearchRequest:(NSString *)searchRequest
{
APLog(@"Failed to find a movie for '%@'", searchRequest);
if (_searchForAudioMetadata) {
[_hatchetFetcher searchForArtist:searchRequest];
}
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindTVShow:(MDFTVShow *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
if (details == nil) {
if (_searchForAudioMetadata) {
[_hatchetFetcher searchForArtist:searchRequest];
}
return;
}
[aFetcher cancelAllRequests];
MDFMovieDBSessionManager *sessionManager = [MDFMovieDBSessionManager sharedInstance];
if (!sessionManager.hasFetchedProperties)
......@@ -118,8 +147,12 @@
imageSize = sizes.firstObject;
}
}
if (!imagePath)
if (!imagePath) {
if (_searchForAudioMetadata) {
[_hatchetFetcher searchForArtist:searchRequest];
}
return;
}
NSString *thumbnailURLString = [NSString stringWithFormat:@"%@%@%@",
sessionManager.imageBaseURL,
......@@ -131,6 +164,49 @@
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFailToFindTVShowForSearchRequest:(NSString *)searchRequest
{
APLog(@"failed to find TV show");
if (_searchForAudioMetadata) {
[_hatchetFetcher searchForArtist:searchRequest];
}
}
- (void)MDFHatchetFetcher:(MDFHatchetFetcher *)aFetcher didFindArtist:(MDFArtist *)artist forSearchRequest:(NSString *)searchRequest
{
/* we have no match */
if (!artist) {
[self _simplifyMetaDataSearchString:searchRequest];
return;
}
NSArray *imageURLStrings = artist.largeSizedImages;
NSString *imageURLString;
if (imageURLStrings.count > 0) {
imageURLString = imageURLStrings.firstObject;
} else {
imageURLStrings = artist.mediumSizedImages;
if (imageURLStrings.count > 0) {
imageURLString = imageURLStrings.firstObject;
}
}
if (imageURLString) {
self.artworkReceiver.thumbnailURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?height=300&width=250",imageURLString]];
} else {
[self _simplifyMetaDataSearchString:searchRequest];
}
}
- (void)MDFHatchetFetcher:(MDFHatchetFetcher *)aFetcher didFailToFindArtistForSearchRequest:(NSString *)searchRequest
{
[self _simplifyMetaDataSearchString:searchRequest];
}
- (void)_simplifyMetaDataSearchString:(NSString *)searchString
{
NSRange lastRange = [searchString rangeOfString:@" " options:NSBackwardsSearch];
if (lastRange.location != NSNotFound)
[_hatchetFetcher searchForArtist:[searchString substringToIndex:lastRange.location]];
}
@end
......@@ -25,7 +25,7 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
@implementation VLCRemoteBrowsingTVCell
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory;
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory, couldBeAudioOnlyMedia = _couldBeAudioOnlyMedia;
- (void)awakeFromNib
{
......@@ -47,6 +47,15 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
self.subtitle = nil;
}
- (void)setCouldBeAudioOnlyMedia:(BOOL)couldBeAudioOnlyMedia
{
_artworkProvider.searchForAudioMetadata = _couldBeAudioOnlyMedia;
if (_couldBeAudioOnlyMedia != couldBeAudioOnlyMedia) {
[_artworkProvider reset];
}
_couldBeAudioOnlyMedia = couldBeAudioOnlyMedia;
}
- (void)setThumbnailURL:(NSURL *)thumbnailURL
{
_thumbnailURL = thumbnailURL;
......
......@@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) UIImage *thumbnailImage;
@property (nonatomic, nullable) NSURL *thumbnailURL;
@property (nonatomic) BOOL isDirectory;
@property (nonatomic) BOOL couldBeAudioOnlyMedia;
#if DOWNLOAD_SUPPORTED
@property (nonatomic) BOOL isDownloadable;
#endif
......
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