tokybook 0.0.1 copy "tokybook: ^0.0.1" to clipboard
tokybook: ^0.0.1 copied to clipboard

An easy to use SDK for interacting with the Tokybook Service. It provides a simple interface for fetching and parsing audiobook data from the service

example/main.dart

import 'package:tokybook/tokybook.dart';

void main() async {
  final api = TokybookApi();

  // 1. Search for audiobooks
  final List<TokybookItem> results = await api.searchTitles(
    query: 'a very stalker',
  );

  // for (final result in results) {
  //   print('${result.title} - ${result.coverUrl}');
  // }

  // 2. Get details using the dynamicSlugId
  if (results.isNotEmpty && results.first.dynamicSlugId != null) {
    final TokybookItem details = await api.getInfo(
      results.first.dynamicSlugId!,
    );
    print('Title: ${details.title}');
    print('Authors: ${details.authors?.join(", ")}');
    print('Narrators: ${details.narrators?.join(", ")}');
    print('Duration: ${details.duration}');
    print('Rating: ${details.ratingValue} (${details.ratingCount} reviews)');

    // 3. Get playlist/tracks using audioBookId and postDetailToken
    if (details.audioBookId != null && details.postDetailToken != null) {
      final TokybookPlaylist playlist = await api.getPlaylist(
        audioBookId: details.audioBookId!,
        postDetailToken: details.postDetailToken!,
      );
      print('Playlist: ${playlist.bookTitle}');
      print('Tracks: ${playlist.tracks.length}');

      // 4. Get streaming info for a track (directly from playlist)
      if (playlist.tracks.isNotEmpty) {
        // // Option 1: Get by index
        final streamInfo = playlist.getStreamInfo(0);
        // print('Stream URL: ${streamInfo.url}');
        // print('Headers: ${streamInfo.headers}');

        // Option 2: Get for a specific track
        final track = playlist.tracks.first;
        final streamInfo2 = playlist.getStreamInfoForTrack(track);
        print('Same URL: ${streamInfo.url == streamInfo2.url}');

        // 5. Optionally fetch the m3u8 playlist content
        final m3u8Content = await api.getTrackPlaylist(
          track: track,
          playlist: playlist,
        );
        print(
          'M3U8 Content (first 200 chars): ${m3u8Content.substring(0, m3u8Content.length > 200 ? 200 : m3u8Content.length)}...',
        );
      }
    }
  }
}
0
likes
150
points
56
downloads

Publisher

verified publishertribestick.com

Weekly Downloads

An easy to use SDK for interacting with the Tokybook Service. It provides a simple interface for fetching and parsing audiobook data from the service

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

equatable, http

More

Packages that depend on tokybook