@@ -92,9 +92,9 @@ const processVideo = (inputFilePath: string, outputFilePath: string, startTime:
92
92
} ) ;
93
93
}
94
94
95
- const trimAndWriteVideo = async ( outputFilePath : string , startTime : number , endTime : number ) => {
95
+ const trimAndWriteVideo = async ( inputFilePath : string , outputFilePath : string , startTime : number , endTime : number ) => {
96
96
try {
97
- await processVideo ( BATCH_VIDEO_TEMP_FILE , outputFilePath , startTime , endTime - startTime ) ;
97
+ await processVideo ( inputFilePath , outputFilePath , startTime , endTime - startTime ) ;
98
98
} catch ( err ) {
99
99
console . error ( "Unable to trim video: " + err ) ;
100
100
throw new Error ( "Unable to trim video: " + err ) ;
@@ -557,8 +557,16 @@ const createWindow = async () => {
557
557
return { action : 'deny' } ;
558
558
} ) ;
559
559
560
- protocol . interceptFileProtocol ( 'app' , ( request , callback ) => {
561
- let url = request . url . substring ( 6 ) ;
560
+ protocol . interceptFileProtocol ( 'localfile' , ( request , callback ) => {
561
+ let filePath = request . url . substring ( 12 ) ;
562
+
563
+ console . log ( "FILE PATH: " + filePath ) ;
564
+
565
+ callback ( filePath ) ;
566
+ } ) ;
567
+
568
+ protocol . interceptFileProtocol ( 'game' , ( request , callback ) => {
569
+ let url = request . url . substring ( 7 ) ;
562
570
let pattern = / ^ ( r i f f t r a x | w h a t t h e d u b ) \/ ( .+ ) \. ( m p 4 | s r t ) $ / ;
563
571
564
572
if ( url === "batch.tmp.mp4" ) {
@@ -667,6 +675,7 @@ ipcMain.handle('getConfig', () => {
667
675
668
676
ipcMain . handle ( 'storeBatch' , async ( event , { clips, video, title } ) => {
669
677
batchCache = {
678
+ video,
670
679
title,
671
680
clipNumber : 1 ,
672
681
clips,
@@ -684,16 +693,15 @@ ipcMain.handle('hasBatch', (event) => {
684
693
} ) ;
685
694
686
695
ipcMain . handle ( 'nextBatchClip' , ( event ) => {
687
- const { startTime, endTime} = batchCache . clips [ 0 ] ;
688
696
return {
689
697
title : batchCache . title ,
690
698
clipNumber : batchCache . clipNumber ,
691
699
clip : batchCache . clips [ 0 ] ,
692
- video : batchCache . video + `#t= ${ startTime / 1000 } , ${ endTime / 1000 } `
700
+ video : batchCache . video
693
701
} ;
694
702
} ) ;
695
703
696
- ipcMain . handle ( 'processBatchClip' , async ( event , { subtitles, title, clipNumber, game} ) => {
704
+ ipcMain . handle ( 'processBatchClip' , async ( event , { videoSource , subtitles, title, clipNumber, game} ) => {
697
705
console . log (
698
706
`STORING ${ title } -${ clipNumber } for game ${ game } with subtitles ${ subtitles } `
699
707
) ;
@@ -720,7 +728,7 @@ ipcMain.handle('processBatchClip', async (event, {subtitles, title, clipNumber,
720
728
const subFilePath : string = `${ subsDirectory } /${ baseFileName } .srt` ;
721
729
722
730
// Write video clip
723
- await trimAndWriteVideo ( videoFilePath , clip . startTime , clip . endTime ) ;
731
+ await trimAndWriteVideo ( videoSource . replace ( "localfile://" , "" ) , videoFilePath , clip . startTime , clip . endTime ) ;
724
732
725
733
// Write matching subtitles
726
734
fs . writeFileSync ( subFilePath , subtitles ) ;
@@ -822,7 +830,7 @@ ipcMain.handle('getVideo', (event, { id, game }) => {
822
830
823
831
ipcMain . handle (
824
832
'storeVideo' ,
825
- ( event , { base64ByteStream , subtitles, title, clipNumber, game } ) => {
833
+ ( event , { videoSource , subtitles, title, clipNumber, game } ) => {
826
834
console . log (
827
835
`STORING ${ title } -${ clipNumber } for game ${ game } with subtitles ${ subtitles } `
828
836
) ;
@@ -849,10 +857,7 @@ ipcMain.handle(
849
857
850
858
console . log ( 'SAVING TO ' + videoFilePath + '\n' + subFilePath ) ;
851
859
852
- fs . writeFileSync (
853
- videoFilePath ,
854
- Buffer . from ( base64ByteStream , 'base64' )
855
- ) ;
860
+ fs . copyFileSync ( videoSource . replace ( "localfile://" , "" ) , videoFilePath ) ;
856
861
fs . writeFileSync ( subFilePath , subtitles ) ;
857
862
858
863
return baseFileName ;
@@ -1031,6 +1036,17 @@ ipcMain.handle('openDialog', async () => {
1031
1036
}
1032
1037
} ) ;
1033
1038
1039
+ ipcMain . handle ( 'openVideoFile' , async ( ) => {
1040
+ const response = await dialog . showOpenDialog ( {
1041
+ properties : [ 'openFile' ] ,
1042
+ } ) ;
1043
+ if ( ! response . canceled ) {
1044
+ return response . filePaths [ 0 ] ;
1045
+ } else {
1046
+ return null ;
1047
+ }
1048
+ } ) ;
1049
+
1034
1050
ipcMain . handle ( 'setActive' , async ( event , { id, game, isActive } ) => {
1035
1051
console . log ( 'TOGGLING ' + id + ' in game ' + game + ' to ' + isActive ) ;
1036
1052
0 commit comments