110 lines
1.7 KiB
Mathematica
110 lines
1.7 KiB
Mathematica
|
//
|
||
|
// BooruImage.m
|
||
|
// cunnyfinder
|
||
|
//
|
||
|
// Created by James Shiffer on 12/20/22.
|
||
|
// Copyright © 2022 FemboyFinancial. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "BooruImage.h"
|
||
|
|
||
|
@implementation BooruImage
|
||
|
|
||
|
-(id)init:(NSDictionary<NSString*, NSString*> *)metadata
|
||
|
{
|
||
|
self.metadata = [[NSDictionary alloc] initWithDictionary:metadata];
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
-(int)width
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
return [self.metadata[@"width"] integerValue];
|
||
|
}
|
||
|
|
||
|
-(int)height
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
return [self.metadata[@"height"] integerValue];
|
||
|
}
|
||
|
|
||
|
-(int)previewWidth
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
return [self.metadata[@"preview_width"] integerValue];
|
||
|
}
|
||
|
|
||
|
-(int)previewHeight
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
return [self.metadata[@"preview_height"] integerValue];
|
||
|
}
|
||
|
|
||
|
-(int)sampleWidth
|
||
|
{
|
||
|
if (!self.metadata || ![self hasSample])
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
return [self.metadata[@"sample_width"] integerValue];
|
||
|
}
|
||
|
|
||
|
-(int)sampleHeight
|
||
|
{
|
||
|
if (!self.metadata || ![self hasSample])
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
return [self.metadata[@"sample_height"] integerValue];
|
||
|
}
|
||
|
|
||
|
-(NSURL *)fileUrl
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return nil;
|
||
|
}
|
||
|
return [NSURL URLWithString:self.metadata[@"file_url"]];
|
||
|
}
|
||
|
|
||
|
-(NSURL *)previewUrl
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return nil;
|
||
|
}
|
||
|
return [NSURL URLWithString:self.metadata[@"preview_url"]];
|
||
|
}
|
||
|
|
||
|
-(NSURL *)sampleUrl
|
||
|
{
|
||
|
if (!self.metadata || ![self hasSample])
|
||
|
{
|
||
|
return nil;
|
||
|
}
|
||
|
return [NSURL URLWithString:self.metadata[@"sample_url"]];
|
||
|
}
|
||
|
|
||
|
-(bool)hasSample
|
||
|
{
|
||
|
if (!self.metadata)
|
||
|
{
|
||
|
return nil;
|
||
|
}
|
||
|
return [self.metadata[@"sample"] boolValue];
|
||
|
}
|
||
|
|
||
|
@end
|