From f8a8f64a144b8e2fcefac4803d7980a16108466b Mon Sep 17 00:00:00 2001 From: macOsScaleway-vscode Date: Fri, 13 Sep 2024 10:52:34 +0200 Subject: [PATCH] [macos] install script --- lib/services/download.dart | 23 +++++++++++++++++------ lib/videoList/cubit/videos_cubit.dart | 4 ++-- macos/Runner.xcodeproj/project.pbxproj | 2 +- macos/Runner/AppDelegate.swift | 14 ++++++++++++++ macos/notube-macos-install.sh | 5 +++++ 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 macos/notube-macos-install.sh diff --git a/lib/services/download.dart b/lib/services/download.dart index 48a7729..2fef233 100644 --- a/lib/services/download.dart +++ b/lib/services/download.dart @@ -41,14 +41,15 @@ class DLServices { if (Platform.isWindows) { //checkFFmpeg(); assetName = 'yt-dlp.exe'; + await copyExecutable(); } else if (Platform.isLinux) { checkFFmpeg(); assetName = 'yt-dlp_linux'; } else if (Platform.isMacOS) { checkFFmpeg(); assetName = 'yt-dlp_macos'; + ytDlpPath = "yt-dlp"; } - await copyExecutable(); } Future copyExecutable() async { @@ -79,8 +80,7 @@ class DLServices { var completer = Completer(); try { shell.run(cmd).then((result) { - FileLogger().d('FFmpeg is already installed.'); - completer.complete(true); + completer.complete(result); result.map((e) { FileLogger().d('Analyse result: $e'); FileLogger().d('Analyse result: ${e.toString()}'); @@ -96,12 +96,13 @@ class DLServices { } catch (error) { completer.completeError(error); } + return completer.future; } Future checkFFmpeg() async { var result = await futureShell('ffmpeg -version'); - FileLogger().d('$result'); - if (result != null && result.exitCode == 0) { + //FileLogger().d('$result'); + if (result != null) { FileLogger().d('FFmpeg is already installed.'); return; } @@ -123,6 +124,14 @@ class DLServices { FileLogger().d('Error installing FFmpeg: ${result.stderr}'); } } else if (Platform.isMacOS) { + var homebrewTest = await futureShell("brew --version"); + FileLogger().d('$homebrewTest'); + if (result == null) { + FileLogger().d('Install homebrew'); + var installHomebrew = await futureShell('/bin/bash -c "\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'); + FileLogger().d('$installHomebrew'); + } + result = await Process.run('brew', ['install', 'ffmpeg']); } else if (Platform.isWindows) { Directory directory = await getApplicationDocumentsDirectory(); @@ -195,7 +204,7 @@ class DLServices { Future analyseUrl(String url) async { FileLogger().d('Analyse $url'); - var command = '${url.trim()} -q --flat-playlist -J'; + var command = '${'"'}${url.trim()}${'"'} -q --flat-playlist -J'; var shellLinesController = ShellLinesController(); var shellErrorController = ShellLinesController(); @@ -210,6 +219,8 @@ class DLServices { stderr: shellErrorController.sink, verbose: false); + FileLogger().d('''$ytDlpPath $command'''); + await shell.run(''' $ytDlpPath $command ''').then((result) { diff --git a/lib/videoList/cubit/videos_cubit.dart b/lib/videoList/cubit/videos_cubit.dart index 91d9c93..0f7e725 100644 --- a/lib/videoList/cubit/videos_cubit.dart +++ b/lib/videoList/cubit/videos_cubit.dart @@ -120,8 +120,8 @@ class VideosCubit extends Cubit { await moveVideos(); - final Directory directory = Directory('temp'); - final List files = directory.listSync(); + //final Directory directory = Directory('temp'); + final List files = tempDir.listSync(); for (FileSystemEntity file in files) { final String dirFilename = p.basenameWithoutExtension(file.path); if (dirFilename.contains('_tmp')) { diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index f0692e4..a2940db 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 60; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index 8e02df2..27f2697 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -6,4 +6,18 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationDidFinishLaunching(_ notification: Notification) { + super.applicationDidFinishLaunching(notification) + runInstallScript() + } + + func runInstallScript() { + let scriptPath = Bundle.main.path(forResource: "notube-macos-install", ofType: "sh") + let task = Process() + task.launchPath = "/bin/bash" + task.arguments = [scriptPath!] + task.launch() + task.waitUntilExit() + } } diff --git a/macos/notube-macos-install.sh b/macos/notube-macos-install.sh new file mode 100644 index 0000000..f083c1b --- /dev/null +++ b/macos/notube-macos-install.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +brew install ffmpeg +brew install yt-dlp \ No newline at end of file