Commit 21b12688 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Iterate on the Hatchet fetcher

parent a4656d99
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "MetaDataFetcherKit" s.name = "MetaDataFetcherKit"
s.version = "0.1.5" s.version = "0.1.6"
s.summary = "An ObjC library to fetch meta data for media content" s.summary = "An ObjC library to fetch meta data for media content"
s.homepage = "https://code.videolan.org/fkuehne/MetaDataFetcherKit" s.homepage = "https://code.videolan.org/fkuehne/MetaDataFetcherKit"
......
...@@ -30,18 +30,47 @@ ...@@ -30,18 +30,47 @@
*/ */
@property (readwrite, nonatomic, nullable) NSString *name; @property (readwrite, nonatomic, nullable) NSString *name;
/**
* a biography abstract of the artist, usually 3 to 4 short paragraphs [STRING];
*/
@property (readwrite, nonatomic, nullable) NSString *biography;
/** /**
* medium sized image URL string(s) with a width < 1000px * medium sized image URL string(s) with a width < 1000px
* \note base URL included * \note base URL included
*/ */
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedImages; @property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedImages;
/**
* medium sized image URL string(s) with a width < 1000px and a height > width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedPortraitImages;
/**
* medium sized image URL string(s) with a width < 1000px and a height < width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedLandscapeImages;
/** /**
* large image URL string(s) with a width > 1000px * large image URL string(s) with a width > 1000px
* \note base URL included * \note base URL included
*/ */
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedImages; @property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedImages;
/**
* large image URL string(s) with a width > 1000px and a height > width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedPortraitImages;
/**
* large image URL string(s) with a width > 1000px and a height < width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedLandscapeImages;
/** /**
* the Hatchet id of the artist [NSInteger] * the Hatchet id of the artist [NSInteger]
*/ */
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
- (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFindArtist:(MDFArtist * _Nonnull)artist forSearchRequest:(NSString * _Nonnull)searchRequest; - (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFindArtist:(MDFArtist * _Nonnull)artist forSearchRequest:(NSString * _Nonnull)searchRequest;
- (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFailToFindArtistForSearchRequest:(NSString * _Nonnull)searchRequest; - (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFailToFindArtistForSearchRequest:(NSString * _Nonnull)searchRequest;
- (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFindAlbum:(MDFMusicAlbum * _Nonnull)album forArtistName:(NSString * _Nonnull)artistName; - (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFindAlbum:(MDFMusicAlbum * _Nonnull)album byArtist:(MDFArtist * _Nullable)artist forSearchRequest:(NSString * _Nonnull)searchRequest;
- (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFailToFindAlbum:(NSString * _Nonnull)albumName forArtistName:(NSString * _Nonnull)artistName; - (void)MDFHatchetFetcher:(MDFHatchetFetcher * _Nonnull)aFetcher didFailToFindAlbum:(NSString * _Nonnull)albumName forArtistName:(NSString * _Nonnull)artistName;
@end @end
......
...@@ -72,30 +72,56 @@ ...@@ -72,30 +72,56 @@
[_requests removeObject:task]; [_requests removeObject:task];
} }
MDFArtist *artist = [[MDFArtist alloc] init]; MDFArtist *artist;
if (responseObject != nil) { if (responseObject != nil) {
NSArray *artistsArray = responseObject[@"artists"]; NSArray *artistsArray = responseObject[@"artists"];
NSArray *imagesArray = responseObject[@"images"]; NSArray *imagesArray = responseObject[@"images"];
if (artistsArray != nil) { if (artistsArray != nil) {
artist = [[MDFArtist alloc] init];
NSDictionary *artistDict = [artistsArray firstObject]; NSDictionary *artistDict = [artistsArray firstObject];
artist.hatchetArtistID = [artistDict[@"id"] integerValue]; artist.hatchetArtistID = [artistDict[@"id"] integerValue];
artist.name = artistDict[@"name"]; artist.name = artistDict[@"name"];
artist.biography = artistDict[@"wikiabstract"];
} }
if (imagesArray != nil) { if (imagesArray != nil) {
if (!artist)
artist = [[MDFArtist alloc] init];
NSMutableArray *mediumImages = [NSMutableArray array]; NSMutableArray *mediumImages = [NSMutableArray array];
NSMutableArray *mediumPortraitImages = [NSMutableArray array];
NSMutableArray *mediumLandscapeImages = [NSMutableArray array];
NSMutableArray *largeImages = [NSMutableArray array]; NSMutableArray *largeImages = [NSMutableArray array];
NSMutableArray *largePortraitImages = [NSMutableArray array];
NSMutableArray *largeLandscapeImages = [NSMutableArray array];
NSUInteger imageCount = imagesArray.count; NSUInteger imageCount = imagesArray.count;
for (NSUInteger x = 0; x < imageCount; x++) { for (NSUInteger x = 0; x < imageCount; x++) {
NSDictionary *imageDict = imagesArray[x]; NSDictionary *imageDict = imagesArray[x];
if ([imageDict[@"width"] integerValue] > 1000) { NSInteger imageWidth = [imageDict[@"width"] integerValue];
[largeImages addObject:imageDict[@"url"]]; NSInteger heightWidth = [imageDict[@"height"] integerValue];
NSString *imageURL = imageDict[@"url"];
if (imageWidth > 1000) {
[largeImages addObject:imageURL];
if (imageWidth > imageWidth) {
[largeLandscapeImages addObject:imageURL];
} else {
[largePortraitImages addObject:imageURL];
}
} else { } else {
[mediumImages addObject:imageDict[@"url"]]; [mediumImages addObject:imageDict[@"url"]];
if (imageWidth > imageWidth) {
[mediumLandscapeImages addObject:imageURL];
} else {
[mediumPortraitImages addObject:imageURL];
}
} }
} }
artist.mediumSizedImages = [mediumImages copy]; artist.mediumSizedImages = [mediumImages copy];
artist.mediumSizedPortraitImages = [mediumPortraitImages copy];
artist.mediumSizedLandscapeImages = [mediumLandscapeImages copy];
artist.largeSizedImages = [largeImages copy]; artist.largeSizedImages = [largeImages copy];
artist.largeSizedPortraitImages = [largePortraitImages copy];
artist.largeSizedLandscapeImages = [largeLandscapeImages copy];
} }
} }
...@@ -141,12 +167,13 @@ ...@@ -141,12 +167,13 @@
[_requests removeObject:task]; [_requests removeObject:task];
} }
NSLog(@"response: %@", responseObject);
MDFMusicAlbum *musicAlbum = [[MDFMusicAlbum alloc] init]; MDFMusicAlbum *musicAlbum = [[MDFMusicAlbum alloc] init];
MDFArtist *artist;
if (responseObject != nil) { if (responseObject != nil) {
NSArray *albumsArray = responseObject[@"albums"]; NSArray *albumsArray = responseObject[@"albums"];
NSArray *imagesArray = responseObject[@"images"]; NSArray *imagesArray = responseObject[@"images"];
NSArray *artistsArray = responseObject[@"artists"];
NSInteger albumArtImageID = 0; NSInteger albumArtImageID = 0;
if (albumsArray != nil) { if (albumsArray != nil) {
NSDictionary *albumDict = [albumsArray firstObject]; NSDictionary *albumDict = [albumsArray firstObject];
...@@ -164,7 +191,11 @@ ...@@ -164,7 +191,11 @@
if (imagesArray != nil) { if (imagesArray != nil) {
NSUInteger imageCount = imagesArray.count; NSUInteger imageCount = imagesArray.count;
NSMutableArray *mediumImages = [NSMutableArray array]; NSMutableArray *mediumImages = [NSMutableArray array];
NSMutableArray *mediumPortraitImages = [NSMutableArray array];
NSMutableArray *mediumLandscapeImages = [NSMutableArray array];
NSMutableArray *largeImages = [NSMutableArray array]; NSMutableArray *largeImages = [NSMutableArray array];
NSMutableArray *largePortraitImages = [NSMutableArray array];
NSMutableArray *largeLandscapeImages = [NSMutableArray array];
for (NSUInteger x = 0; x < imageCount; x++) { for (NSUInteger x = 0; x < imageCount; x++) {
NSDictionary *imageDict = imagesArray[x]; NSDictionary *imageDict = imagesArray[x];
if (albumArtImageID > 0) { if (albumArtImageID > 0) {
...@@ -173,23 +204,62 @@ ...@@ -173,23 +204,62 @@
albumArtImageID = 0; // speed-up the further processing albumArtImageID = 0; // speed-up the further processing
continue; continue;
} }
if ([imageDict[@"width"] integerValue] > 1000) { NSMutableArray *mediumImages = [NSMutableArray array];
[largeImages addObject:imageDict[@"url"]]; NSMutableArray *mediumPortraitImages = [NSMutableArray array];
} else { NSMutableArray *mediumLandscapeImages = [NSMutableArray array];
[mediumImages addObject:imageDict[@"url"]]; NSMutableArray *largeImages = [NSMutableArray array];
NSMutableArray *largePortraitImages = [NSMutableArray array];
NSMutableArray *largeLandscapeImages = [NSMutableArray array];
NSUInteger imageCount = imagesArray.count;
for (NSUInteger x = 0; x < imageCount; x++) {
NSDictionary *imageDict = imagesArray[x];
NSInteger imageWidth = [imageDict[@"width"] integerValue];
NSInteger heightWidth = [imageDict[@"height"] integerValue];
NSString *imageURL = imageDict[@"url"];
if (imageWidth > 1000) {
[largeImages addObject:imageURL];
if (imageWidth > imageWidth) {
[largeLandscapeImages addObject:imageURL];
} else {
[largePortraitImages addObject:imageURL];
}
} else {
[mediumImages addObject:imageDict[@"url"]];
if (imageWidth > imageWidth) {
[mediumLandscapeImages addObject:imageURL];
} else {
[mediumPortraitImages addObject:imageURL];
}
}
} }
} }
musicAlbum.mediumSizedArtistImages = [mediumImages copy];
musicAlbum.mediumSizedPortraitArtistImages = [mediumPortraitImages copy];
musicAlbum.mediumSizedLandscapeArtistImages = [mediumLandscapeImages copy];
musicAlbum.largeSizedArtistImages = [largeImages copy];
musicAlbum.largeSizedPortraitArtistImages = [largePortraitImages copy];
musicAlbum.largeSizedLandscapeArtistImages = [largeLandscapeImages copy];
} }
musicAlbum.largeSizedArtistImages = [largeImages copy];
musicAlbum.mediumSizedArtistImages = [mediumImages copy];
} }
}
if (self.dataRecipient) { if (artistsArray != nil) {
if ([self.dataRecipient respondsToSelector:@selector(MDFHatchetFetcher:didFindAlbum:forArtistName:)]) { NSDictionary *artistDict = [artistsArray firstObject];
[self.dataRecipient MDFHatchetFetcher:self artist = [[MDFArtist alloc] init];
didFindAlbum:musicAlbum artist.name = artistDict[@"name"];
forArtistName:artistName]; artist.hatchetArtistID = [artistDict[@"id"] integerValue];
artist.biography = artistDict[@"wikiabstract"];
}
if (self.dataRecipient) {
if ([self.dataRecipient respondsToSelector:@selector(MDFHatchetFetcher:didFindAlbum:byArtist:forSearchRequest:)]) {
[self.dataRecipient MDFHatchetFetcher:self
didFindAlbum:musicAlbum
byArtist:artist
forSearchRequest:artistName];
}
} }
} }
} }
......
...@@ -47,12 +47,36 @@ ...@@ -47,12 +47,36 @@
*/ */
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedArtistImages; @property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedArtistImages;
/**
* medium sized image URL string(s) with a width < 1000px and a height > width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedPortraitArtistImages;
/**
* medium sized image URL string(s) with a width < 1000px and a height < width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *mediumSizedLandscapeArtistImages;
/** /**
* large image URL string(s) with a width > 1000px * large image URL string(s) with a width > 1000px
* \note base URL included * \note base URL included
*/ */
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedArtistImages; @property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedArtistImages;
/**
* large image URL string(s) with a width > 1000px and a height > width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedPortraitArtistImages;
/**
* large image URL string(s) with a width > 1000px and a height < width
* \note base URL included
*/
@property (readwrite, nonatomic, nullable) NSArray<NSString *> *largeSizedLandscapeArtistImages;
/** /**
* the Hatchet id of the album [NSInteger] * the Hatchet id of the album [NSInteger]
*/ */
......
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