// // MP42MkvTagWriter.h // MP42Foundation // // Rewrites the Tags element (and, when the cover art changed, the // Attachments element) of an existing Matroska file in place, leaving all // track payloads and clusters untouched. Conceptually the same job as // `mkvpropedit --tags`. // // When model tracks are supplied, the per-track fields the model exposes — // Name, TrackLanguage/LanguageIETF, TrackFlagEnabled and (for subtitles) // TrackFlagForced — are diffed against each TrackEntry's effective values // and the Tracks element is rebuilt with only the changed fields // substituted. Conceptually `mkvpropedit --edit track:… --set …`; all other // TrackEntry children (CodecPrivate, timings, …) are copied byte-for-byte. // // When the new content fits into the old element's extent plus the Void // padding that follows it, the region is rewritten without shifting any // other byte (fast path, SeekHead/Cues/Segment stay valid). Otherwise the // file tail is rebuilt through a temporary file, SeekHead and Cues position // entries are recomputed, and the result atomically replaces the original. // // Tag groups Subler does not model (chapter/scene/shot targets, track/ // edition/attachment targets, unmapped SimpleTag names such as ACTOR, // binary-valued tags) and non-cover attachments are preserved verbatim from // the file on disk, so saving never silently drops data the UI never showed. // #import #import @class MP42Metadata; @class MP42Track; NS_ASSUME_NONNULL_BEGIN @interface MP42MkvTagWriter : NSObject @property (nonatomic, readonly) NSURL *fileURL; // When set, the write refuses to touch a file whose size or modification // date no longer matches (callers snapshot these when the document is read). @property (nonatomic) uint64_t expectedFileSize; @property (nonatomic, copy, nullable) NSDate *expectedModificationDate; // Called on the writing thread with a 0...1 estimate; may be nil. @property (nonatomic, copy, nullable) void (^progressHandler)(double progress); - (instancetype)initWithURL:(NSURL *)URL; - (BOOL)writeMetadata:(MP42Metadata *)metadata error:(NSError * _Nullable *)outError; // Also apply per-track edits (name, language, enabled, subtitle forced) // taken from the model tracks. The array must hold the document's tracks in // file order; chapter tracks are ignored (they are not Matroska tracks). // Pass nil to leave the Tracks element untouched. - (BOOL)writeMetadata:(MP42Metadata *)metadata tracks:(nullable NSArray *)tracks error:(NSError * _Nullable *)outError; // Safe to call from another thread while -writeMetadata:error: is running; // the write aborts at the next chunk boundary leaving the original file // untouched. - (void)cancel; @end NS_ASSUME_NONNULL_END