parse method

Future<Map<String, Video>>? parse(
  1. String link, [
  2. bool mp4 = false
])

Implementation

Future<Map<String, Video>>? parse(String link, [bool mp4 = false]) async {
  if (Detect().validate(link, "kodik")) {
    final data = await _parsePlayer(link);
    final domain = RegExp(
            r"(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]")
        .stringMatch(link);
    final res = await _dio.post(
      "https://$domain${await _getActualAPIEndpoint(data[1], domain.toString())}",
      data: FormData.fromMap(data[0]),
      options: Options(headers: {
        "origin": "https://kodik.info",
        "accept": "application/json, text/javascript, */*; q=0.01",
        "referer": "https://$domain",
        ...randomUserAgent(),
        'x-requested-with': 'XMLHttpRequest'
      }),
    );
    if (res.statusCode == 200) {
      final links = res.data["links"];
      if (!mp4) {
        return {
          "360": Video(360, "m3u8",
              "https:${_decodeUrl(links["360"][0]["src"])}", null),
          "480": Video(480, "m3u8",
              "https:${_decodeUrl(links["480"][0]["src"])}", null),
          "720": Video(720, "m3u8",
              "https:${_decodeUrl(links["720"][0]["src"])}", null)
        };
      } else {
        return {
          "360": Video(
              360,
              "mp4",
              "https:${_decodeUrl(links["360"][0]["src"]).replaceAll(":hls:manifest.m3u8", "")}",
              null),
          "480": Video(
              480,
              "mp4",
              "https:${_decodeUrl(links["480"][0]["src"]).replaceAll(":hls:manifest.m3u8", "")}",
              null),
          "720": Video(
              720,
              "mp4",
              "https:${_decodeUrl(links["720"][0]["src"]).replaceAll(":hls:manifest.m3u8", "")}",
              null)
        };
      }
    } else {
      throw Exception("Link decode error.");
    }
  } else {
    throw BadDataException("Bad url!");
  }
}