Compare commits

...

10 Commits

Author SHA1 Message Date
jscampucci f4940b189d [clean] macos install 2024-10-11 10:00:25 +02:00
macOsScaleway-vscode a81d34cf82 [macos] install script 2024-09-13 10:52:34 +02:00
macOsScaleway-vscode f6c48354f0 [macos] migrate xcode 2024-09-09 13:50:25 +02:00
jscampucci 53096d9c0a [win] add phantomjs debug 2024-09-05 10:16:01 +02:00
jscampucci 0ede898b5a [macos] xcode 9.3 -> 15.0 2024-09-05 10:15:23 +02:00
jscampucci 0702774345 [convert] clean conversion 2024-08-27 16:41:28 +02:00
jscampucci 2d4fb0253b [setup] clean env 2024-08-27 16:41:07 +02:00
jscampucci 2c5088dd2f [audio] manage audio download 2024-08-27 16:40:51 +02:00
jscampucci c14d38866e [setup] installer & external ffmpeg 2024-08-26 10:20:18 +02:00
jscampucci 9070349c83 [ffmpeg] clean linux install 2024-08-15 16:10:41 +02:00
14 changed files with 264 additions and 63 deletions

Binary file not shown.

0
assets/executable/yt-dlp_macos Normal file → Executable file
View File

View File

@ -11,12 +11,12 @@ enum Format {
mp3(
format: 'MP3',
ytCmd: 'bestaudio[ext=m4a]/bestaudio[ext=webm]',
ffmpegCmd: '-f mp3 -loglevel quiet -ab 192k -vn',
ffmpegCmd: '-f mp3 -ab 192k -vn',
extension: 'mp3'),
mp3HD(
format: 'MP3 HD',
ytCmd: 'bestaudio[ext=m4a]/bestaudio[ext=webm]',
ffmpegCmd: '-f mp3 -loglevel quiet -ab 320k -vn',
ffmpegCmd: '-f mp3 -ab 320k -vn',
extension: 'mp3'),
mp4(format: 'MP4'),
mp4HD(
@ -64,3 +64,9 @@ const convertedFormats = [
Format.tGP,
Format.flv,
];
const audioFormats = [
Format.m4a,
Format.mp3,
Format.mp3HD,
];

View File

@ -19,6 +19,7 @@ class Video extends Equatable {
this.uploadDate = '',
this.filename = '',
this.playlistTitle = '',
this.destination = '',
});
final String id;
@ -35,6 +36,7 @@ class Video extends Equatable {
final String uploadDate;
final String filename;
final String playlistTitle;
final String destination;
factory Video.fromJson(Map<String, dynamic> json) {
return Video(
@ -66,6 +68,7 @@ class Video extends Equatable {
String? uploadDate,
String? filename,
String? playlistTitle,
String? destination,
}) {
return Video(
id: id ?? this.id,
@ -82,6 +85,7 @@ class Video extends Equatable {
uploadDate: uploadDate ?? this.uploadDate,
filename: filename ?? this.filename,
playlistTitle: playlistTitle ?? this.playlistTitle,
destination: destination ?? this.destination,
);
}
@ -100,5 +104,6 @@ class Video extends Equatable {
isParsed,
filename,
playlistTitle,
destination
];
}

View File

@ -31,19 +31,6 @@ class ConverterService {
} else if (Platform.isMacOS) {
ffmpegPath = 'ffmpeg';
}
await checkFFmpeg();
}
Future<void> checkFFmpeg() async {
try {
var result = await Process.run(ffmpegPath, ['-version']);
if (result.exitCode == 0) {
FileLogger().d('FFmpeg is installed.');
return;
}
} catch (e) {
FileLogger().d('FFmpeg is not installed.');
}
}
Future<File?> getTmpFile(String filename) async {
@ -54,6 +41,7 @@ class ConverterService {
FileLogger().d('dirFilename $dirFilename');
FileLogger().d('filename $filename');
if (dirFilename == '${filename}_tmp') {
FileLogger().d('Found tmp file ${file.path}');
return File(file.path);
}
}
@ -64,29 +52,39 @@ class ConverterService {
FileLogger().d(
'____Converting ${video.title} to ${video.format.format} format_____');
File tmpFile = File('temp/${video.filename}_tmp.mp4');
if (!tmpFile.existsSync()) {
tmpFile = await getTmpFile(video.filename) ??
File('temp/${video.filename}_tmp.mp4');
File tmpFile = File('${tempDir.path}/${video.filename}_tmp.mp4');
var dlFileExist = await tmpFile.exists();
FileLogger().d('dlFileExist: $dlFileExist');
if (!dlFileExist) {
FileLogger()
.d('File not found, testing destination ${video.destination}');
if (video.destination != '') {
tmpFile = File('${tempDir.path}/${video.destination}');
}
if (!tmpFile.existsSync()) {
FileLogger().d('File not found, testing temp directory');
tmpFile = await getTmpFile(video.filename) ??
File('${tempDir.path}/${video.filename}_tmp.mp4');
}
}
FileLogger().d('tmpFile: ${tmpFile.path}');
File doneFile =
File('temp/${video.filename}_done.${video.format.extension}');
File doneFile = File(
'${tempDir.path}/${video.filename}_done.${video.format.extension}');
if (doneFile.existsSync()) {
FileLogger().d('File already converted');
return Stream.fromIterable(['progress=end']);
}
var command =
'-i "${tmpFile.path}" ${video.format.ffmpegCmd} "temp/${video.filename}_done.${video.format.extension}"';
"-i '${tmpFile.path}' ${video.format.ffmpegCmd} '${tempDir.path}/${video.filename}_done.${video.format.extension}'";
var shellLinesController = ShellLinesController();
var shell = Shell(
stdout: shellLinesController.sink, stderr: shellLinesController.sink);
await shell.run('''
$ffmpegPath $command
''');
FileLogger().d('Running $ffmpegPath $command');
await shell.run("$ffmpegPath $command");
return shellLinesController.stream;
}

View File

@ -39,16 +39,17 @@ class DLServices {
Future<void> _init() async {
tempDir = await getTemporaryDirectory();
if (Platform.isWindows) {
checkFFmpeg();
//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<void> 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,19 +96,18 @@ class DLServices {
} catch (error) {
completer.completeError(error);
}
return completer.future;
}
Future<void> checkFFmpeg() async {
var result = await futureShell('ffmpeg -version');
//FileLogger().d('$result');
if (result != null) {
FileLogger().d('FFmpeg is already installed.');
return;
}
try {
var result = await Process.run('ffmpeg', ['-version']);
FileLogger().d('$result');
if (result.exitCode == 0) {
FileLogger().d('FFmpeg is already installed.');
return;
}
FileLogger().d('RESULTS: $result');
FileLogger().d('Installing FFmpeg...');
if (Platform.isLinux) {
result = await Process.run('sudo', ['-n', 'true']);
@ -125,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();
@ -153,16 +160,17 @@ class DLServices {
Format.values.firstWhere((e) => e.format == video.format.format).ytCmd;
FileLogger().d('Format code: $formatCmd');
File doneFile = File('temp/${video.filename}_tmp.mp4');
File doneFile = File('${tempDir.path}/${video.filename}_tmp.mp4');
if (doneFile.existsSync()) {
FileLogger().d('File already downloaded');
return Stream.fromIterable(['[EmbedThumbnail]']);
}
var strType = convertedFormats.contains(video.format) ? 'tmp' : 'done';
var isAudio = audioFormats.contains(video.format);
var command =
'${video.url.trim()} --sub-langs "all,-live_chat" --embed-subs --embed-thumbnail --embed-metadata --progress -o "temp/${video.filename}_$strType.%(ext)s" -f "$formatCmd"';
'${video.url.trim()}${isAudio ? '' : '--embed-subs --embed-thumbnail --embed-metadata'} --progress -o "${tempDir.path}/${video.filename}_$strType.%(ext)s" -f "$formatCmd"';
//--sub-langs "all,-live_chat"
var shellLinesController = ShellLinesController();
var shellErrorController = ShellLinesController();
@ -186,7 +194,6 @@ class DLServices {
FileLogger().e('ShellException error: ${error.result?.stderr}');
FileLogger().e('ShellException out: ${error.result?.stdout}');
} else {
FileLogger().d('Error: $error');
FileLogger().e('Error: $error');
}
});
@ -197,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();
@ -212,6 +219,8 @@ class DLServices {
stderr: shellErrorController.sink,
verbose: false);
FileLogger().d('''$ytDlpPath $command''');
await shell.run('''
$ytDlpPath $command
''').then((result) {

View File

@ -7,6 +7,7 @@ class FileLogger {
static final FileLogger _instance = FileLogger._internal();
late Logger _logger;
late File _logFile;
late Directory tempDir;
factory FileLogger() {
return _instance;
@ -15,7 +16,8 @@ class FileLogger {
FileLogger._internal();
Future<void> init() async {
_logFile = File('apps_logs.txt');
tempDir = await getTemporaryDirectory();
_logFile = File('${tempDir.path}/apps_logs.txt');
_logger = Logger(
filter: ProductionFilter(),
@ -30,6 +32,7 @@ class FileLogger {
}
void i(String message) {
debugPrint(message);
_logger.i(message);
}
@ -39,6 +42,7 @@ class FileLogger {
}
void e(String message, [dynamic error, StackTrace? stackTrace]) {
debugPrint(message);
_logger.e(message, error: error, stackTrace: stackTrace);
}

View File

@ -7,6 +7,7 @@ import 'package:notube/models/video.dart';
import 'package:notube/services/converter.dart';
import 'package:notube/services/download.dart';
import 'package:notube/constants.dart';
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:downloadsfolder/downloadsfolder.dart';
import 'package:path/path.dart' as p;
@ -19,6 +20,7 @@ class VideosCubit extends Cubit<VideosState> {
late DLServices dlService;
late ConverterService converterService;
late Directory tempDir;
Iterable<Video> downloadingVid = [];
@ -47,6 +49,22 @@ class VideosCubit extends Cubit<VideosState> {
return completer.future;
}
Future changeDestination(Video video, String destination) async {
var completer = Completer<void>();
var tmpVideoList = state.videoList.toList();
int index = tmpVideoList.indexWhere((v) => v.id == video.id);
if (index != -1) {
tmpVideoList[index] = video.copyWith(destination: destination);
emit(VideosState(videoList: tmpVideoList));
completer.complete(tmpVideoList[index]);
} else {
FileLogger().d('Video not found in the list');
completer.completeError('Video not found in the list');
}
return completer.future;
}
void setGlobalStatus(String status) {
emit(VideosState(status: status));
}
@ -71,6 +89,7 @@ class VideosCubit extends Cubit<VideosState> {
}
Future<void> startConverter() async {
tempDir = await getTemporaryDirectory();
var videosToConvert = state.videoList.where((video) =>
video.status == 'downloaded' &&
convertedFormats.contains(video.format));
@ -101,8 +120,8 @@ class VideosCubit extends Cubit<VideosState> {
await moveVideos();
final Directory directory = Directory('temp');
final List<FileSystemEntity> files = directory.listSync();
//final Directory directory = Directory('temp');
final List<FileSystemEntity> files = tempDir.listSync();
for (FileSystemEntity file in files) {
final String dirFilename = p.basenameWithoutExtension(file.path);
if (dirFilename.contains('_tmp')) {
@ -127,15 +146,15 @@ class VideosCubit extends Cubit<VideosState> {
for (Video video in state.videoList.where((video) =>
video.status == 'downloaded' || video.status == 'converted')) {
var cleanTitle = video.title.replaceAll(RegExp(r'[^\w\s]+'), '');
final tmpFile =
File('temp/${video.filename}_done.${video.format.extension}');
final tmpFile = File(
'${tempDir.path}/${video.filename}_done.${video.format.extension}');
var playlistTitle = video.playlistTitle;
await Directory('${downloadDirectory.path}/$playlistTitle')
.create(recursive: true)
.catchError((e) => FileLogger().e('Error creating directory: $e'));
FileLogger().d('Playlist title: $playlistTitle');
if (playlistTitle.isNotEmpty && playlistTitle != '') {
await Directory('${downloadDirectory.path}/$playlistTitle')
.create(recursive: true)
.catchError((e) => FileLogger().e('Error creating directory: $e'));
FileLogger().d('Playlist title: $playlistTitle');
cleanTitle = '$playlistTitle/$cleanTitle';
}
@ -145,6 +164,7 @@ class VideosCubit extends Cubit<VideosState> {
var isMoved = false;
while (!isMoved) {
try {
FileLogger().d('Moving ${tmpFile.path} to ${newFile.path}');
await tmpFile.rename(newFile.path);
isMoved = true;
} on FileSystemException catch (e) {
@ -152,9 +172,10 @@ class VideosCubit extends Cubit<VideosState> {
await Future.delayed(Duration(seconds: 1));
}
}
FileLogger().d('File moved to ${newFile.path}');
await changeStatus(video, 'done');
await archiveVideo(video.copyWith(status: 'done'));
FileLogger().d('File moved to ${newFile.path}');
}
}
@ -216,20 +237,49 @@ class VideosCubit extends Cubit<VideosState> {
FileLogger().d(
'___Downloading ${video.title} in ${video.format} format ${video.filename}____');
FileLogger().d(
'___Downloading ${video.title} in ${video.format} format ${video.filename}____');
final shellStream = await dlService.downloadFile(video);
var completer = Completer<void>();
shellStream.listen(
(line) {
(line) async {
if (line.contains('[download]') &&
line.contains('of') &&
line.contains('%')) {
var percentString =
line.split('[download]')[1].split(' of')[0].split('%')[0].trim();
var percent = percentString == null ? 0 : double.parse(percentString);
changeStatus(video, 'downloading $percent%');
if (audioFormats.contains(video.format) && percent == 100) {
changeStatus(video, 'downloaded');
if (!completer.isCompleted) {
FileLogger().d('____Download completed___');
FileLogger().d('Download completed');
runningTasks--;
completer.complete();
}
} else {
changeStatus(video, 'downloading $percent%');
}
}
if (line.contains('Destination:')) {
FileLogger().w('Destination: $line');
var destination =
line.split('Destination:')[1].trim().split(RegExp(r'[\\/]')).last;
video = await changeDestination(video, destination);
}
if (line.contains('has already been downloaded')) {
FileLogger().w('Destination: $line');
RegExp regExp = RegExp(r'\\([^\\]+?\.[^\\]+?)\s');
Match? match = regExp.firstMatch(line);
if (match != null) {
String destination = match.group(1)!;
FileLogger().w('Destination: $destination');
video = await changeDestination(video, destination);
} else {
FileLogger().w('Destination: $line');
}
}
if (line.contains('[EmbedThumbnail]')) {
@ -242,7 +292,7 @@ class VideosCubit extends Cubit<VideosState> {
completer.complete();
}
}
//FileLogger().d(line);
FileLogger().d(line);
},
onError: (error) {
if (!completer.isCompleted) {

View File

@ -283,7 +283,7 @@
};
};
buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */;
compatibilityVersion = "Xcode 9.3";
compatibilityVersion = "Xcode 15.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (

View File

@ -1,9 +1,23 @@
import Cocoa
import FlutterMacOS
@NSApplicationMain
@main
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()
}
}

View File

@ -0,0 +1,31 @@
#!/bin/bash
# Check if Homebrew is installed
if ! command -v brew &> /dev/null
then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Homebrew is already installed."
fi
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
# Install FFmpeg
if ! command -v ffmpeg &> /dev/null
then
echo "FFmpeg not found. Installing FFmpeg..."
brew install ffmpeg
else
echo "FFmpeg is already installed."
fi
# Install yt-dlp
if ! command -v yt-dlp &> /dev/null
then
echo "yt-dlp not found. Installing yt-dlp..."
brew install yt-dlp
else
echo "yt-dlp is already installed."
fi

View File

@ -854,10 +854,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
web:
dependency: transitive
description:

View File

@ -3,7 +3,7 @@ description: noTube
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 0.0.23
version: 0.0.50
environment:
sdk: ">=3.0.0 <4.0.0"

84
windows-setup-script.iss Normal file
View File

@ -0,0 +1,84 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "noTube"
#define MyAppVersion "0.50"
#define MyAppPublisher "noTube"
#define MyAppURL "https://notube.lol/"
#define MyAppExeName "notube.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{C715B92D-00E4-48BD-954F-202DB362ED4C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\Skapdat\Oth\buildNoTube
OutputBaseFilename=notube-windows
SetupIconFile=C:\Users\Skapdat\Projets\Dev\NoTube-Flutter\notube\build\windows\x64\runner\Release\data\flutter_assets\assets\images\favicon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
ChangesEnvironment=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "C:\Users\Skapdat\Projets\Dev\NoTube-Flutter\notube\build\windows\x64\runner\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Skapdat\Projets\Dev\NoTube-Flutter\notube\build\windows\x64\runner\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}\data\flutter_assets\assets\executable"; \
Check: NeedsAddPath('{app}\data\flutter_assets\assets\executable')
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[Code]
function NeedsAddPath(Param: string): boolean;
var
OrigPath: string;
begin
if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'Path', OrigPath)
then begin
Result := True;
exit;
end;
{ look for the path with leading and trailing semicolon }
{ Pos() returns 0 if not found }
Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;