sendPost method

Future<JsonMap> sendPost(
  1. String action,
  2. Map<String, dynamic> data, {
  3. Map<String, String>? headers,
})

Sends a call to the youtube api endpoint.

Implementation

Future<JsonMap> sendPost(String action, Map<String, dynamic> data,
    {Map<String, String>? headers}) {
  assert(action == 'next' || action == 'browse' || action == 'search');

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

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

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

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