getVideoInfo method

Future<void> getVideoInfo(
  1. String videoId
)

Implementation

Future<void> getVideoInfo(String videoId) async {
  try {
    final response = await get(
      Uri.parse(
        "https://cdn34.savetube.me/info?url=https://www.youtube.com/watch?v=$videoId",
      ),
    );
    if (response.statusCode == 200) {
      List<String> qualities = [];
      List formats =
          (jsonDecode(response.body)['data']['video_formats'] as List);
      qualities.addAll(formats
          .where((e) => e['quality'] != 360)
          .toList()
          .map((e) => e['quality'].toString()));
      final key = jsonDecode(response.body)['data']['key'];
      if (qualities.isNotEmpty) {
        for (var element in qualities) {
          final url = await getDownloadUrl(
            url: "https://cdn35.savetube.me/download/video/$element/$key",
          );
          if (url != null) {
            videosList.add(
              VideoData(
                url: url,
                quality: "${element}p",
                format: "mp4",
                size: "0",
              ),
            );
          }
        }
        videosList.refresh();
      }
      sortByQuality();
    }
  } catch (e) {
    log("Error $e");
  }
}