sendPost method

Future<JsonMap> sendPost(
  1. String action,
  2. String token
)

Sends a call to the youtube api endpoint.

Implementation

Future<JsonMap> sendPost(String action, String token) async {
  assert(action == 'next' || action == 'browse' || action == 'search');

  final body = {
    'context': const {
      'client': {
        'browserName': 'Chrome',
        'browserVersion': '105.0.0.0',
        'clientFormFactor': 'UNKNOWN_FORM_FACTOR',
        'clientName': "WEB",
        'clientVersion': "2.20220921.00.00"
      }
    },
    'continuation': token
  };

  final url = Uri.parse(
      'https://www.youtube.com/youtubei/v1/$action?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8');

  return retry<JsonMap>(this, () async {
    final raw = await post(url, body: json.encode(body));
    if (_closed) throw HttpClientClosedException();

    //final now = DateTime.now();
    //_log(raw.body,
    //    '${now.minute}.${now.second}.${now.millisecond}-$action-POST');
    return json.decode(raw.body);
  });
}