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|
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.homepage = "https://code.videolan.org/fkuehne/MetaDataFetcherKit"
......
......@@ -30,18 +30,47 @@
*/
@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
* \note base URL included
*/
@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
* \note base URL included
*/
@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]
*/
......
......@@ -33,7 +33,7 @@
- (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 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;
@end
......
......@@ -72,30 +72,56 @@
[_requests removeObject:task];
}
MDFArtist *artist = [[MDFArtist alloc] init];
MDFArtist *artist;
if (responseObject != nil) {
NSArray *artistsArray = responseObject[@"artists"];
NSArray *imagesArray = responseObject[@"images"];
if (artistsArray != nil) {
artist = [[MDFArtist alloc] init];
NSDictionary *artistDict = [artistsArray firstObject];
artist.hatchetArtistID = [artistDict[@"id"] integerValue];
artist.name = artistDict[@"name"];
artist.biography = artistDict[@"wikiabstract"];
}
if (imagesArray != nil) {
if (!artist)
artist = [[MDFArtist alloc] init];
NSMutableArray *mediumImages = [NSMutableArray array];
NSMutableArray *mediumPortraitImages = [NSMutableArray array];
NSMutableArray *mediumLandscapeImages = [NSMutableArray array];
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];
if ([imageDict[@"width"] integerValue] > 1000) {
[largeImages addObject:imageDict[@"url"]];
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];
}
}
}
artist.mediumSizedImages = [mediumImages copy];
artist.mediumSizedPortraitImages = [mediumPortraitImages copy];
artist.mediumSizedLandscapeImages = [mediumLandscapeImages copy];
artist.largeSizedImages = [largeImages copy];
artist.largeSizedPortraitImages = [largePortraitImages copy];
artist.largeSizedLandscapeImages = [largeLandscapeImages copy];
}
}
......@@ -141,12 +167,13 @@
[_requests removeObject:task];
}
NSLog(@"response: %@", responseObject);
MDFMusicAlbum *musicAlbum = [[MDFMusicAlbum alloc] init];
MDFArtist *artist;
if (responseObject != nil) {
NSArray *albumsArray = responseObject[@"albums"];
NSArray *imagesArray = responseObject[@"images"];
NSArray *artistsArray = responseObject[@"artists"];
NSInteger albumArtImageID = 0;
if (albumsArray != nil) {
NSDictionary *albumDict = [albumsArray firstObject];
......@@ -164,7 +191,11 @@
if (imagesArray != nil) {
NSUInteger imageCount = imagesArray.count;
NSMutableArray *mediumImages = [NSMutableArray array];
NSMutableArray *mediumPortraitImages = [NSMutableArray array];
NSMutableArray *mediumLandscapeImages = [NSMutableArray array];
NSMutableArray *largeImages = [NSMutableArray array];
NSMutableArray *largePortraitImages = [NSMutableArray array];
NSMutableArray *largeLandscapeImages = [NSMutableArray array];
for (NSUInteger x = 0; x < imageCount; x++) {
NSDictionary *imageDict = imagesArray[x];
if (albumArtImageID > 0) {
......@@ -173,23 +204,62 @@
albumArtImageID = 0; // speed-up the further processing
continue;
}
if ([imageDict[@"width"] integerValue] > 1000) {
[largeImages addObject:imageDict[@"url"]];
} else {
[mediumImages addObject:imageDict[@"url"]];
NSMutableArray *mediumImages = [NSMutableArray array];
NSMutableArray *mediumPortraitImages = [NSMutableArray array];
NSMutableArray *mediumLandscapeImages = [NSMutableArray array];
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 ([self.dataRecipient respondsToSelector:@selector(MDFHatchetFetcher:didFindAlbum:forArtistName:)]) {
[self.dataRecipient MDFHatchetFetcher:self
didFindAlbum:musicAlbum
forArtistName:artistName];
if (artistsArray != nil) {
NSDictionary *artistDict = [artistsArray firstObject];
artist = [[MDFArtist alloc] init];
artist.name = artistDict[@"name"];
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 @@
*/
@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
* \note base URL included
*/
@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]
*/
......
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