mangayomi/lib/services/anime_extractors/mytv_extractor.dart
kodjomoustapha b10c3f3a22 misc changes
- remove cronet_http & cupertino_http
- use rhttp package as default http client
- fix #198 #200 crashes on multiple downloads
- fix #162 #102 unable to download with forbidden characters in the name (as it is fixed this can cause reading problems concerning chapters downloaded before this version)
- now supports all features on all platforms such as VPNs and HTTP proxies thanks to rhttp package
2024-08-21 13:30:13 +01:00

42 lines
1.3 KiB
Dart

import 'package:html/parser.dart' show parse;
import 'package:http_interceptor/http_interceptor.dart';
import 'package:mangayomi/models/video.dart';
import 'package:mangayomi/services/http/m_client.dart';
import 'package:mangayomi/utils/extensions/string_extensions.dart';
class MytvExtractor {
final InterceptedClient client =
MClient.init(reqcopyWith: {'useDartHttpClient': true});
Future<List<Video>> videosFromUrl(String url) async {
try {
final response = await client.get(Uri.parse(url));
final document = parse(response.body);
final videoList = <Video>[];
document.querySelectorAll("script").forEach((script) {
if (script.text.contains("CreatePlayer(\"v")) {
final videosString = script.text;
final videoUrl = videosString
.substringAfter("\"v=")
.substringBefore("\\u0026tp=video")
.replaceAll("%26", "&")
.replaceAll("%3a", ":")
.replaceAll("%2f", "/")
.replaceAll("%3f", "?")
.replaceAll("%3d", "=");
if (!videoUrl.contains("https:")) {
videoList.add(Video(videoUrl, "Stream", videoUrl));
} else {
videoList.add(Video(videoUrl, "Mytv", videoUrl));
}
}
});
return videoList;
} catch (_) {
return [];
}
}
}