-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved selection + queries + regex
- Loading branch information
Luuk
committed
Oct 26, 2021
1 parent
e7067d8
commit 54f0172
Showing
9 changed files
with
182 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
const { app, BrowserWindow, dialog, ipcMain } = require('electron') | ||
const path = require('path') | ||
const { app, BrowserWindow, dialog, ipcMain } = require("electron"); | ||
const path = require("path"); | ||
|
||
function createWindow() { | ||
const win = new BrowserWindow({ | ||
width: 600, | ||
height: 800, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js') | ||
} | ||
}) | ||
const win = new BrowserWindow({ | ||
width: 600, | ||
height: 800, | ||
webPreferences: { | ||
preload: path.join(__dirname, "preload.js"), | ||
}, | ||
}); | ||
|
||
win.loadFile('index.html') | ||
win.webContents.openDevTools({ mode: 'undocked' }) | ||
win.loadFile("index.html"); | ||
win.webContents.openDevTools({ mode: "undocked" }); | ||
|
||
ipcMain.on('select-dirs', async (event, arg) => { | ||
console.log('huuhhhhh') | ||
try { | ||
const result = await dialog.showOpenDialog(win, { | ||
properties: ['openDirectory'], | ||
message: 'hunnnnh' | ||
}) | ||
console.log('directories selected', result.filePaths) | ||
event.reply('dir-selected', result.filePaths[0]) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}) | ||
ipcMain.on("select-dirs", async (event, arg) => { | ||
try { | ||
const result = await dialog.showOpenDialog(win, { | ||
properties: ["openDirectory"], | ||
message: "select output directory", | ||
}); | ||
console.log("directories selected", result.filePaths); | ||
event.reply("dir-selected", result.filePaths[0]); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
} | ||
|
||
app.whenReady().then(() => { | ||
createWindow() | ||
createWindow(); | ||
|
||
app.on('activate', function () { | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow() | ||
}) | ||
}) | ||
app.on("activate", function () { | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | ||
}); | ||
}); | ||
|
||
app.on('window-all-closed', function () { | ||
if (process.platform !== 'darwin') app.quit() | ||
}) | ||
app.on("window-all-closed", function () { | ||
if (process.platform !== "darwin") app.quit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,107 @@ | ||
const movieSampler = require("movie-sampler"); | ||
var open = require("open"); | ||
const { ipcRenderer } = require('electron') | ||
const ffmpegPath = require('ffmpeg-static-electron').path; | ||
|
||
process.once('loaded', () => { | ||
window.addEventListener('message', evt => { | ||
if (evt.data.type === 'select-dirs') { | ||
ipcRenderer.send('select-dirs') | ||
} | ||
}) | ||
}) | ||
|
||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
console.log('hi from preload') | ||
const $ = require("jquery"); | ||
|
||
$(document).on('click', 'a[href^="http"]', function (event) { | ||
event.preventDefault(); | ||
open(this.href); | ||
}); | ||
|
||
const $video = $('#video-input') | ||
const $subs = $('#subs-input') | ||
const $margin = $('#margin-input') | ||
const $offset = $('#offset-input') | ||
const $videoValue = $('#video-value') | ||
const $subsValue = $('#subs-value') | ||
const $outValue = $('#out-value') | ||
const $marginValue = $('#margin-value') | ||
const $offsetValue = $('#offset-value') | ||
|
||
$video.on('change', () => { | ||
const video = $video[0].files[0].path; | ||
$videoValue.text(video) | ||
}) | ||
$subs.on('change', () => { | ||
const subs = $subs[0].files[0].path; | ||
$subsValue.text(subs) | ||
}) | ||
$margin.on('change', () => { | ||
$marginValue.text(`margin: ${$margin.val()} seconds`) | ||
}) | ||
$offset.on('change', () => { | ||
$offsetValue.text(`subtitle offset: ${$offset.val()} seconds`) | ||
}) | ||
|
||
let out = '' | ||
|
||
ipcRenderer.on('dir-selected', (event, arg) => { | ||
console.log('got async reply', arg) | ||
out = arg | ||
$outValue.text(out) | ||
}) | ||
|
||
|
||
$("#form").on("submit", async (e) => { | ||
e.preventDefault(); | ||
|
||
const $button = $("#form-button"); | ||
$button.prop("disabled", true); | ||
|
||
const $output = $("#output"); | ||
$output.text(""); | ||
|
||
const video = $video[0].files[0].path; | ||
const subs = $subs[0].files[0].path; | ||
const margin = $margin.val(); | ||
const offset = $offset.val(); | ||
|
||
const onProcessItem = (sub) => | ||
$output.text(`processing item:\n${JSON.stringify(sub, null, 2)}`); | ||
|
||
try { | ||
console.log({ video, subs, out }) | ||
await movieSampler({ video, subs, out, onProcessItem, ffmpegPath, margin, offset }); | ||
$output.text("done"); | ||
} catch (e) { | ||
console.log(e); | ||
$output.text(e.message); | ||
} | ||
$button.prop("disabled", false); | ||
}); | ||
}) | ||
|
||
const { ipcRenderer } = require("electron"); | ||
const ffmpegPath = require("ffmpeg-static-electron").path; | ||
|
||
process.once("loaded", () => { | ||
window.addEventListener("message", (evt) => { | ||
if (evt.data.type === "select-dirs") { | ||
ipcRenderer.send("select-dirs"); | ||
} | ||
}); | ||
}); | ||
|
||
window.addEventListener("DOMContentLoaded", () => { | ||
console.log("hi from preload"); | ||
const $ = require("jquery"); | ||
|
||
$(document).on("click", 'a[href^="http"]', function (event) { | ||
event.preventDefault(); | ||
open(this.href); | ||
}); | ||
|
||
const $video = $("#video-input"); | ||
const $subs = $("#subs-input"); | ||
const $margin = $("#margin-input"); | ||
const $offset = $("#offset-input"); | ||
const $mode = $("#mode"); | ||
const $query = $("#query-input"); | ||
const $videoValue = $("#video-value"); | ||
const $subsValue = $("#subs-value"); | ||
const $outValue = $("#out-value"); | ||
const $marginValue = $("#margin-value"); | ||
const $offsetValue = $("#offset-value"); | ||
const $modeValue = $("#mode-value"); | ||
|
||
$video.on("change", () => { | ||
const video = $video[0].files[0].path; | ||
$videoValue.text(video); | ||
}); | ||
$subs.on("change", () => { | ||
const subs = $subs[0].files[0].path; | ||
$subsValue.text(subs); | ||
}); | ||
$margin.on("change", () => { | ||
$marginValue.text(`margin: ${$margin.val()} seconds`); | ||
}); | ||
$offset.on("change", () => { | ||
$offsetValue.text(`subtitle offset: ${$offset.val()} seconds`); | ||
}); | ||
$mode.on("change", () => { | ||
const mode = $mode.val(); | ||
$modeValue.text(`subtitle mode: ${mode}`); | ||
if (mode === "normal") { | ||
$query.hide(); | ||
} else { | ||
$query.show(); | ||
} | ||
}); | ||
|
||
let out = ""; | ||
|
||
ipcRenderer.on("dir-selected", (event, arg) => { | ||
out = arg; | ||
$outValue.text(out); | ||
}); | ||
|
||
$("#form").on("submit", async (e) => { | ||
e.preventDefault(); | ||
|
||
const $button = $("#form-button"); | ||
$button.prop("disabled", true); | ||
|
||
const $output = $("#output"); | ||
$output.text(""); | ||
|
||
const video = $video[0].files[0].path; | ||
const subs = $subs[0].files[0].path; | ||
const margin = $margin.val(); | ||
const offset = $offset.val(); | ||
const mode = $mode.val(); | ||
const query = $query.val(); | ||
|
||
const onProcessItem = (sub) => | ||
$output.text(`processing item:\n${JSON.stringify(sub, null, 2)}`); | ||
|
||
try { | ||
await movieSampler({ | ||
video, | ||
subs, | ||
out, | ||
onProcessItem, | ||
ffmpegPath, | ||
margin, | ||
offset, | ||
regex: mode === "regex" ? query : undefined, | ||
query: mode === "query" ? query : undefined, | ||
}); | ||
$output.text("done"); | ||
} catch (e) { | ||
console.log(e); | ||
$output.text(e.message); | ||
} | ||
$button.prop("disabled", false); | ||
}); | ||
}); | ||
|
||
function createControl() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters