diff --git a/lib/services/download.dart b/lib/services/download.dart index 62bf382..021826d 100644 --- a/lib/services/download.dart +++ b/lib/services/download.dart @@ -39,6 +39,7 @@ class DLServices { if (Platform.isWindows) { assetName = 'yt-dlp.exe'; } else if (Platform.isLinux) { + checkFFmpeg(); assetName = 'yt-dlp_linux'; } else if (Platform.isMacOS) { assetName = 'yt-dlp_macos'; @@ -65,6 +66,35 @@ class DLServices { } } + Future checkFFmpeg() async { + try { + var result = await Process.run('ffmpeg', ['-version']); + if (result.exitCode == 0) { + print('FFmpeg is already installed.'); + return; + } + + result = await Process.run('sudo', ['-n', 'true']); + bool hasSudo = result.exitCode == 0; + + if (hasSudo) { + print('Installing FFmpeg...'); + result = + await Process.run('sudo', ['apt-get', 'install', 'ffmpeg', '-y']); + 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 + } + } catch (e) { + print('An error occurred: $e'); + } + } + Future downloadFile(Video video) async { debugPrint( 'Downloading $url in ${video.format.format} format (${video.filename})'); @@ -131,23 +161,12 @@ class DLServices { ) { if (error is ShellException) { debugPrint('ShellException: ${error.message}'); - FileLogger().e('ShellException: ${error.message}'); + FileLogger().e('ShellException error: ${error.result?.stderr}'); + FileLogger().e('ShellException out: ${error.result?.stdout}'); } else { debugPrint('Error: $error'); FileLogger().e('Error: $error'); } - if (stackTrace != null) { - debugPrint('Stacktrace: $stackTrace'); - FileLogger().e('Stacktrace: $stackTrace'); - } - if (error.map) { - error.map((e) { - debugPrint('Analyse result: $e'); - FileLogger().d('Analyse result: ${e.toString()}'); - FileLogger().d('stdout: ${e.stdout}'); - FileLogger().d('stderr: ${e.stderr}'); - }); - } }); return shellLinesController.stream;