diff --git a/src/main.ts b/src/main.ts index 77e11d1..04c4d18 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ import { BrowserWindow, app, dialog, ipcMain } from "electron"; -import { unlink, statSync } from "fs"; +import { statSync, unlink } from "fs"; +import { getNewFilename, getVideoDuration } from "./utils/misc"; import path = require("path"); import ffmpegPath = require("ffmpeg-static"); -import ffprobe = require("ffprobe-static"); import child_process = require("child_process"); const moviesFilter = { @@ -28,19 +28,6 @@ const createWindow = () => { return win; }; -/* Create a new filename from the OG one */ -const getNewFilename = (ogFile: string, part: string) => { - const oldFile = path.parse(ogFile); - return path.join(oldFile.dir, `${part}`.concat(oldFile.base)); -}; - -/** Return the duration of a video in second */ -const getVideoDuration = (file: string) => { - const command = `${ffprobe.path} -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${file}"`; - const durationString = child_process.execSync(command).toString().trim(); - return parseFloat(durationString); -}; - /** Merge all audios track of a video into one */ const mergeAudio = (file: string) => { const tmp_file = getNewFilename(file, "TMP_"); diff --git a/src/utils/misc.ts b/src/utils/misc.ts new file mode 100644 index 0000000..a55fb05 --- /dev/null +++ b/src/utils/misc.ts @@ -0,0 +1,16 @@ +import ffprobe = require("ffprobe-static"); +import child_process = require("child_process"); +import path = require("path"); + +/* Create a new filename from the OG one */ +export const getNewFilename = (ogFile: string, part: string) => { + const oldFile = path.parse(ogFile); + return path.join(oldFile.dir, `${part}`.concat(oldFile.base)); +}; + +/** Return the duration of a video in second */ +export const getVideoDuration = (file: string) => { + const command = `${ffprobe.path} -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${file}"`; + const durationString = child_process.execSync(command).toString().trim(); + return parseFloat(durationString); +};