SwiftShelf: A tvOS Client for Audiobookshelf
SwiftShelf is a tvOS client designed for Audiobookshelf, leveraging SwiftUI to provide a seamless and engaging interface for audiobook management. The emphasis on authenticated playback ensures a secure and user-friendly experience, allowing users to navigate their libraries efficiently. The architecture is built around a clean API interaction model using Bearer authentication, focusing on performance and responsiveness in a tvOS environment.
Architecture/Technical Overview
At its core, SwiftShelf employs a client-server model where it communicates with the Audiobookshelf API to fetch audiobooks and user data. The app is designed for concurrent operations, allowing multiple API requests to be processed simultaneously while maintaining a responsive UI. The in-memory caching for cover images enhances performance by reducing load times during browsing.
Key architectural decisions include:
- Utilizing SwiftUI for the user interface to take full advantage of declarative programming, which simplifies UI updates and state management.
- Implementing a carousel interface that is optimized for focus-aware navigation, catering to the unique requirements of tvOS.
- Adopting a persistent user configuration that remembers the last selected library to streamline the user experience.
Technical Stack
Backend:
- Language: Swift
- Framework: SwiftUI
- Concurrency Model: Asynchronous API calls using Swift’s Combine framework.
API:
- Endpoints:
POST /login: Authenticates a user with host and API key.GET /libraries: Retrieves a list of available Audiobookshelf libraries.GET /cover: Fetches cover images for audiobooks using Bearer authentication.
Frontend:
- UI Technologies: SwiftUI for a responsive design that takes advantage of tvOS features.
- Real-time updates: Leveraging Combine to handle updates from the API asynchronously.
Database/Storage:
- No persistent storage is used beyond runtime memory; all state management is handled in-memory, providing a fast and fluid user experience.
Implementation Details
Configuration is straightforward, requiring only the following parameters:
host: "https://library.example.net"
apiKey: "your_api_key_here"
One critical technical challenge was ensuring secure API communication. This is addressed by storing sensitive information only in runtime memory, with all API requests using Bearer tokens, which eliminates risks associated with persistent storage.
Integration points with the Audiobookshelf API are streamlined, ensuring that all relevant data (like audiobooks and cover images) is fetched on-demand, enhancing both the performance and security of the application.
Deployment/Setup Section
SwiftShelf can be deployed on any tvOS simulator or device. To get started, simply clone the repository and follow these commands:
git clone https://github.com/michaeldvinci/SwiftShelf-tvOS.git
cd SwiftShelf-tvOS
open SwiftShelf.xcodeproj
Ensure you input valid credentials in the configuration file. There are no default credentials; users must provide their own Audiobookshelf host and API key.
For a complete view of the project, check out the GitHub repository: SwiftShelf-tvOS.
Future Work
- Enhance the media player integration to support more formats and streaming options.
- Implement offline access for previously fetched audiobooks.
- Add user preferences for sorting and filtering audiobooks more effectively.
- Improve accessibility features for a broader range of users.