Skip to content

Enhance MP3 Quick Cleanse ID3v2.3 metadata writing#39

Merged
ChrisAdamsdevelopment merged 1 commit into
mainfrom
codex/enhance-mp3-quick-cleanse-id3-metadata-completeness
May 21, 2026
Merged

Enhance MP3 Quick Cleanse ID3v2.3 metadata writing#39
ChrisAdamsdevelopment merged 1 commit into
mainfrom
codex/enhance-mp3-quick-cleanse-id3-metadata-completeness

Conversation

@ChrisAdamsdevelopment
Copy link
Copy Markdown
Owner

@ChrisAdamsdevelopment ChrisAdamsdevelopment commented May 21, 2026

Motivation

  • Improve MP3 Quick Cleanse output so release-quality metadata is written into MP3s while avoiding unsupported frames that previously caused failures.
  • Use only safe ID3v2.3 frames and preserve the deterministic, browser-based Quick Cleanse flow.
  • Add compact diagnostics so callers can see which frames were attempted, written, or skipped without exposing large private fields.

Description

  • Updated src/utils/metadata.js writeMP3Metadata to write safe ID3v2.3 frames and to track attemptedFrames, writtenFrames, and skippedFrames.
  • Implemented safe writes for TIT2, TPE1, TPE2, TCON, COMM, USLT (optional), and TCOP, and optional attempts for TPUB and TXXX:Producer that are skipped with console.warn if unsupported.
  • Added fallback behaviors: albumArtist defaults to artist, comment falls back to description, producer/tags are folded into COMM if a producer frame is unsafe, and copyright defaults to © CURRENT_YEAR <artist> when absent.
  • Updated app.tsx to expand ReleaseMetadata and to pass the fuller metadata payload (title, artist, albumArtist, producer, copyright, genre, description, comment, lyrics, tags, publisher) into writeMP3Metadata, and to log a compact frame write/skip summary.
  • Files changed: src/utils/metadata.js, app.tsx.

Testing

  • Ran a repo search confirming TENC/TSSE are not written anywhere and that new safe frames (TIT2,TPE1,TPE2,TCON,COMM,USLT,TCOP,TPUB,TXXX) are present in the code.
  • Executed npm run build; the build failed in this container due to missing React/TypeScript environment dependencies unrelated to these metadata changes.
  • Verified (static checks) that Quick Cleanse code path still creates a downloadable object URL and that writeMP3Metadata now returns a frameReport summarizing attemptedFrames, writtenFrames, and skippedFrames so unsupported optional frames cannot crash the cleanse.

Codex Task

Summary by Sourcery

Enhance MP3 Quick Cleanse to write safer, richer ID3v2.3 metadata and surface a compact report of frame write outcomes.

New Features:

  • Extend MP3 metadata writing to support album artist, publisher, comment, lyrics, tags, and computed copyright using safe ID3v2.3 frames.
  • Return an MP3 metadata write result that includes both the rewritten audio blob and a frame report summarizing attempted, written, and skipped frames.
  • Log a concise ID3 frame write and skip summary into the Quick Cleanse UI for each processed MP3.

Enhancements:

  • Tighten text sanitization for ID3 fields with configurable maximum lengths and richer fallback behavior for comment and copyright metadata.
  • Update Quick Cleanse metadata resolution to populate new release metadata fields with sensible defaults and parsed values.
  • Include a static list of core frames in the forensic report to document which ID3 frames Quick Cleanse attempts to write.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 21, 2026

Reviewer's Guide

Enhances MP3 Quick Cleanse to write a richer but safe ID3v2.3 metadata set, adds frame-level tracking/reporting for attempted/written/skipped frames, and updates the app to provide expanded release metadata into the writer and surface a compact log summary of frame outcomes.

Sequence diagram for updated MP3 metadata writing and logging

sequenceDiagram
  actor User
  participant App
  participant writeMP3Metadata
  participant writer

  User->>App: Start Quick Cleanse
  App->>writeMP3Metadata: writeMP3Metadata(file, metadata)
  writeMP3Metadata->>writer: setFrame(TIT2, title)
  writeMP3Metadata->>writer: setFrame(TPE1, [artist])
  writeMP3Metadata->>writer: setFrame(TPE2, [albumArtist])
  writeMP3Metadata->>writer: setFrame(TCON, [genre])
  writeMP3Metadata->>writer: setFrame(COMM, comment)
  writeMP3Metadata->>writer: setFrame(USLT, lyrics) [optional]
  writeMP3Metadata->>writer: setFrame(TCOP, copyright) [optional]
  writeMP3Metadata->>writer: setFrame(TPUB, [publisher]) [optional]
  writeMP3Metadata->>writer: setFrame(TXXX, producer) [optional]
  writeMP3Metadata-->>App: { blob, frameReport }
  App->>App: addLog(itemId, frameReport summary)
  App->>App: updateItem(itemId, downloadUrl, report)
Loading

File-Level Changes

Change Details Files
Harden and expand MP3 ID3v2.3 metadata writing with safe frames, richer field support, and frame-level reporting.
  • Extend safeText helper to support configurable maximum lengths for different fields.
  • Derive additional metadata fields (albumArtist, description, comment, lyrics, producer, publisher, tags, computedCopyright) with sensible fallbacks.
  • Track attempted, written, and skipped ID3 frame IDs during write operations.
  • Wrap writer.setFrame in safeSetFrame that logs and records skipped frames while supporting optional frames that can safely fail.
  • Write core ID3v2.3 frames TIT2, TPE1, TPE2, TCON using normalized values.
  • Construct a combined COMM comment from comment/description, optionally appending producer and tags annotations.
  • Optionally write USLT (lyrics), TCOP (copyright), TPUB (publisher), and TXXX:Producer when supported, skipping them safely otherwise.
  • Log a compact metadata summary (flags + frame lists) after attempting writes.
  • Change writeMP3Metadata return type to include both the rewritten Blob and a frameReport with attempted/written/skipped frames.
src/utils/metadata.js
Plumb expanded ReleaseMetadata through the app and log frame write results for Quick Cleanse.
  • Extend ReleaseMetadata type and initial/default metadata resolution to include albumArtist and comment fields, and to keep them non-empty where needed.
  • Update Quick Cleanse MP3 path to pass expanded metadata (albumArtist, producer, copyright, description, comment, lyrics, tags, publisher) into writeMP3Metadata, with sensible fallbacks from SEO/analysis fields.
  • Handle the new writeMP3Metadata return shape by extracting the blob and logging which frames were written or skipped via addLog.
  • Augment the forensic/cleanup report to include a static note about core ID3 frames being attempted.
app.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The hardcoded report message 'Core frames attempted: TIT2,TPE1,TPE2,TCON,COMM,USLT,TCOP' in App is now out of sync with the actual set of frames attempted (e.g. TPUB, TXXX), so it may be worth deriving this summary from frameReport.attemptedFrames instead of maintaining a separate static list.
  • The new console.info summary and console.warn calls inside writeMP3Metadata will fire on every Quick Cleanse run and for all optional-frame failures; consider gating these logs behind a debug flag or reducing their frequency to avoid noisy consoles in production.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The hardcoded report message `'Core frames attempted: TIT2,TPE1,TPE2,TCON,COMM,USLT,TCOP'` in `App` is now out of sync with the actual set of frames attempted (e.g. TPUB, TXXX), so it may be worth deriving this summary from `frameReport.attemptedFrames` instead of maintaining a separate static list.
- The new `console.info` summary and `console.warn` calls inside `writeMP3Metadata` will fire on every Quick Cleanse run and for all optional-frame failures; consider gating these logs behind a debug flag or reducing their frequency to avoid noisy consoles in production.

## Individual Comments

### Comment 1
<location path="src/utils/metadata.js" line_range="211-213" />
<code_context>
+    if (publisher) safeSetFrame('TPUB', [publisher], { optional: true });
+    if (producer) safeSetFrame('TXXX', { description: 'Producer', value: producer }, { optional: true });
+
+    console.info('[quick-cleanse] mp3 metadata summary', {
+      hasLyrics: Boolean(lyrics),
+      hasComment: Boolean(commentText),
+      hasDescription: Boolean(description),
+      hasProducer: Boolean(producer),
</code_context>
<issue_to_address>
**suggestion:** The hasComment flag may not reflect whether a comment frame was actually written.

Since `finalComment` adds producer/tags to `commentText`, `hasComment` can be `false` even when a `COMM` frame is written (e.g., empty `commentText` but non-empty producer/tags). If this summary is for debugging/analytics, consider deriving it from `Boolean(finalComment)` or from whether `writtenFrames` includes `COMM` so it matches actual behavior.

Suggested implementation:

```javascript
    console.info('[quick-cleanse] mp3 metadata summary', {
      hasLyrics: Boolean(lyrics),
      hasComment: Boolean(finalComment),
      hasDescription: Boolean(description),
      hasProducer: Boolean(producer),
      attemptedFrames,
      writtenFrames,
      skippedFrames,
    });

```

1. Ensure that `finalComment` is defined in this function and that it is the exact value used when calling `safeSetFrame('COMM', ...)` (e.g., `text: finalComment`).
2. If `finalComment` is not currently available in this scope, either:
   - Plumb it through so it is, or
   - Change the implementation to derive `hasComment` from whether the `COMM` frame was actually written, e.g. `hasComment: writtenFrames?.includes?.('COMM')`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/utils/metadata.js
Comment on lines +211 to +213
console.info('[quick-cleanse] mp3 metadata summary', {
hasLyrics: Boolean(lyrics),
hasComment: Boolean(commentText),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The hasComment flag may not reflect whether a comment frame was actually written.

Since finalComment adds producer/tags to commentText, hasComment can be false even when a COMM frame is written (e.g., empty commentText but non-empty producer/tags). If this summary is for debugging/analytics, consider deriving it from Boolean(finalComment) or from whether writtenFrames includes COMM so it matches actual behavior.

Suggested implementation:

    console.info('[quick-cleanse] mp3 metadata summary', {
      hasLyrics: Boolean(lyrics),
      hasComment: Boolean(finalComment),
      hasDescription: Boolean(description),
      hasProducer: Boolean(producer),
      attemptedFrames,
      writtenFrames,
      skippedFrames,
    });
  1. Ensure that finalComment is defined in this function and that it is the exact value used when calling safeSetFrame('COMM', ...) (e.g., text: finalComment).
  2. If finalComment is not currently available in this scope, either:
    • Plumb it through so it is, or
    • Change the implementation to derive hasComment from whether the COMM frame was actually written, e.g. hasComment: writtenFrames?.includes?.('COMM').

@ChrisAdamsdevelopment ChrisAdamsdevelopment merged commit 6f1d988 into main May 21, 2026
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant