diff --git a/.gitignore b/.gitignore index a67ef55..67b0e47 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,6 @@ app.*.map.json /android/app/release samples/ -apps_logs.txt \ No newline at end of file +apps_logs.txt +windows/out/build/ +.vs/ diff --git a/assets/executable/ffmpeg.exe b/assets/executable/ffmpeg.exe new file mode 100644 index 0000000..f4da16d Binary files /dev/null and b/assets/executable/ffmpeg.exe differ diff --git a/lib/services/download.dart b/lib/services/download.dart index c605555..253d614 100644 --- a/lib/services/download.dart +++ b/lib/services/download.dart @@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:get/get_navigation/src/nav2/get_router_delegate.dart'; import 'package:logger/logger.dart'; +import 'package:path/path.dart'; import 'package:notube/constants.dart'; import 'package:notube/models/video.dart'; import 'package:notube/services/file_logger.dart'; @@ -38,6 +39,7 @@ class DLServices { Future _init() async { tempDir = await getTemporaryDirectory(); if (Platform.isWindows) { + checkFFmpeg(); assetName = 'yt-dlp.exe'; } else if (Platform.isLinux) { checkFFmpeg(); @@ -68,9 +70,7 @@ class DLServices { } var shell = Shell(); - await shell.run( - '$ytDlpPath -U' - ); + await shell.run('$ytDlpPath -U'); // await Process.run(ytDlpPath, ['-U']) } @@ -93,52 +93,52 @@ class DLServices { ) { completer.completeError(error); }); - } catch(error) { + } catch (error) { completer.completeError(error); } } - Future checkFFmpeg() async { var result = await futureShell('ffmpeg -version'); debugPrint('$result'); - /* - try { - var result = await Process.run('ffmpeg', ['-version']); if (result.exitCode == 0) { print('FFmpeg is already installed.'); return; } - + debugPrint('RESULTS: $result'); - result = await Process.run('sudo', ['-n', 'true']); - bool hasSudo = result.exitCode == 0; - - if (hasSudo) { - print('Installing FFmpeg...'); - if (Platform.isLinux) { + print('Installing FFmpeg...'); + if (Platform.isLinux) { + result = await Process.run('sudo', ['-n', 'true']); + bool hasSudo = result.exitCode == 0; + if (hasSudo) { result = await Process.run('sudo', ['apt-get', 'install', 'ffmpeg', '-y']); - } else if (Platform.isMacOS) { - result = await Process.run('brew', ['install', 'ffmpeg']); + } else { + print('Cannot install FFmpeg without sudo privileges.'); } if (result.exitCode == 0) { print('FFmpeg installed successfully.'); } else { print('Error installing FFmpeg: ${result.stderr}'); } - } else { - print('Cannot install FFmpeg without sudo privileges.'); - // Here, you might want to inform the user they need to manually install FFmpeg + } else if (Platform.isMacOS) { + result = await Process.run('brew', ['install', 'ffmpeg']); + } else if (Platform.isWindows) { + Directory directory = await getApplicationDocumentsDirectory(); + String assetsPath = join(directory.path, 'assets'); + result = await Process.run('setx', [ + 'PATH', + '$assetsPath;%PATH%', + ]); } } catch (e) { print('An error occurred: $e'); } - */ } Future downloadFile(Video video) async {