fetchConfig method

Future<void> fetchConfig()

Fetches the configuration data required for API requests.

Implementation

Future<void> fetchConfig() async {
  try {
    final response = await dio.get('/');
    final html = response.data;
    config['VISITOR_DATA'] = _extractValue(html, r'"VISITOR_DATA":"(.*?)"');
    config['INNERTUBE_CONTEXT_CLIENT_NAME'] = _extractValue(
        html, r'"INNERTUBE_CONTEXT_CLIENT_NAME":\s*(-?\d+|\"(.*?)\")');
    config['INNERTUBE_CLIENT_VERSION'] =
        _extractValue(html, r'"INNERTUBE_CLIENT_VERSION":"(.*?)"');
    config['DEVICE'] = _extractValue(html, r'"DEVICE":"(.*?)"');
    config['PAGE_CL'] =
        _extractValue(html, r'"PAGE_CL":\s*(-?\d+|\"(.*?)\")');
    config['PAGE_BUILD_LABEL'] =
        _extractValue(html, r'"PAGE_BUILD_LABEL":"(.*?)"');
    config['INNERTUBE_API_KEY'] =
        _extractValue(html, r'"INNERTUBE_API_KEY":"(.*?)"');
    config['INNERTUBE_API_VERSION'] =
        _extractValue(html, r'"INNERTUBE_API_VERSION":"(.*?)"');
    config['INNERTUBE_CLIENT_NAME'] =
        _extractValue(html, r'"INNERTUBE_CLIENT_NAME":"(.*?)"');
    config['GL'] = _extractValue(html, r'"GL":"(.*?)"');
    config['HL'] = _extractValue(html, r'"HL":"(.*?)"');
  } catch (e) {
    print('Error fetching data: ${e.toString()}');
  }
}