Skip to content

feat: enhance TIDAL_DATA parsing and filtering in readTrackMetadata f…#690

Open
Muhammad5777 wants to merge 1 commit into
monochrome-music:mainfrom
Muhammad5777:feat/read-tidal-data
Open

feat: enhance TIDAL_DATA parsing and filtering in readTrackMetadata f…#690
Muhammad5777 wants to merge 1 commit into
monochrome-music:mainfrom
Muhammad5777:feat/read-tidal-data

Conversation

@Muhammad5777
Copy link
Copy Markdown

@Muhammad5777 Muhammad5777 commented Jun 4, 2026

bug: enhance TIDAL_DATA parsing and filtering in readTrackMetadata function

Description

On large local file playlists (>100) with the shuffle tuned on, The raw data was clogging localStorage; Added a filter to stop it doing that.
The filter managed to reduce the size of JSON.parse(localStorage.getItem('monochrome-queue')) by 5x

Type of Change

  • Bug fix

Checklist

  • I have read the Contributing Guidelines.
  • I understand every line of code I am submitting.
  • I have tested these changes locally, and they work as expected.
  • Is this Pull request Using AI/Is Vibecoded?

By submitting this PR, I agree to follow the guidelines. I understand that the final decision to merge rests with the maintainers and that not all contributions can be accepted.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced track metadata parsing with improved error handling and data sanitization for greater reliability.

…unction

on large local playlists (>100) with the shuffle tuned on the raw data was clogging localstorage, added a filter to stop it doing that.

The filter managed to reduce the size of `JSON.parse(localStorage.getItem('monochrome-queue'))` by 5x
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

readTrackMetadata in js/metadata.js now performs more robust parsing of data.extra.TIDAL_DATA: it attempts JSON parsing, and on failure either filters an object-shaped value or stores the raw value as a string with a warning. Both routes converge on a new local filterTidalTrack helper that constructs a sanitized metadata.tidalData object with selected fields including nested album data.

Changes

TIDAL metadata parsing and filtering

Layer / File(s) Summary
TIDAL data parsing and filtering logic
js/metadata.js
readTrackMetadata introduces robust JSON parsing of data.extra.TIDAL_DATA, with error handling that falls back to object filtering or raw string storage with warning. A new filterTidalTrack(full) helper function selects and normalizes a fixed subset of top-level and nested album fields into metadata.tidalData.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐇 A rabbit hops through metadata streams,
Parsing TIDAL data—no more broken dreams!
Where JSON fails, objects stand tall,
The filterTidalTrack catches them all. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: enhancing TIDAL_DATA parsing and filtering in the readTrackMetadata function, which aligns with the core improvements made.
Description check ✅ Passed The description covers all required template sections including description, type of change, and completed checklist items with substantive context about the performance improvement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

js/metadata.js

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@js/metadata.js`:
- Around line 207-208: Replace the unbounded raw-string fallback for TIDAL_DATA
by truncating or omitting it: instead of directly assigning
data.extra.TIDAL_DATA to metadata.tidalData, check parsed validity and if
parsing fails set metadata.tidalData to either a bounded substring (e.g., first
N chars) or simply omit the property; update the assignment site that currently
performs metadata.tidalData = data.extra.TIDAL_DATA and the related console.warn
so the stored payload is size-limited (and include context in the warn message
if you keep a truncated fallback).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88caccfd-e915-462b-9be8-7f006b90dcd5

📥 Commits

Reviewing files that changed from the base of the PR and between b6c83c5 and 6002735.

📒 Files selected for processing (1)
  • js/metadata.js

Comment thread js/metadata.js
Comment on lines +207 to +208
metadata.tidalData = data.extra.TIDAL_DATA; // raw string fallback
console.warn('TIDAL_DATA is not valid JSON or object, storing as raw string');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid unbounded raw-string fallback for invalid TIDAL_DATA.

On parse failure, Line 207 stores the full raw payload. That can still blow up queue/localStorage size and recreate the quota-pressure issue this PR is fixing. Prefer a bounded fallback (or omit tidalData) instead of persisting the full string.

Suggested fix
-                        metadata.tidalData = data.extra.TIDAL_DATA; // raw string fallback
-                        console.warn('TIDAL_DATA is not valid JSON or object, storing as raw string');
+                        const raw = String(data.extra.TIDAL_DATA);
+                        metadata.tidalData = {
+                            parseError: true,
+                            rawLength: raw.length,
+                            rawPreview: raw.slice(0, 256),
+                        };
+                        console.warn('TIDAL_DATA is not valid JSON/object; stored bounded fallback');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@js/metadata.js` around lines 207 - 208, Replace the unbounded raw-string
fallback for TIDAL_DATA by truncating or omitting it: instead of directly
assigning data.extra.TIDAL_DATA to metadata.tidalData, check parsed validity and
if parsing fails set metadata.tidalData to either a bounded substring (e.g.,
first N chars) or simply omit the property; update the assignment site that
currently performs metadata.tidalData = data.extra.TIDAL_DATA and the related
console.warn so the stored payload is size-limited (and include context in the
warn message if you keep a truncated fallback).

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.

1 participant