84 lines
1.6 KiB
Objective-C
84 lines
1.6 KiB
Objective-C
//
|
|
// SBMetadataResult.m
|
|
// Subler
|
|
//
|
|
// Created by Damiano Galassi on 17/02/16.
|
|
//
|
|
//
|
|
|
|
#import "SBMetadataResult.h"
|
|
#import <MP42Foundation/MP42Metadata.h>
|
|
|
|
@implementation SBMetadataResult
|
|
|
|
- (instancetype)init
|
|
{
|
|
if ((self = [super init]))
|
|
{
|
|
_tags = [[NSMutableDictionary alloc] init];
|
|
_artworks = [[NSMutableArray alloc] init];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)merge:(SBMetadataResult *)metadata
|
|
{
|
|
[_tags addEntriesFromDictionary:metadata.tags];
|
|
|
|
for (MP42Image *artwork in metadata.artworks) {
|
|
[_artworks addObject:artwork];
|
|
}
|
|
|
|
_mediaKind = metadata.mediaKind;
|
|
_contentRating = metadata.contentRating;
|
|
}
|
|
|
|
- (void)removeTagForKey:(NSString *)aKey
|
|
{
|
|
[_tags removeObjectForKey:aKey];
|
|
}
|
|
|
|
- (void)setTag:(id)value forKey:(NSString *)key
|
|
{
|
|
_tags[key] = value;
|
|
}
|
|
|
|
- (id)objectForKeyedSubscript:(NSString *)key
|
|
{
|
|
return _tags[key];
|
|
}
|
|
|
|
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key
|
|
{
|
|
if (obj == nil) {
|
|
[self removeTagForKey:key];
|
|
}
|
|
else {
|
|
[self setTag:obj forKey:key];
|
|
}
|
|
}
|
|
|
|
- (MP42Metadata *)metadata
|
|
{
|
|
MP42Metadata *metadata = [[MP42Metadata alloc] init];
|
|
|
|
for (NSString *key in [MP42Metadata writableMetadata]) {
|
|
NSString *tagValue;
|
|
if ((tagValue = _tags[key])) {
|
|
[metadata setTag:tagValue forKey:key];
|
|
}
|
|
}
|
|
|
|
for (MP42Image *artwork in self.artworks) {
|
|
[metadata.artworks addObject:artwork];
|
|
}
|
|
|
|
metadata.mediaKind = self.mediaKind;
|
|
metadata.contentRating = self.contentRating;
|
|
|
|
return metadata;
|
|
}
|
|
|
|
@end
|