Add a metadata overwrite option

This commit is contained in:
Damiano Galassi committed 2026-09-11 09:51:30 +02:00
1 parent 740fd075b3
commit 2b36c035de
4 files changed
+16 -9

No files matched your search

+4 -4
View File
@@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSArray<MP42MetadataItem *> *items; @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 @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. 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. @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; - (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 @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. 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. @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; - (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 @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. 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. @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. @param metadata the instance to merge.
*/ */
- (void)mergeMetadata:(MP42Metadata *)metadata; - (void)mergeMetadata:(MP42Metadata *)metadata overwrite:(BOOL)overwrite;
@end @end
+10 -3
View File
@@ -56,7 +56,7 @@
if (self) { if (self) {
MP42XMLReader *xmlReader = [[MP42XMLReader alloc] initWithURL:URL error:NULL]; MP42XMLReader *xmlReader = [[MP42XMLReader alloc] initWithURL:URL error:NULL];
if (xmlReader) { if (xmlReader) {
[self mergeMetadata:[xmlReader mMetadata]]; [self mergeMetadata:[xmlReader mMetadata] overwrite:true];
} else { } else {
return nil; return nil;
} }
@@ -414,7 +414,7 @@
#pragma mark - Mutators #pragma mark - Mutators
- (void)mergeMetadata:(MP42Metadata *)metadata { - (void)mergeMetadata:(MP42Metadata *)metadata overwrite:(BOOL)overwrite {
NSArray<MP42MetadataItem *> *coverArts = [metadata metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt]; NSArray<MP42MetadataItem *> *coverArts = [metadata metadataItemsFilteredByIdentifier:MP42MetadataKeyCoverArt];
// Remove existings cover arts only if new one is available // Remove existings cover arts only if new one is available
@@ -425,8 +425,15 @@
} }
for (MP42MetadataItem *item in metadata.items) { for (MP42MetadataItem *item in metadata.items) {
if (overwrite) {
[self addMetadataItem:[item copy]]; [self addMetadataItem:[item copy]];
} }
else {
if ([self metadataItemsFilteredByIdentifier:item.identifier].count == 0) {
[self addMetadataItem:[item copy]];
}
}
}
self.edited = YES; self.edited = YES;
self.artworkEdited = YES; self.artworkEdited = YES;
@@ -1465,7 +1472,7 @@
- (id)copyWithZone:(NSZone *)zone - (id)copyWithZone:(NSZone *)zone
{ {
MP42Metadata *newObject = [[MP42Metadata allocWithZone:zone] init]; MP42Metadata *newObject = [[MP42Metadata allocWithZone:zone] init];
[newObject mergeMetadata:self]; [newObject mergeMetadata:self overwrite:true];
return newObject; return newObject;
} }
+1 -1
View File
@@ -336,7 +336,7 @@ MP42_OBJC_DIRECT_MEMBERS
[self addTrack:newTrack]; [self addTrack:newTrack];
} }
[self.metadata mergeMetadata:[self readMatroskaMetadata]]; [self.metadata mergeMetadata:[self readMatroskaMetadata] overwrite:true];
} }
return self; return self;
+1 -1
View File
@@ -46,7 +46,7 @@ typedef struct MP4DemuxHelper {
} }
[self addTracks:sourceFile.tracks]; [self addTracks:sourceFile.tracks];
[self.metadata mergeMetadata:sourceFile.metadata]; [self.metadata mergeMetadata:sourceFile.metadata overwrite:true];
} }
return self; return self;