deleteCachedVideos method
Implementation
Future<List<Map<String, dynamic>>> deleteCachedVideos({
List<String>? videoNames,
required bool mode,
required List<String> identifiers,
}) async {
final dir = await _containerParseSetTitleBlur();
final fm = Directory(dir);
final allFiles = await fm
.list()
.map((e) => e.path.split('/').last)
.toList();
allFiles.where((f) => f.endsWith(".mp4")).toList();
if (mode) {
if (await fm.exists()) {
await fm.delete(recursive: true);
}
await Directory(dir).create(recursive: true);
} else {
for (final id in identifiers) {
final targetFile = "$id.mp4";
final filePath = "$dir/$targetFile";
final file = File(filePath);
if (await file.exists()) {
await file.delete();
}
}
}
final remaining = await Directory(
dir,
).list().map((e) => e.path.split('/').last).toList();
remaining.where((f) => f.endsWith(".mp4")).toList();
List<Map<String, dynamic>> resultArray = [];
if (videoNames != null) {
for (int i = 0; i < videoNames.length; i++) {
final fileName = videoNames[i];
final uuid = (identifiers.isNotEmpty && i < identifiers.length)
? identifiers[i]
: i;
resultArray.add({
"${getRandomString()}ul": fileName,
"${getRandomString()}ud": uuid,
});
}
}
return resultArray;
}