Shuttle2 icon indicating copy to clipboard operation
Shuttle2 copied to clipboard

M3u playlist export

Open timusus opened this issue 3 months ago • 0 comments

This commit implements a robust, scalable, and accurate solution for exporting playlists to m3u format as requested in issue #112.

Core Components:

  • M3uWriter: Generates m3u file content from song lists with proper formatting

    • Supports extended m3u format with #EXTINF metadata
    • Handles duration conversion (milliseconds to seconds)
    • Provides custom path resolver support for flexibility
  • PlaylistExporter: Service class for handling export operations

    • Multiple export strategies: to URI, to directory, or generate content
    • Best-effort path resolution for content:// URIs
    • Robust error handling with detailed error messages
    • Uses Android Storage Access Framework for file operations

Repository Layer:

  • Added export methods to PlaylistRepository interface
  • Implemented in LocalPlaylistRepository with proper song retrieval

UI Layer:

  • Added "Export playlist" menu item to playlist detail screen
  • Integrated with Android's file picker using ActivityResultContracts
  • User-friendly success/error messages with localized strings
  • Export uses playlist name as default filename

Technical Approach:

  • Handles Android's content:// URI limitation by attempting to resolve real paths
  • Falls back to content URIs when real paths unavailable (known limitation)
  • Flexible path resolver allows callers to provide custom resolution logic
  • Comprehensive error handling for permissions, I/O, and invalid data

Testing:

  • Added comprehensive unit tests for M3uWriter covering:
    • Basic single/multiple song export
    • Null handling for artist/track names
    • Custom path resolvers
    • Duration conversion accuracy
    • M3u format structure validation

Addresses issue #112

timusus avatar Nov 16 '25 06:11 timusus