get static method
Implementation
static Future<List<DGDirectLinkModel>> get(String url) async {
final List<DGDirectLinkModel> links = [];
final Completer<List<DGDirectLinkModel>> c =
Completer<List<DGDirectLinkModel>>();
DGHubWebScrapper.getFromWebView(
url,
onLoaded: (controller, gurl) async {
try {
var htm = await controller.getHtml();
var document = parse(htm);
var script = document.body!.text;
//print(document.body);
if (script.contains("html5player.setVideoUrlLow")) {
List<String> lines = script.split("\n");
// print(lines.length);
await Future.wait(lines.map((line) async {
if (line.contains("html5player.setVideoUrlLow")) {
String lowQ = line
.replaceAll("html5player.setVideoUrlLow('", "")
.replaceAll("');", "");
//print(lowQ);
links.add(DGDirectLinkModel(quality: 'SD', link: lowQ));
}
}));
}
if (script.contains("html5player.setVideoUrlHigh")) {
List<String> lines = script.split("\n");
await Future.wait(lines.map((line) async {
if (line.contains("html5player.setVideoUrlHigh")) {
String highQ = line
.replaceAll("html5player.setVideoUrlHigh('", "")
.replaceAll("');", "");
links.add(DGDirectLinkModel(quality: 'HD', link: highQ));
c.complete(links);
}
}));
}
} catch (e) {
if (kDebugMode) {
print(e);
}
}
},
).then((value) {}).onError((error, stackTrace) {
// print(error.toString());
// print(stackTrace.toString());
});
return c.future;
}