Skip to content

feat: Save Matroska and WebM tags - #106

Merged
decriptor merged 4 commits into
mainfrom
feat/matroska-save
Nov 17, 2026
Merged

decriptor merged 4 commits into
mainfrom
feat/matroska-save

Conversation

@decriptor

@decriptor decriptor commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Saves Matroska and WebM tag values by splicing MatroskaTag.Render into the first Segment. An unknown-size Segment ends at the next EBML header or the next Segment, and the bytes after that are copied unchanged. MediaFile.Read(string) now sets SourcePath for Matroska so SaveToFile() can write back through AtomicFileWriter. A failed rewrite does not touch the destination.

Round-trips the fields the reader already maps: title, artist, performers, album, album artist, year, comment, genre, track, total tracks, composer, copyright, description, lyrics, conductor, and publisher. Clearing a value removes it. WebM keeps its DocType.

Cluster, attachment, and cue payload bytes are copied through. A title edit does not move or alter a known-size Cluster (duration, sample rate, and picture bytes stay). An unknown-size tail that has to move gets CueClusterPosition updated, including the Cues CRC-32. SeekHead entries for Tags are rewritten when the new Segment position fits in the existing Seek element; otherwise that entry is replaced with Void so it cannot point at the old offset. A new Seek is added only when a Void inside or directly after the SeekHead is large enough.

Files the reader cannot bound (an unknown-size element that does not parse through to a sibling or the parent end, or a gap after the first element) fail the save and are left unchanged. Nothing is resynced by scanning media bytes.

Not rewritten

  • Image attachments. Existing Attachments elements are preserved; the Pictures setter still does not emit them.
  • Chapters elements and FlagEnabled. A Tag aimed at a chapter, track, edition, or attachment is copied back unchanged. A file-level tag keeps its target UIDs, TagLanguage, TagLanguageBCP47, and TagBinary.
  • AlbumArtistSort and ComposerSort.
  • Cue-relative timestamps and the Opus 48000 Hz rule.
  • Bytes inside a Cluster, including an in-cluster Position.

Fixes #53

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.49372% with 165 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.07%. Comparing base (bb0b21d) to head (0f5b750).

Files with missing lines Patch % Lines
src/TagLibSharp2/Matroska/MatroskaRewrite.cs 77.69% 71 Missing and 53 partials ⚠️
...s/TagLibSharp2.Tests/Matroska/MatroskaSaveTests.cs 95.81% 17 Missing and 14 partials ⚠️
src/TagLibSharp2/Matroska/MatroskaFile.cs 91.42% 4 Missing and 5 partials ⚠️
src/TagLibSharp2/Core/MediaFile.cs 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
- Coverage   93.19%   93.07%   -0.13%     
==========================================
  Files         276      278       +2     
  Lines       51734    53151    +1417     
  Branches     4595     4831     +236     
==========================================
+ Hits        48214    49470    +1256     
- Misses       2078     2168      +90     
- Partials     1442     1513      +71     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@decriptor
decriptor merged commit 113c244 into main Nov 17, 2026
8 checks passed
@decriptor
decriptor deleted the feat/matroska-save branch November 17, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Matroska tagging support

1 participant