Skip to content

Fix playlist import for songs with accented characters #4385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jul 26, 2025

Description

Fixes playlist import issues for songs with accented characters from Apple Music M3U playlists. The problem occurred because Apple Music exports M3U playlists with Unicode NFC (Canonical Composed) encoding while macOS filesystem normalizes paths to NFD (Canonical Decomposed) encoding, causing path mismatches during playlist import.

Related Issues

Fixes #3332

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor
  • Other (please describe):

Checklist

Please review and check all that apply:

  • My code follows the project's coding style
  • I have tested the changes locally
  • I have added or updated documentation as needed
  • I have added tests that prove my fix/feature works (or explain why not)
  • All existing and new tests pass

How to Test

  1. Run specific Unicode tests: Use go test -v ./core -ginkgo.focus "normalizePathForComparison|Unicode normalization" to run only the Unicode-related tests
  2. Integration testing (optional):
    • Create a test M3U file with paths containing accented characters (both NFC and NFD encoded)
    • Place it in a monitored playlist directory
    • Verify that songs are correctly matched during playlist sync

Screenshots / Demos (if applicable)

N/A - This is a backend fix for Unicode path handling.

Additional Notes

Technical Details:

  • Added normalizePathForComparison() helper function that normalizes paths to NFC form using golang.org/x/text/unicode/norm
  • Updated parseM3U() to normalize both filesystem paths and M3U playlist paths before comparison
  • Added comprehensive test coverage for Unicode normalization scenarios including both NFC and NFD character representations

Root Cause:
Apple Music exports M3U playlists with Unicode characters in NFC (Canonical Composed) form, while macOS filesystem stores file paths in NFD (Canonical Decomposed) form. For example:

  • M3U path: Noël (NFC: é as single character U+00E9)
  • Filesystem path: Noël (NFD: e + combining acute accent U+0065 U+0301)

These look identical but have different byte representations, causing the path matching to fail during playlist import.

Impact:
This fix resolves the issue for all users on macOS who import playlists from Apple Music containing songs with accented characters, diacritics, or other Unicode combining characters.

Fixes #3332 where songs with accented characters failed to import from Apple Music M3U playlists. The issue occurred because Apple Music exports use NFC Unicode normalization while macOS filesystem stores paths in NFD normalization.

Added normalizePathForComparison() function that normalizes both filesystem and M3U playlist paths to NFC form before comparison. This ensures consistent path matching regardless of the Unicode normalization form used.

Changes include comprehensive test coverage for Unicode normalization scenarios with both NFC and NFD character representations.
@Copilot Copilot AI review requested due to automatic review settings July 26, 2025 14:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes playlist import issues for songs with accented characters from Apple Music M3U playlists. The problem occurs due to Unicode normalization differences between Apple Music's NFC encoding and macOS filesystem's NFD encoding, causing path mismatches during import.

  • Adds Unicode normalization to path comparison logic
  • Introduces normalizePathForComparison() helper function using NFC normalization
  • Updates path matching in parseM3U() to handle Unicode encoding differences

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core/playlists.go Adds Unicode normalization helper function and updates path comparison logic in parseM3U()
core/playlists_test.go Adds comprehensive test coverage for Unicode normalization scenarios and path comparison edge cases
Comments suppressed due to low confidence (2)

core/playlists_test.go:196

  • The test comment claims this is NFD form, but the string literal may not actually be in NFD encoding. Consider using norm.NFD.String() to explicitly create an NFD-encoded string for this test case to ensure the test accurately represents the real-world scenario.
			nfdPath := "artist/Michèle Desrosiers/album/Noël.m4a" // NFD form

core/playlists_test.go:200

  • Similar to the NFD case, this string literal may not actually be in NFC encoding. Consider using norm.NFC.String() to explicitly create an NFC-encoded string to ensure the test properly validates the Unicode normalization fix.
			nfcPath := "/music/artist/Michèle Desrosiers/album/Noël.m4a" // NFC form

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @deluan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a bug that prevented the successful import of M3U playlists containing songs with accented characters, particularly those exported from Apple Music on macOS. The core of the fix involves implementing robust Unicode path normalization to ensure consistent comparisons between playlist entries and filesystem paths, thereby eliminating mismatches caused by differing Unicode encoding forms.

Highlights

  • Unicode Path Normalization Utility: I've introduced a new helper function, normalizePathForComparison(), which standardizes file paths by converting them to Unicode NFC (Normalization Form Canonical Composition) and then to lowercase. This is crucial for consistent path comparisons, especially when dealing with different Unicode representations.
  • Playlist Import Fix: The parseM3U() function has been updated to utilize the new normalizePathForComparison() function. This ensures that both the paths found in the music library and the paths read from M3U playlist files are normalized to the same Unicode form (NFC) before comparison, resolving issues where paths with accented characters might not match due to differing Unicode encodings (e.g., NFC from Apple Music M3U vs. NFD from macOS filesystems).
  • Comprehensive Test Coverage: I've added new test cases to core/playlists_test.go to specifically validate the Unicode normalization logic. These tests cover scenarios involving both NFC and NFD character representations, ensuring the fix correctly handles accented characters and prevents regressions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request provides a solid fix for importing playlists with accented characters on macOS by addressing Unicode normalization differences. The core logic change correctly uses golang.org/x/text/unicode/norm to normalize paths to NFC before comparison. The addition of a dedicated helper function normalizePathForComparison improves code clarity.

The new tests are comprehensive, covering both the helper function in isolation and the end-to-end import scenario. I've made one suggestion to improve the robustness of an integration test to ensure it explicitly tests the NFC vs. NFD normalization mismatch.

Overall, this is a high-quality contribution that effectively solves the reported issue.

deluan added 2 commits July 26, 2025 10:51
Signed-off-by: Deluan <deluan@navidrome.org>
…normalization tests

Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan merged commit d28a282 into master Jul 26, 2025
35 checks passed
@deluan deluan deleted the fix/playlist-unicode-normalization branch July 26, 2025 15:27
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.

[Bug]: Songs with accented characters do not auto-import from Apple Music m3u playlists
1 participant