notube-export/lib/states/dlFormState.dart

52 lines
1.3 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:process_run/shell.dart';
class DlFormState extends ChangeNotifier {
String url = '';
String format = 'MP3';
void setUrl(String newUrl) {
url = newUrl;
notifyListeners();
}
void setFormat(String newFormat) {
format = newFormat;
notifyListeners();
}
Future<void> download() async {
debugPrint('Downloading $url in $format format');
Directory tempDir = await getTemporaryDirectory();
String assetName = 'yt-dlp.exe';
File tempFile = File('${tempDir.path}/$assetName');
ByteData data = await rootBundle.load('assets/executable/$assetName');
await tempFile.exists().then((value) {
if (!value) {
debugPrint('Copying $assetName to ${tempFile.path}');
tempFile.writeAsBytes(
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
}
});
var ytDlpPath = tempFile.path;
var command =
'${url.trim()} --sub-langs "all,-live_chat" --embed-subs --embed-thumbnail --embed-metadata --output temp.mp4';
var shell = Shell();
debugPrint('Running $ytDlpPath $command');
var results = await shell.run('''
dir
$ytDlpPath $command
''');
}
}