Add a metadata overwrite option
This commit is contained in:
4 files changed
+17
-10
No files matched your search
+4
-4
@@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, readonly) NSArray<MP42MetadataItem *> *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<MP42MetadataItem *> *)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<MP42MetadataItem *> *)metadataItemsFilteredByIdentifiers:(NSArray<NSString *> *)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
|
||||
|
||||
|
||||
+11
-4
@@ -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<MP42MetadataItem *> *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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user