[log] clean file logger
This commit is contained in:
parent
01db0170fd
commit
fd60d2c137
|
|
@ -7,6 +7,7 @@ import 'package:notube/constants.dart';
|
|||
import 'package:notube/models/video.dart';
|
||||
import 'package:notube/videoList/cubit/videos_cubit.dart';
|
||||
import 'package:notube/dlForm/cubit/dl_form_cubit.dart';
|
||||
import 'package:notube/services/file_logger.dart';
|
||||
|
||||
class SubmitButton extends StatefulWidget {
|
||||
const SubmitButton({super.key});
|
||||
|
|
@ -22,7 +23,7 @@ class _SubmitButtonState extends State<SubmitButton> {
|
|||
if (state.isParsed) {
|
||||
context.read<VideosCubit>().setGlobalStatus('loaded');
|
||||
for (Video video in state.videos) {
|
||||
debugPrint('Adding video: $video');
|
||||
FileLogger().d('Adding video: $video');
|
||||
context.read<VideosCubit>().addVideo(video);
|
||||
}
|
||||
context.read<DlFormCubit>().clearForm();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:process_run/process_run.dart';
|
||||
import 'package:notube/models/video.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:notube/services/file_logger.dart';
|
||||
|
||||
class ConverterService {
|
||||
late Directory tempDir;
|
||||
|
|
@ -15,7 +16,7 @@ class ConverterService {
|
|||
ConverterService._();
|
||||
|
||||
static Future<ConverterService> init() async {
|
||||
debugPrint('Initializing DLServices');
|
||||
FileLogger().d('Initializing DLServices');
|
||||
var dlService = ConverterService._();
|
||||
await dlService._init();
|
||||
return dlService;
|
||||
|
|
@ -50,8 +51,8 @@ class ConverterService {
|
|||
final List<FileSystemEntity> files = directory.listSync();
|
||||
for (FileSystemEntity file in files) {
|
||||
final String dirFilename = p.basenameWithoutExtension(file.path);
|
||||
debugPrint('dirFilename $dirFilename');
|
||||
debugPrint('filename $filename');
|
||||
FileLogger().d('dirFilename $dirFilename');
|
||||
FileLogger().d('filename $filename');
|
||||
if (dirFilename == '${filename}_tmp') {
|
||||
return File(file.path);
|
||||
}
|
||||
|
|
@ -60,7 +61,7 @@ class ConverterService {
|
|||
}
|
||||
|
||||
Future<Stream> convertFile(Video video) async {
|
||||
debugPrint(
|
||||
FileLogger().d(
|
||||
'____Converting ${video.title} to ${video.format.format} format_____');
|
||||
|
||||
File tmpFile = File('temp/${video.filename}_tmp.mp4');
|
||||
|
|
@ -72,7 +73,7 @@ class ConverterService {
|
|||
File doneFile =
|
||||
File('temp/${video.filename}_done.${video.format.extension}');
|
||||
if (doneFile.existsSync()) {
|
||||
debugPrint('File already converted');
|
||||
FileLogger().d('File already converted');
|
||||
return Stream.fromIterable(['progress=end']);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class DLServices {
|
|||
DLServices._();
|
||||
|
||||
static Future<DLServices> init() async {
|
||||
debugPrint('Initializing DLServices');
|
||||
FileLogger().d('Initializing DLServices');
|
||||
var dlService = DLServices._();
|
||||
await dlService._init();
|
||||
return dlService;
|
||||
|
|
@ -57,7 +57,7 @@ class DLServices {
|
|||
ByteData data = await rootBundle.load('assets/executable/$assetName');
|
||||
await tempFile.exists().then((value) {
|
||||
if (!value) {
|
||||
debugPrint('Copying $assetName to ${tempFile.path}');
|
||||
FileLogger().d('Copying $assetName to ${tempFile.path}');
|
||||
tempFile.writeAsBytes(
|
||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
|
||||
}
|
||||
|
|
@ -82,10 +82,10 @@ class DLServices {
|
|||
print('FFmpeg is already installed.');
|
||||
completer.complete(true);
|
||||
result.map((e) {
|
||||
debugPrint('Analyse result: $e');
|
||||
FileLogger().d('Analyse result: $e');
|
||||
FileLogger().d('Analyse result: ${e.toString()}');
|
||||
FileLogger().d('stdout: ${e.stdout}');
|
||||
FileLogger().d('stderr: ${e.stderr}');
|
||||
FileLogger().w('stdout: ${e.stdout}');
|
||||
FileLogger().e('stderr: ${e.stderr}');
|
||||
});
|
||||
}).catchError((
|
||||
error,
|
||||
|
|
@ -100,7 +100,7 @@ class DLServices {
|
|||
|
||||
Future<void> checkFFmpeg() async {
|
||||
var result = await futureShell('ffmpeg -version');
|
||||
debugPrint('$result');
|
||||
FileLogger().d('$result');
|
||||
|
||||
try {
|
||||
var result = await Process.run('ffmpeg', ['-version']);
|
||||
|
|
@ -109,7 +109,7 @@ class DLServices {
|
|||
return;
|
||||
}
|
||||
|
||||
debugPrint('RESULTS: $result');
|
||||
FileLogger().d('RESULTS: $result');
|
||||
|
||||
print('Installing FFmpeg...');
|
||||
if (Platform.isLinux) {
|
||||
|
|
@ -142,7 +142,7 @@ class DLServices {
|
|||
}
|
||||
|
||||
Future<Stream> downloadFile(Video video) async {
|
||||
debugPrint(
|
||||
FileLogger().d(
|
||||
'Downloading $url in ${video.format.format} format (${video.filename})');
|
||||
|
||||
/*
|
||||
|
|
@ -153,11 +153,11 @@ class DLServices {
|
|||
// get the format code from the Format enum
|
||||
var formatCmd =
|
||||
Format.values.firstWhere((e) => e.format == video.format.format).ytCmd;
|
||||
debugPrint('Format code: $formatCmd');
|
||||
FileLogger().d('Format code: $formatCmd');
|
||||
|
||||
File doneFile = File('temp/${video.filename}_tmp.mp4');
|
||||
if (doneFile.existsSync()) {
|
||||
debugPrint('File already downloaded');
|
||||
FileLogger().d('File already downloaded');
|
||||
return Stream.fromIterable(['[EmbedThumbnail]']);
|
||||
}
|
||||
|
||||
|
|
@ -171,24 +171,24 @@ class DLServices {
|
|||
var shell = Shell(
|
||||
stdout: shellLinesController.sink, stderr: shellErrorController.sink);
|
||||
|
||||
debugPrint('Running $ytDlpPath $command');
|
||||
FileLogger().d('Running $ytDlpPath $command');
|
||||
shell.run('$ytDlpPath $command').then((result) {
|
||||
result.map((e) {
|
||||
debugPrint('Analyse result: $e');
|
||||
FileLogger().d('Analyse result: $e');
|
||||
FileLogger().d('Analyse result: ${e.toString()}');
|
||||
FileLogger().d('stdout: ${e.stdout}');
|
||||
FileLogger().d('stderr: ${e.stderr}');
|
||||
FileLogger().w('stdout: ${e.stdout}');
|
||||
FileLogger().e('stderr: ${e.stderr}');
|
||||
});
|
||||
}).catchError((
|
||||
error,
|
||||
stackTrace,
|
||||
) {
|
||||
if (error is ShellException) {
|
||||
debugPrint('ShellException: ${error.message}');
|
||||
FileLogger().d('ShellException: ${error.message}');
|
||||
FileLogger().e('ShellException error: ${error.result?.stderr}');
|
||||
FileLogger().e('ShellException out: ${error.result?.stdout}');
|
||||
} else {
|
||||
debugPrint('Error: $error');
|
||||
FileLogger().d('Error: $error');
|
||||
FileLogger().e('Error: $error');
|
||||
}
|
||||
});
|
||||
|
|
@ -197,7 +197,7 @@ class DLServices {
|
|||
}
|
||||
|
||||
Future analyseUrl(String url) async {
|
||||
debugPrint('Analyse $url');
|
||||
FileLogger().d('Analyse $url');
|
||||
|
||||
var command = '${url.trim()} -q --flat-playlist -J';
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ class DLServices {
|
|||
var shellErrorController = ShellLinesController();
|
||||
|
||||
shellErrorController.stream.listen((event) {
|
||||
debugPrint('Analyse error: $event');
|
||||
FileLogger().d('Analyse error: $event');
|
||||
FileLogger().e('Analyse error: $event');
|
||||
});
|
||||
|
||||
|
|
@ -218,21 +218,21 @@ class DLServices {
|
|||
$ytDlpPath $command
|
||||
''').then((result) {
|
||||
result.map((e) {
|
||||
debugPrint('Analyse result: $e');
|
||||
FileLogger().d('Analyse result: $e');
|
||||
FileLogger().d('Analyse result: ${e.toString()}');
|
||||
FileLogger().d('stdout: ${e.stdout}');
|
||||
FileLogger().d('stderr: ${e.stderr}');
|
||||
FileLogger().w('stdout: ${e.stdout}');
|
||||
FileLogger().e('stderr: ${e.stderr}');
|
||||
});
|
||||
}).catchError((
|
||||
error,
|
||||
stackTrace,
|
||||
) {
|
||||
if (error is ShellException) {
|
||||
debugPrint('ShellException: ${error.message}');
|
||||
FileLogger().d('ShellException: ${error.message}');
|
||||
FileLogger().e('ShellException error: ${error.result?.stderr}');
|
||||
FileLogger().e('ShellException out: ${error.result?.stdout}');
|
||||
} else {
|
||||
debugPrint('Error: $error');
|
||||
FileLogger().d('Error: $error');
|
||||
FileLogger().e('Error: $error');
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ class FileLogger {
|
|||
_logFile = File('apps_logs.txt');
|
||||
|
||||
_logger = Logger(
|
||||
filter: ProductionFilter(),
|
||||
printer: PrettyPrinter(),
|
||||
output: FileOutput(file: _logFile),
|
||||
);
|
||||
}
|
||||
|
||||
void d(String message) {
|
||||
FileLogger().d(message);
|
||||
_logger.d(message);
|
||||
}
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ class FileLogger {
|
|||
}
|
||||
|
||||
void w(String message) {
|
||||
FileLogger().d(message);
|
||||
_logger.w(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import 'package:notube/constants.dart';
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:downloadsfolder/downloadsfolder.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:notube/services/file_logger.dart';
|
||||
|
||||
part 'videos_state.dart';
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
emit(VideosState(videoList: tmpVideoList));
|
||||
completer.complete();
|
||||
} else {
|
||||
debugPrint('Video not found in the list');
|
||||
FileLogger().d('Video not found in the list');
|
||||
completer.completeError('Video not found in the list');
|
||||
}
|
||||
return completer.future;
|
||||
|
|
@ -60,12 +61,12 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
}
|
||||
|
||||
Future<void> archiveVideo(Video video) async {
|
||||
debugPrint('Archiving video: ${video.title} ${video.format.format}');
|
||||
FileLogger().d('Archiving video: ${video.title} ${video.format.format}');
|
||||
var nVideoList = state.videoList.where((v) => v.id != video.id).toList();
|
||||
var archivedVideos = state.archiveList.toList();
|
||||
debugPrint('Archived videos before: ${archivedVideos.length}');
|
||||
FileLogger().d('Archived videos before: ${archivedVideos.length}');
|
||||
archivedVideos.add(video);
|
||||
debugPrint('Archived videos after: $archivedVideos');
|
||||
FileLogger().d('Archived videos after: $archivedVideos');
|
||||
emit(state.copyWith(videoList: nVideoList, archiveList: archivedVideos));
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +77,8 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
for (Video video in videosToConvert) {
|
||||
await convertVideo(video);
|
||||
}
|
||||
debugPrint('All videos converted');
|
||||
FileLogger().d('All videos converted');
|
||||
FileLogger().d('All videos converted');
|
||||
}
|
||||
|
||||
Future<void> startDownloader() async {
|
||||
|
|
@ -86,9 +88,9 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
state.videoList.where((video) => video.status == 'pending').take(3);
|
||||
|
||||
while (downloadingVid.isNotEmpty && runningTasks < maxConcurrentTasks) {
|
||||
debugPrint('Videos to download: ${downloadingVid.length}');
|
||||
FileLogger().d('Videos to download: ${downloadingVid.length}');
|
||||
runningTasks++;
|
||||
debugPrint('Concurrent workers: $runningTasks');
|
||||
FileLogger().d('Concurrent workers: $runningTasks');
|
||||
|
||||
await downloadVideo(downloadingVid.first);
|
||||
downloadingVid =
|
||||
|
|
@ -108,11 +110,12 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
}
|
||||
}
|
||||
|
||||
debugPrint('All videos downloaded');
|
||||
FileLogger().d('All videos downloaded');
|
||||
FileLogger().d('All videos downloaded');
|
||||
}
|
||||
|
||||
Future moveVideos() async {
|
||||
debugPrint('Moving videos to download folder');
|
||||
FileLogger().d('Moving videos to download folder');
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
Directory defaultDownloadDirectory = await getDownloadDirectory();
|
||||
prefs.get('downloadFolder') ??
|
||||
|
|
@ -130,8 +133,8 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
var playlistTitle = video.playlistTitle;
|
||||
await Directory('${downloadDirectory.path}/$playlistTitle')
|
||||
.create(recursive: true)
|
||||
.catchError((e) => debugPrint('Error creating directory: $e'));
|
||||
debugPrint('Playlist title: $playlistTitle');
|
||||
.catchError((e) => FileLogger().e('Error creating directory: $e'));
|
||||
FileLogger().d('Playlist title: $playlistTitle');
|
||||
if (playlistTitle.isNotEmpty && playlistTitle != '') {
|
||||
cleanTitle = '$playlistTitle/$cleanTitle';
|
||||
}
|
||||
|
|
@ -145,19 +148,20 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
await tmpFile.rename(newFile.path);
|
||||
isMoved = true;
|
||||
} on FileSystemException catch (e) {
|
||||
debugPrint('Error moving file: $e');
|
||||
FileLogger().e('Error moving file: $e');
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
await changeStatus(video, 'done');
|
||||
await archiveVideo(video.copyWith(status: 'done'));
|
||||
debugPrint('File moved to ${newFile.path}');
|
||||
FileLogger().d('File moved to ${newFile.path}');
|
||||
}
|
||||
}
|
||||
|
||||
Future convertVideo(Video video) async {
|
||||
converterService = await ConverterService.init();
|
||||
debugPrint('Converting ${video.title} to ${video.format.format}');
|
||||
FileLogger().d('Converting ${video.title} to ${video.format.format}');
|
||||
FileLogger().d('Converting ${video.title} to ${video.format.format}');
|
||||
changeStatus(video, 'converting');
|
||||
final shellStream = await converterService.convertFile(video);
|
||||
var duration = '0.0';
|
||||
|
|
@ -165,12 +169,13 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
|
||||
shellStream.listen(
|
||||
(line) {
|
||||
debugPrint(line);
|
||||
FileLogger().d(line);
|
||||
//FFmpeg doesn't return any output for audio conversion
|
||||
if (video.format.extension == "mp3") {
|
||||
changeStatus(video, 'converted');
|
||||
if (!completer.isCompleted) {
|
||||
debugPrint('____Conversion audio completed___');
|
||||
FileLogger().d('____Conversion audio completed___');
|
||||
FileLogger().d('Conversion audio completed');
|
||||
runningTasks--;
|
||||
completer.complete();
|
||||
}
|
||||
|
|
@ -179,18 +184,18 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
var durationString =
|
||||
line.split('Duration: ')[1].split(',')[0].trim();
|
||||
duration = durationString;
|
||||
debugPrint('Duration: $duration');
|
||||
FileLogger().d('Duration: $duration');
|
||||
}
|
||||
if (line.contains('out_time_ms=')) {
|
||||
var timeString = line.split('out_time_ms=')[1];
|
||||
var time = timeString;
|
||||
debugPrint('Time: $time');
|
||||
FileLogger().d('Time: $time');
|
||||
changeStatus(video, 'converting $time on $duration');
|
||||
}
|
||||
if (line.contains('progress=end')) {
|
||||
changeStatus(video, 'converted');
|
||||
if (!completer.isCompleted) {
|
||||
debugPrint('____Conversion completed___');
|
||||
FileLogger().d('____Conversion completed___');
|
||||
runningTasks--;
|
||||
completer.complete();
|
||||
}
|
||||
|
|
@ -208,7 +213,10 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
}
|
||||
|
||||
Future downloadVideo(Video video) async {
|
||||
debugPrint(
|
||||
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>();
|
||||
|
|
@ -228,12 +236,13 @@ class VideosCubit extends Cubit<VideosState> {
|
|||
changeStatus(video, 'downloaded');
|
||||
|
||||
if (!completer.isCompleted) {
|
||||
debugPrint('____Download completed___');
|
||||
FileLogger().d('____Download completed___');
|
||||
FileLogger().d('Download completed');
|
||||
runningTasks--;
|
||||
completer.complete();
|
||||
}
|
||||
}
|
||||
//debugPrint(line);
|
||||
//FileLogger().d(line);
|
||||
},
|
||||
onError: (error) {
|
||||
if (!completer.isCompleted) {
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue