loadTracks method

Future<LoadResult> loadTracks(
  1. String identifier
)

Load tracks by identifier

identifier can be:

Implementation

Future<LoadResult> loadTracks(String identifier) async {
  LavalinkLogger.debug('Loading tracks: $identifier', tag: 'REST');

  try {
    final uri = Uri.parse('$baseUrl/v4/loadtracks')
        .replace(queryParameters: {'identifier': identifier});

    final request = await _httpClient.getUrl(uri);
    _addHeaders(request);

    final response = await request.close();
    final responseBody = await _readResponse(response);

    if (response.statusCode != 200) {
      throw LavalinkException(
        'Failed to load tracks: ${response.statusCode}',
        statusCode: response.statusCode,
      );
    }

    final json = jsonDecode(responseBody) as Map<String, dynamic>;
    final result = LoadResult.fromJson(json);

    LavalinkLogger.debug(
      'Loaded ${result.tracks?.length ?? 0} tracks',
      tag: 'REST',
    );

    return result;
  } on TimeoutException {
    throw LavalinkTimeoutException('Request timed out');
  } on SocketException catch (e) {
    throw LavalinkConnectionException(
      'Failed to connect to Lavalink server',
      cause: e,
    );
  } catch (e) {
    if (e is LavalinkException) rethrow;
    throw LavalinkException('Unexpected error: $e', cause: e);
  }
}