getMetadata static method

Future<Metadata?> getMetadata({
  1. required String link,
  2. String? proxyUrl = '',
  3. Duration? cache = const Duration(days: 1),
  4. Map<String, String>? headers,
  5. String? userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
})

Method to fetch metadata directly

Implementation

static Future<Metadata?> getMetadata({
  required String link,
  String? proxyUrl = '', // Pass for web
  Duration? cache = const Duration(days: 1),
  Map<String, String>? headers,
  String? userAgent =
      'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
}) async {
  final linkValid = isValidLink(link);
  if (linkValid) {
    // removing www. from the link if available
    if (link.startsWith('www.')) link = link.replaceFirst('www.', '');
    return _getMetadata(
      link,
      cache: cache,
      headers: headers ?? {},
      userAgent: userAgent,
    );
  } else if (!linkValid) {
    throw Exception('Invalid link');
  } else {
    throw Exception('Proxy URL is invalid. Kindly pass only if required');
  }
}