diff --git a/MP42/MP42Metadata.h b/MP42/MP42Metadata.h index 84e54ea..5ff66e0 100644 --- a/MP42/MP42Metadata.h +++ b/MP42/MP42Metadata.h @@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSArray *items; /*! - @abstract Filters an array of AVMetadataItems according to identifier. + @abstract Filters an array of MP42MetadataItems according to identifier. @param identifier The identifier that must be matched for a metadata item to be copied to the output array. Items are considered a match not only when their identifiers are equal to the specified identifier, and also when their identifiers conform to the specified identifier. @result An instance of NSArray containing the metadata items of the target NSArray that match the specified identifier. @@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSArray *)metadataItemsFilteredByIdentifier:(NSString *)identifier; /*! - @abstract Filters an array of AVMetadataItems according to a identifiers array. + @abstract Filters an array of MP42MetadataItems according to a identifiers array. @param identifiers The identifiers that must be matched for a metadata item to be copied to the output array. Items are considered a match not only when their identifiers are equal to the specified identifier, and also when their identifiers conform to the specified identifier. @result An instance of NSArray containing the metadata items of the target NSArray that match the specified identifier. @@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSArray *)metadataItemsFilteredByIdentifiers:(NSArray *)identifiers; /*! - @abstract Filters an array of AVMetadataItems according a data type mask. + @abstract Filters an array of MP42MetadataItems according a data type mask. @param dataType The identifier that must be matched for a metadata item to be copied to the output array. Items are considered a match not only when their identifiers are equal to the specified identifier, and also when their identifiers conform to the specified identifier. @result An instance of NSArray containing the metadata items of the target NSArray that match the specified identifier. @@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN @param metadata the instance to merge. */ -- (void)mergeMetadata:(MP42Metadata *)metadata; +- (void)mergeMetadata:(MP42Metadata *)metadata overwrite:(BOOL)overwrite; @end diff --git a/MP42/MP42Metadata.m b/MP42/MP42Metadata.m index a2149d4..7d2a6d3 100644 --- a/MP42/MP42Metadata.m +++ b/MP42/MP42Metadata.m @@ -56,7 +56,7 @@ if (self) { MP42XMLReader *xmlReader = [[MP42XMLReader alloc] initWithURL:URL error:NULL]; if (xmlReader) { - [self mergeMetadata:[xmlReader mMetadata]]; + [self mergeMetadata:[xmlReader mMetadata] overwrite:true]; } else { return nil; } @@ -414,7 +414,7 @@ #pragma mark - Mutators -- (void)mergeMetadata:(MP42Metadata *)metadata { +- (void)mergeMetadata:(MP42Metadata *)metadata overwrite:(BOOL)overwrite { NSArray *coverArts = [metadata metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt]; // Remove existings cover arts only if new one is available @@ -425,7 +425,14 @@ } for (MP42MetadataItem *item in metadata.items) { - [self addMetadataItem:[item copy]]; + if (overwrite) { + [self addMetadataItem:[item copy]]; + } + else { + if ([self metadataItemsFilteredByIdentifier:item.identifier].count == 0) { + [self addMetadataItem:[item copy]]; + } + } } self.edited = YES; @@ -1465,7 +1472,7 @@ - (id)copyWithZone:(NSZone *)zone { MP42Metadata *newObject = [[MP42Metadata allocWithZone:zone] init]; - [newObject mergeMetadata:self]; + [newObject mergeMetadata:self overwrite:true]; return newObject; } diff --git a/MP42/MP42MkvImporter.m b/MP42/MP42MkvImporter.m index 439b7e4..6a41a0c 100644 --- a/MP42/MP42MkvImporter.m +++ b/MP42/MP42MkvImporter.m @@ -336,7 +336,7 @@ MP42_OBJC_DIRECT_MEMBERS [self addTrack:newTrack]; } - [self.metadata mergeMetadata:[self readMatroskaMetadata]]; + [self.metadata mergeMetadata:[self readMatroskaMetadata] overwrite:true]; } return self; diff --git a/MP42/MP42Mp4Importer.m b/MP42/MP42Mp4Importer.m index 71e732f..32e8190 100644 --- a/MP42/MP42Mp4Importer.m +++ b/MP42/MP42Mp4Importer.m @@ -46,7 +46,7 @@ typedef struct MP4DemuxHelper { } [self addTracks:sourceFile.tracks]; - [self.metadata mergeMetadata:sourceFile.metadata]; + [self.metadata mergeMetadata:sourceFile.metadata overwrite:true]; } return self;