getSignatureTimestamp method

Future<int> getSignatureTimestamp({
  1. String? url,
})

Fetch the base.js script from YouTube Music and parse out the signatureTimestamp for use with getSong.

  • url Optional. Provide the URL of the base.js script. If this isn't specified, a call will be made to getBaseJsUrl.

Returns signatureTimestamp String.

Implementation

Future<int> getSignatureTimestamp({String? url}) async {
  url ??= await getBaseJsUrl();
  final response = await sendGetRequest(url);
  final match = RegExp(
    r'signatureTimestamp[:=](\d+)',
  ).firstMatch(decodeEscapes(response.data as String));
  if (match == null) {
    throw Exception('Unable to identify the signatureTimestamp.');
  }
  return int.parse(match.group(1)!);
}