Skip to content

Commit 6072d8e

Browse files
Videos are now pulled directly from the file system instead of copying them
1 parent 6e4ee66 commit 6072d8e

File tree

9 files changed

+53
-58
lines changed

9 files changed

+53
-58
lines changed

release/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dub-editor-electron",
3-
"version": "1.3.1-alpha-preview",
3+
"version": "1.4.0-beta",
44
"description": "A dub editor for What the Dub and Rifftrax games by Wide Right Studios",
55
"license": "MIT",
66
"author": {

src/main/main.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ const processVideo = (inputFilePath: string, outputFilePath: string, startTime:
9292
});
9393
}
9494

95-
const trimAndWriteVideo = async (outputFilePath: string, startTime: number, endTime: number) => {
95+
const trimAndWriteVideo = async (inputFilePath: string, outputFilePath: string, startTime: number, endTime: number) => {
9696
try {
97-
await processVideo(BATCH_VIDEO_TEMP_FILE, outputFilePath, startTime, endTime - startTime);
97+
await processVideo(inputFilePath, outputFilePath, startTime, endTime - startTime);
9898
} catch (err) {
9999
console.error("Unable to trim video: " + err);
100100
throw new Error("Unable to trim video: " + err);
@@ -557,8 +557,16 @@ const createWindow = async () => {
557557
return { action: 'deny' };
558558
});
559559

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);
562570
let pattern = /^(rifftrax|whatthedub)\/(.+)\.(mp4|srt)$/;
563571

564572
if (url === "batch.tmp.mp4") {
@@ -667,6 +675,7 @@ ipcMain.handle('getConfig', () => {
667675

668676
ipcMain.handle('storeBatch', async (event, { clips, video, title }) => {
669677
batchCache = {
678+
video,
670679
title,
671680
clipNumber: 1,
672681
clips,
@@ -684,16 +693,15 @@ ipcMain.handle('hasBatch', (event) => {
684693
});
685694

686695
ipcMain.handle('nextBatchClip', (event) => {
687-
const {startTime, endTime} = batchCache.clips[0];
688696
return {
689697
title: batchCache.title,
690698
clipNumber: batchCache.clipNumber,
691699
clip: batchCache.clips[0],
692-
video: batchCache.video + `#t=${startTime/1000},${endTime/1000}`
700+
video: batchCache.video
693701
};
694702
});
695703

696-
ipcMain.handle('processBatchClip', async (event, {subtitles, title, clipNumber, game}) => {
704+
ipcMain.handle('processBatchClip', async (event, {videoSource, subtitles, title, clipNumber, game}) => {
697705
console.log(
698706
`STORING ${title}-${clipNumber} for game ${game} with subtitles ${subtitles}`
699707
);
@@ -720,7 +728,7 @@ ipcMain.handle('processBatchClip', async (event, {subtitles, title, clipNumber,
720728
const subFilePath: string = `${subsDirectory}/${baseFileName}.srt`;
721729

722730
// Write video clip
723-
await trimAndWriteVideo(videoFilePath, clip.startTime, clip.endTime);
731+
await trimAndWriteVideo(videoSource.replace("localfile://", ""), videoFilePath, clip.startTime, clip.endTime);
724732

725733
// Write matching subtitles
726734
fs.writeFileSync(subFilePath, subtitles);
@@ -822,7 +830,7 @@ ipcMain.handle('getVideo', (event, { id, game }) => {
822830

823831
ipcMain.handle(
824832
'storeVideo',
825-
(event, { base64ByteStream, subtitles, title, clipNumber, game }) => {
833+
(event, { videoSource, subtitles, title, clipNumber, game }) => {
826834
console.log(
827835
`STORING ${title}-${clipNumber} for game ${game} with subtitles ${subtitles}`
828836
);
@@ -849,10 +857,7 @@ ipcMain.handle(
849857

850858
console.log('SAVING TO ' + videoFilePath + '\n' + subFilePath);
851859

852-
fs.writeFileSync(
853-
videoFilePath,
854-
Buffer.from(base64ByteStream, 'base64')
855-
);
860+
fs.copyFileSync(videoSource.replace("localfile://", ""), videoFilePath);
856861
fs.writeFileSync(subFilePath, subtitles);
857862

858863
return baseFileName;
@@ -1031,6 +1036,17 @@ ipcMain.handle('openDialog', async () => {
10311036
}
10321037
});
10331038

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+
10341050
ipcMain.handle('setActive', async (event, { id, game, isActive }) => {
10351051
console.log('TOGGLING ' + id + ' in game ' + game + ' to ' + isActive);
10361052

src/main/preload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ contextBridge.exposeInMainWorld('api', {
3030
'exportCollection',
3131
'setActive',
3232
'openDialog',
33+
'openVideoFile',
3334
'importZip',
3435
];
3536
if (validChannels.includes(channel)) {

src/renderer/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { interstitialAtom } from './atoms/interstitial.atom';
2727
import './App.css';
2828
import 'react-toastify/dist/ReactToastify.css';
2929

30-
const VERSION = 'v1.3.1-alpha-preview';
30+
const VERSION = 'v1.4.0-beta';
3131

3232
let App = (props) => {
3333
const navigate = useNavigate();

src/renderer/api/VideoAPI.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ const storeTempVideo = async (videoArrayBuffer, type) => {
22
return await window.api.send('storeTempVideo', {videoArrayBuffer , type});
33
};
44

5+
const getVideoFile = async () => {
6+
return await window.api.send('openVideoFile');
7+
};
8+
59
export default {
6-
storeTempVideo
10+
storeTempVideo,
11+
getVideoFile
712
};

src/renderer/routes/VideoView.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let VideoView = (props) => {
2727
<div>Name: {videoDetails.name}</div>
2828
<div>
2929
<WhatTheDubPlayer
30-
videoSource={`app://${params.game}/${params.id}.mp4`}
30+
videoSource={`game://${params.game}/${params.id}.mp4`}
3131
isPlaying={false}
3232
videoPosition={0}
3333
subs={convertSrtToSubtitles(videoDetails.srtBase64)}

src/renderer/routes/editor/AdvancedEditor.jsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ let AdvancedEditor = () => {
7777
}
7878
);
7979
let { clip, video, title, clipNumber } = batchClip;
80-
setVideoSource("app://batch.tmp.mp4");
80+
console.log("DOG WATER: " + video);
81+
setVideoSource(video);
8182
setVideoLength((clip.endTime - clip.startTime) / 1000);
8283
setBatchClip(batchClip);
8384
setStartTime(clip.startTime);
@@ -87,23 +88,9 @@ let AdvancedEditor = () => {
8788
setCurrentPosition(clip.startTime / 1000);
8889
};
8990

90-
let onFileOpen = (e) => {
91-
let f = e.target.files[0];
92-
let fr = new FileReader();
93-
handleInterstitial(
94-
new Promise((resolve, reject) => {
95-
fr.onload = async () => {
96-
let url = await VideoAPI.storeTempVideo(fr.result, "clip");
97-
console.log("URL: " + url);
98-
setVideoSource(url);
99-
resolve();
100-
};
101-
}),
102-
(isOpen) => {
103-
setInterstitialState({ isOpen, message: 'Loading Video...' });
104-
})
105-
106-
fr.readAsArrayBuffer(f);
91+
let onFileOpen = async () => {
92+
let filePath = await VideoAPI.getVideoFile();
93+
setVideoSource(`localfile://${filePath}`);
10794
};
10895

10996
let convertSecondsToTimestamp = (seconds) => {
@@ -142,7 +129,7 @@ let AdvancedEditor = () => {
142129
try {
143130
setButtonsDisabled(true);
144131
let videoId = await addVideo(
145-
videoSource.substring(videoSource.indexOf(',') + 1),
132+
videoSource,
146133
subs,
147134
videoName,
148135
clipNumber,
@@ -333,7 +320,7 @@ let AdvancedEditor = () => {
333320
length you want it. However you can use batch mode if
334321
you want to cut up your video into smaller pieces.
335322
</p>
336-
<input type="file" accept=".mp4" onChange={onFileOpen} />
323+
<button onClick={onFileOpen}>Open Video</button>
337324
<Link to="/">
338325
<button type="button">Cancel</button>
339326
</Link>

src/renderer/routes/editor/ClipCutter.jsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,9 @@ let ClipCutter = () => {
5353
setWindowSize({ width: window.innerWidth, height: window.innerHeight });
5454
};
5555

56-
let onFileOpen = (e) => {
57-
let f = e.target.files[0];
58-
let fr = new FileReader();
59-
60-
handleInterstitial(
61-
new Promise((resolve, reject) => {
62-
fr.onload = async () => {
63-
let url = await VideoAPI.storeTempVideo(fr.result, "batch");
64-
setVideoSource(url);
65-
resolve();
66-
};
67-
}),
68-
(isOpen) => {
69-
setInterstitialState({ isOpen, message: 'Loading Video...' });
70-
}
71-
);
72-
73-
fr.readAsArrayBuffer(f);
56+
let onFileOpen = async () => {
57+
let filePath = await VideoAPI.getVideoFile();
58+
setVideoSource(`localfile://${filePath}`);
7459
};
7560

7661
let convertSecondsToTimestamp = (seconds) => {
@@ -226,7 +211,7 @@ let ClipCutter = () => {
226211
<p>
227212
Please choose the video you wish to create clips from.
228213
</p>
229-
<input type="file" accept=".mp4" onChange={onFileOpen} />
214+
<button onClick={onFileOpen}>Open Video</button>
230215
<Link to="/">
231216
<button type="button">Cancel</button>
232217
</Link>

src/renderer/util/VideoTools.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export let createWebVttDataUri = (subtitles, substitution, offset = 0) => {
139139
};
140140

141141
export let addVideo = async (
142-
base64ByteStream,
142+
videoSource,
143143
subtitles,
144144
title,
145145
clipNumber = 1,
@@ -148,14 +148,15 @@ export let addVideo = async (
148148
) => {
149149
if (isBatch) {
150150
return await window.api.send('processBatchClip', {
151+
videoSource,
151152
subtitles: convertSubtitlesToSrt(subtitles, type),
152153
title,
153154
clipNumber,
154155
game: type,
155156
});
156157
}
157158
return await window.api.send('storeVideo', {
158-
base64ByteStream,
159+
videoSource,
159160
subtitles: convertSubtitlesToSrt(subtitles, type),
160161
title,
161162
clipNumber,

0 commit comments

Comments
 (0)