Skip to content

Conversation

@timusus
Copy link
Owner

@timusus timusus commented Nov 16, 2025

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

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
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.

3 participants