get static method

Future<List<DGDirectLinkModel>> get(
  1. String url,
  2. bool debugMode
)

Implementation

static Future<List<DGDirectLinkModel>> get(String url,bool debugMode) async {

 final List<DGDirectLinkModel> links = [];
  final Completer<List<DGDirectLinkModel>> c = Completer<List<DGDirectLinkModel>>();
  HeadlessInAppWebView(
    initialUrlRequest: URLRequest(
        url: Uri.parse('https://en.savefrom.net')),
    onLoadStop: (controller, url) async {
      await controller.evaluateJavascript(source: '''
document.querySelector('#sf_url').value = '$url'
document.querySelector('#sf_submit').click()
''');
      var data = await Future.delayed(const Duration(seconds: 3), () async {
        var htm = await controller.getHtml();
        var document = parse(htm);

        try {
          String? thumbnail = document
              .querySelector("media-result clip img")
              ?.attributes['src'];

          var info = document.querySelector("info-box");
          List<dom.Element> linkGroup = [
            ...info!.querySelectorAll("link-group a")
          ];

          linkGroup.map((element) {
            String? href = element.attributes['href'];
            String? text = element.text;
          print(href.toString());

          links.add(DGDirectLinkModel(
                quality: text.toString(), link: href.toString()));
            c.complete(links);
          }).toList();
        } catch (e) {
          print('Error social:'+e.toString());
        }

      });
    },
  )
    ..run()
    ..dispose();

    return c.future;
}