Skip to content

Commit 46c555c

Browse files
feat: implement split mode. (#5)
* allow running ccx on a bunch of files at once using split mode todo: progress indicator * feat: implement split mode
1 parent 21e265e commit 46c555c

File tree

12 files changed

+567
-252
lines changed

12 files changed

+567
-252
lines changed

lib/bloc/process_bloc/process_bloc.dart

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,31 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
100100
);
101101
}
102102

103+
Stream<ProcessState> _extractFilesInSplitMode() async* {
104+
unawaited(
105+
_extractor
106+
.extractFilesInSplitMode(
107+
state.orignalList,
108+
listenProgress: (progress) =>
109+
add(ProcessFileExtractorProgress(progress)),
110+
listenOutput: (line) => add(ProcessFileExtractorOutput(line)),
111+
listenVideoDetails: (videoDetails) =>
112+
add(ProcessFileVideoDetails(videoDetails)),
113+
)
114+
.then(
115+
(value) {
116+
if (value != 0) {
117+
add(ProcessError(value));
118+
}
119+
add(SplitModeProcessComplete());
120+
},
121+
),
122+
);
123+
}
124+
103125
@override
104126
Stream<ProcessState> mapEventToState(ProcessEvent event) async* {
105-
if (event is ProcessStarted) {
127+
if (event is StartAllProcess) {
106128
yield state.copyWith(
107129
current: state.current,
108130
// This equality checks if the queue and originalList are same which
@@ -117,11 +139,14 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
117139
started: true,
118140
);
119141
yield* _extractNext();
120-
} else if (event is ProcessStopped) {
142+
} else if (event is StartProcessInSplitMode) {
143+
yield state.copyWith(current: state.current, started: true);
144+
yield* _extractFilesInSplitMode();
145+
} else if (event is StopAllProcess) {
121146
// stops everything
122147
try {
123148
_extractor.cancelRun();
124-
} on Exception catch (_) {}
149+
} catch (_) {}
125150
yield state.copyWith(
126151
current: null,
127152
queue: state.orignalList,
@@ -132,7 +157,7 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
132157
} else if (event is ProcessKill) {
133158
try {
134159
_extractor.cancelRun();
135-
} on Exception catch (_) {}
160+
} catch (_) {}
136161
yield state.copyWith(
137162
current: state.current,
138163
orignalList: state.orignalList
@@ -143,7 +168,7 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
143168
} else if (event is ProcessRemoveAll) {
144169
try {
145170
_extractor.cancelRun();
146-
} on Exception catch (_) {}
171+
} catch (_) {}
147172
yield state.copyWith(
148173
current: null,
149174
progress: '0',
@@ -175,6 +200,13 @@ class ProcessBloc extends Bloc<ProcessEvent, ProcessState> {
175200
);
176201
yield* _extractNext();
177202
}
203+
} else if (event is SplitModeProcessComplete) {
204+
yield state.copyWith(
205+
current: null,
206+
log: state.log,
207+
exitCode: null,
208+
started: false,
209+
progress: '100');
178210
} else if (event is ProcessFilesSubmitted) {
179211
yield state.copyWith(
180212
current: state.current,

lib/bloc/process_bloc/process_event.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ class ProcessFilesSubmitted extends ProcessEvent {
1111
const ProcessFilesSubmitted(this.files);
1212
}
1313

14-
class ProcessStarted extends ProcessEvent {}
14+
class StartAllProcess extends ProcessEvent {}
1515

1616
/// ProcessStopped stops all the files from processing.
17-
class ProcessStopped extends ProcessEvent {}
17+
class StopAllProcess extends ProcessEvent {}
18+
19+
/// ccx runs on all the files at once
20+
class StartProcessInSplitMode extends ProcessEvent {}
21+
22+
class SplitModeProcessComplete extends ProcessEvent {}
1823

1924
/// Removes pending file from state queue
2025
class ProcessFileRemoved extends ProcessEvent {

lib/bloc/settings_bloc/settings_state.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
part of 'settings_bloc.dart';
22

3+
//TODO: CurrentSettingsState sometimes makes the code messy,
4+
//try to change it a single class state like other bloc states
35
abstract class SettingsState extends Equatable {
46
const SettingsState();
57

lib/models/settings_model.dart

Lines changed: 107 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SettingsModel {
120120
bool detectItalics;
121121
String confThresh;
122122
String whiteThresh;
123-
123+
bool splitMode;
124124
SettingsModel({
125125
this.out = 'auto/default',
126126
this.inp = 'auto/default',
@@ -216,6 +216,7 @@ class SettingsModel {
216216
this.detectItalics = false,
217217
this.confThresh = '',
218218
this.whiteThresh = '',
219+
this.splitMode = false,
219220
});
220221

221222
static Map<String, String> get paramsLookUpMap {
@@ -312,6 +313,7 @@ class SettingsModel {
312313
'detectItalics': '-detect_italics',
313314
'confThresh': '-conf_thresh',
314315
'whiteThresh': '-whiteness_thresh',
316+
'splitMode': '', // splitMode is not a ccx setting
315317
};
316318
}
317319

@@ -341,102 +343,102 @@ class SettingsModel {
341343
return enabledtextfields;
342344
}
343345

344-
SettingsModel copyWith({
345-
String? out,
346-
String? inp,
347-
String? outputfilename,
348-
bool? fixptsjumps,
349-
bool? append,
350-
String? outInterval,
351-
bool? segmentonkeyonly,
352-
bool? goptime,
353-
bool? nogoptime,
354-
bool? fixpadding,
355-
bool? freqEs15,
356-
String? stream,
357-
bool? videoedited,
358-
bool? usepicorder,
359-
bool? myth,
360-
bool? nomyth,
361-
bool? wtvconvertfix,
362-
bool? wtvmpeg2,
363-
String? program_number,
364-
bool? autoprogram,
365-
bool? multiprogram,
366-
String? streamtype,
367-
bool? hauppauge,
368-
bool? mp4vidtrack,
369-
bool? noautotimeref,
370-
bool? noscte20,
371-
bool? webvttcss,
372-
bool? analyzevideo,
373-
bool? notimestamp,
374-
bool? nolevdist,
375-
String? minlevdist,
376-
String? maxlevdist,
377-
bool? chapters,
378-
bool? bom,
379-
bool? nobom,
380-
String? encoder,
381-
bool? nofontcolor,
382-
bool? nohtmlescape,
383-
bool? notypesetting,
384-
bool? trim,
385-
String? defaultcolor,
386-
bool? sentencecap,
387-
String? capFile,
388-
bool? kf,
389-
String? profanityFile,
390-
bool? splitbysentence,
391-
bool? datets,
392-
bool? sects,
393-
bool? latrusmap,
394-
bool? xds,
395-
bool? lf,
396-
bool? df,
397-
bool? autodash,
398-
String? xmltv,
399-
String? xmltvliveinterval,
400-
String? xmltvoutputinterval,
401-
bool? xmltvonlycurrent,
402-
bool? sem,
403-
String? dvblang,
404-
String? mkvlang,
405-
String? ocrlang,
406-
String? quant,
407-
String? oem,
408-
bool? bufferinput,
409-
bool? nobufferinput,
410-
String? buffersize,
411-
bool? koc,
412-
bool? dru,
413-
bool? norollup,
414-
String? rollUp,
415-
String? delay,
416-
String? startat,
417-
String? endat,
418-
String? codec,
419-
String? nocodec,
420-
String? startcreditstext,
421-
String? startcreditsnotbefore,
422-
String? startcreditsnotafter,
423-
String? startcreditsforatleast,
424-
String? startcreditsforatmost,
425-
String? endcreditstext,
426-
String? endcreditsforatleast,
427-
String? endcreditsforatmost,
428-
String? tpage,
429-
bool? teletext,
430-
bool? noteletext,
431-
bool? hardsubx,
432-
bool? tickertext,
433-
String? ocrMode,
434-
String? subcolor,
435-
String? minSubDuration,
436-
bool? detectItalics,
437-
String? confThresh,
438-
String? whiteThresh,
439-
}) {
346+
SettingsModel copyWith(
347+
{String? out,
348+
String? inp,
349+
String? outputfilename,
350+
bool? fixptsjumps,
351+
bool? append,
352+
String? outInterval,
353+
bool? segmentonkeyonly,
354+
bool? goptime,
355+
bool? nogoptime,
356+
bool? fixpadding,
357+
bool? freqEs15,
358+
String? stream,
359+
bool? videoedited,
360+
bool? usepicorder,
361+
bool? myth,
362+
bool? nomyth,
363+
bool? wtvconvertfix,
364+
bool? wtvmpeg2,
365+
String? program_number,
366+
bool? autoprogram,
367+
bool? multiprogram,
368+
String? streamtype,
369+
bool? hauppauge,
370+
bool? mp4vidtrack,
371+
bool? noautotimeref,
372+
bool? noscte20,
373+
bool? webvttcss,
374+
bool? analyzevideo,
375+
bool? notimestamp,
376+
bool? nolevdist,
377+
String? minlevdist,
378+
String? maxlevdist,
379+
bool? chapters,
380+
bool? bom,
381+
bool? nobom,
382+
String? encoder,
383+
bool? nofontcolor,
384+
bool? nohtmlescape,
385+
bool? notypesetting,
386+
bool? trim,
387+
String? defaultcolor,
388+
bool? sentencecap,
389+
String? capFile,
390+
bool? kf,
391+
String? profanityFile,
392+
bool? splitbysentence,
393+
bool? datets,
394+
bool? sects,
395+
bool? latrusmap,
396+
bool? xds,
397+
bool? lf,
398+
bool? df,
399+
bool? autodash,
400+
String? xmltv,
401+
String? xmltvliveinterval,
402+
String? xmltvoutputinterval,
403+
bool? xmltvonlycurrent,
404+
bool? sem,
405+
String? dvblang,
406+
String? mkvlang,
407+
String? ocrlang,
408+
String? quant,
409+
String? oem,
410+
bool? bufferinput,
411+
bool? nobufferinput,
412+
String? buffersize,
413+
bool? koc,
414+
bool? dru,
415+
bool? norollup,
416+
String? rollUp,
417+
String? delay,
418+
String? startat,
419+
String? endat,
420+
String? codec,
421+
String? nocodec,
422+
String? startcreditstext,
423+
String? startcreditsnotbefore,
424+
String? startcreditsnotafter,
425+
String? startcreditsforatleast,
426+
String? startcreditsforatmost,
427+
String? endcreditstext,
428+
String? endcreditsforatleast,
429+
String? endcreditsforatmost,
430+
String? tpage,
431+
bool? teletext,
432+
bool? noteletext,
433+
bool? hardsubx,
434+
bool? tickertext,
435+
String? ocrMode,
436+
String? subcolor,
437+
String? minSubDuration,
438+
bool? detectItalics,
439+
String? confThresh,
440+
String? whiteThresh,
441+
bool? splitMode}) {
440442
return SettingsModel(
441443
out: out ?? this.out,
442444
inp: inp ?? this.inp,
@@ -535,6 +537,7 @@ class SettingsModel {
535537
detectItalics: detectItalics ?? this.detectItalics,
536538
confThresh: confThresh ?? this.confThresh,
537539
whiteThresh: whiteThresh ?? this.whiteThresh,
540+
splitMode: splitMode ?? this.splitMode,
538541
);
539542
}
540543

@@ -634,6 +637,7 @@ class SettingsModel {
634637
'detectItalics': detectItalics,
635638
'confThresh': confThresh,
636639
'whiteThresh': whiteThresh,
640+
'splitMode': splitMode,
637641
};
638642
}
639643

@@ -733,12 +737,13 @@ class SettingsModel {
733737
detectItalics: map['detectItalics'],
734738
confThresh: map['confThresh'],
735739
whiteThresh: map['whiteThresh'],
740+
splitMode: map['splitMode'],
736741
);
737742
}
738743

739744
@override
740745
String toString() {
741-
return 'SettingsModel(out: $out, inp: $inp, outputfilename: $outputfilename, fixptsjumps: $fixptsjumps, append: $append, outInterval: $outInterval, segmentonkeyonly: $segmentonkeyonly, goptime: $goptime, nogoptime: $nogoptime, fixpadding: $fixpadding, freqEs15: $freqEs15, stream: $stream, videoedited: $videoedited, usepicorder: $usepicorder, myth: $myth, nomyth: $nomyth, wtvconvertfix: $wtvconvertfix, wtvmpeg2: $wtvmpeg2, program_number: $program_number, autoprogram: $autoprogram, multiprogram: $multiprogram, streamtype: $streamtype, hauppauge: $hauppauge, mp4vidtrack: $mp4vidtrack, noautotimeref: $noautotimeref, noscte20: $noscte20, webvttcss: $webvttcss, analyzevideo: $analyzevideo, notimestamp: $notimestamp, nolevdist: $nolevdist, minlevdist: $minlevdist, maxlevdist: $maxlevdist, chapters: $chapters, bom: $bom, nobom: $nobom, encoder: $encoder, nofontcolor: $nofontcolor, nohtmlescape: $nohtmlescape, notypesetting: $notypesetting, trim: $trim, defaultcolor: $defaultcolor, sentencecap: $sentencecap, capFile: $capFile, kf: $kf, profanityFile: $profanityFile, splitbysentence: $splitbysentence, datets: $datets, sects: $sects, latrusmap: $latrusmap, xds: $xds, lf: $lf, df: $df, autodash: $autodash, xmltv: $xmltv, xmltvliveinterval: $xmltvliveinterval, xmltvoutputinterval: $xmltvoutputinterval, xmltvonlycurrent: $xmltvonlycurrent, sem: $sem, dvblang: $dvblang, mkvlang: $mkvlang, ocrlang: $ocrlang, quant: $quant, oem: $oem, bufferinput: $bufferinput, nobufferinput: $nobufferinput, buffersize: $buffersize, koc: $koc, dru: $dru, norollup: $norollup, rollUp: $rollUp, delay: $delay, startat: $startat, endat: $endat, codec: $codec, nocodec: $nocodec, startcreditstext: $startcreditstext, startcreditsnotbefore: $startcreditsnotbefore, startcreditsnotafter: $startcreditsnotafter, startcreditsforatleast: $startcreditsforatleast, startcreditsforatmost: $startcreditsforatmost, endcreditstext: $endcreditstext, endcreditsforatleast: $endcreditsforatleast, endcreditsforatmost: $endcreditsforatmost, tpage: $tpage, teletext: $teletext, noteletext: $noteletext, hardsubx: $hardsubx, tickertext: $tickertext, ocrMode: $ocrMode, subcolor: $subcolor, minSubDuration: $minSubDuration, detectItalics: $detectItalics, confThresh: $confThresh, whiteThresh: $whiteThresh)';
746+
return 'SettingsModel(out: $out, inp: $inp, outputfilename: $outputfilename, fixptsjumps: $fixptsjumps, append: $append, outInterval: $outInterval, segmentonkeyonly: $segmentonkeyonly, goptime: $goptime, nogoptime: $nogoptime, fixpadding: $fixpadding, freqEs15: $freqEs15, stream: $stream, videoedited: $videoedited, usepicorder: $usepicorder, myth: $myth, nomyth: $nomyth, wtvconvertfix: $wtvconvertfix, wtvmpeg2: $wtvmpeg2, program_number: $program_number, autoprogram: $autoprogram, multiprogram: $multiprogram, streamtype: $streamtype, hauppauge: $hauppauge, mp4vidtrack: $mp4vidtrack, noautotimeref: $noautotimeref, noscte20: $noscte20, webvttcss: $webvttcss, analyzevideo: $analyzevideo, notimestamp: $notimestamp, nolevdist: $nolevdist, minlevdist: $minlevdist, maxlevdist: $maxlevdist, chapters: $chapters, bom: $bom, nobom: $nobom, encoder: $encoder, nofontcolor: $nofontcolor, nohtmlescape: $nohtmlescape, notypesetting: $notypesetting, trim: $trim, defaultcolor: $defaultcolor, sentencecap: $sentencecap, capFile: $capFile, kf: $kf, profanityFile: $profanityFile, splitbysentence: $splitbysentence, datets: $datets, sects: $sects, latrusmap: $latrusmap, xds: $xds, lf: $lf, df: $df, autodash: $autodash, xmltv: $xmltv, xmltvliveinterval: $xmltvliveinterval, xmltvoutputinterval: $xmltvoutputinterval, xmltvonlycurrent: $xmltvonlycurrent, sem: $sem, dvblang: $dvblang, mkvlang: $mkvlang, ocrlang: $ocrlang, quant: $quant, oem: $oem, bufferinput: $bufferinput, nobufferinput: $nobufferinput, buffersize: $buffersize, koc: $koc, dru: $dru, norollup: $norollup, rollUp: $rollUp, delay: $delay, startat: $startat, endat: $endat, codec: $codec, nocodec: $nocodec, startcreditstext: $startcreditstext, startcreditsnotbefore: $startcreditsnotbefore, startcreditsnotafter: $startcreditsnotafter, startcreditsforatleast: $startcreditsforatleast, startcreditsforatmost: $startcreditsforatmost, endcreditstext: $endcreditstext, endcreditsforatleast: $endcreditsforatleast, endcreditsforatmost: $endcreditsforatmost, tpage: $tpage, teletext: $teletext, noteletext: $noteletext, hardsubx: $hardsubx, tickertext: $tickertext, ocrMode: $ocrMode, subcolor: $subcolor, minSubDuration: $minSubDuration, detectItalics: $detectItalics, confThresh: $confThresh, whiteThresh: $whiteThresh, splitMode: $splitMode,)';
742747
}
743748

744749
@override
@@ -839,7 +844,8 @@ class SettingsModel {
839844
other.minSubDuration == minSubDuration &&
840845
other.detectItalics == detectItalics &&
841846
other.confThresh == confThresh &&
842-
other.whiteThresh == whiteThresh;
847+
other.whiteThresh == whiteThresh &&
848+
other.splitMode == splitMode;
843849
}
844850

845851
@override
@@ -937,6 +943,7 @@ class SettingsModel {
937943
minSubDuration.hashCode ^
938944
detectItalics.hashCode ^
939945
confThresh.hashCode ^
940-
whiteThresh.hashCode;
946+
whiteThresh.hashCode ^
947+
splitMode.hashCode;
941948
}
942949
}

0 commit comments

Comments
 (0)