audiobookshelf_api 0.2.0 copy "audiobookshelf_api: ^0.2.0" to clipboard
audiobookshelf_api: ^0.2.0 copied to clipboard

A Dart wrapper for the audiobookshelf API, a self-hosted audiobook and podcast server.

example/audiobookshelf_api_example.dart

import 'package:audiobookshelf_api/audiobookshelf_api.dart';

void main() async {
  final api = AudiobookshelfApi(baseUrl: Uri.https('abs.example.com'));

  final loginResponse =
      await api.login(username: 'username', password: 'password');
  if (loginResponse == null) {
    throw Exception('Error logging in');
  }

  // After logging in, the token is stored on the `AudiobookshelfApi` object and
  // can be used in the future to skip logging in:
  // `AudiobookshelfApi(baseUrl: Uri.https('abs.example.com'), token: token)`
  //
  // e.g. 'exJhbGciOiJI6IkpXVCJ9.eyJ1c2Vyi5NDEyODc4fQ.ZraBFohS4Tg39NszY'
  print(api.token);

  final getLibraryResponse = await api.libraries.get(
    libraryId: loginResponse.userDefaultLibraryId,
  );
  if (getLibraryResponse == null) {
    throw Exception('Error getting default library');
  }

  // e.g. 'Audiobooks'
  print(getLibraryResponse.library.name);

  // To use the socket, set up your callbacks and initialize it.
  final onInitSub = api.socket.miscEvents.onInit.listen((initEvent) {
    // e.g. 'username'
    print(initEvent.username);
  });
  api.socket.init();

  await onInitSub.cancel();

  // Make sure to dispose the `AudiobookshelfApi` instance  when done.
  api.dispose();
}
2
likes
120
pub points
0%
popularity

Publisher

unverified uploader

A Dart wrapper for the audiobookshelf API, a self-hosted audiobook and podcast server.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

freezed_annotation, http, http_parser, json_annotation, mime, socket_io_client

More

Packages that depend on audiobookshelf_api