Skip to content

Commit

Permalink
improved selection + queries + regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Luuk committed Oct 26, 2021
1 parent e7067d8 commit 54f0172
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 129 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Movie Sampler Electron

Electron UI for [movie-sampler](https://github.com/luukschipperheyn/movie-sampler)
Movie Sampler extracts sound effects from movies based on subtitle files
that have noise captions. It just samples the movie audio whenever the
subtitles say something in square brackets, parentheses or all caps like
[alarm beeping] or (agonized grunts) or INDISTINCT CHATTER.

![screenshot](./assets/screenshot.png)

Expand Down
6 changes: 3 additions & 3 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<h1>Movie Sampler</h1>
<p>
Movie Sampler extracts sound effects from movies based on subtitle files
that have captions for noises using [square brackets]. It just samples the
movie audio whenever the subtitles say something in square brackets, like
[alarm beeping] or [agonized grunts].
that have noise captions. It just samples the movie audio whenever the
subtitles say something in square brackets, parentheses or all caps like
[alarm beeping] or (agonized grunts) or INDISTINCT CHATTER.
</p>
<p>
Made by Luuk Schipperheijn <br />
Expand Down
Binary file modified assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,22 @@ <h1>Movie Sampler</h1>
id="offset-input"
value="0"
/>
<div class="input-value ltr" id="offset-value">subtitle offset: 0 seconds</div>
<div class="input-value ltr" id="offset-value">
subtitle offset: 0 seconds
</div>
</div>
</div>
<div class="row">
<div class="input-container--column">
<select id="mode">
<option value="normal">normal</option>
<option value="query">query</option>
<option value="regex">regex</option>
</select>
<div class="input-value ltr" id="mode-value">mode: normal</div>
</div>
<div class="input-container--column">
<input type="text" name="query-input" id="query-input" />
</div>
</div>
<button type="submit" id="form-button">go</button>
Expand Down
63 changes: 31 additions & 32 deletions main.js
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();
});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "movie-sampler",
"main": "main.js",
"version": "1.2.0",
"version": "1.3.0",
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"ffmpeg-static-electron": "^2.0.3",
"jquery": "^3.6.0",
"movie-sampler": "^1.5.2",
"movie-sampler": "^1.6.1",
"open": "^8.3.0"
},
"devDependencies": {
Expand Down Expand Up @@ -50,4 +50,4 @@
]
}
}
}
}
189 changes: 105 additions & 84 deletions preload.js
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() {}
17 changes: 16 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ button {
.row {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
}

.input-container--column {
margin-right: 16px;
flex: 1;
}

.input-container--column:last-of-type {
Expand All @@ -154,4 +156,17 @@ button {

pre {
overflow-x: auto;
}
}

select {
padding: 8px 4px;
background: black;
color: white;
border: 1px solid white;
font-size: 18px;
width: 100%;
}

#query-input {
display: none;
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2455,10 +2455,10 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

movie-sampler@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/movie-sampler/-/movie-sampler-1.5.2.tgz#1a25ba4e12ddc4186f9a297cb5b22375931230af"
integrity sha512-LFA8tilztHjtat8cOOnIy9V1i/EGX8B+MYATxyfvN1VIX8eJ0a9XKo3IXOC4mgkNvoOP21qFvMkSwBgMoTbGBg==
movie-sampler@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/movie-sampler/-/movie-sampler-1.6.1.tgz#791ca1d7a77b481f424d9cb6d652f6d685b589bc"
integrity sha512-QB8Jzw0oK6G/njppqd9rMGDooJkCPnzyjneLtGkIqrF12qgS8xGdnKGKySEETGNg8d2Jsj2nt0+YBbiI0WJvcQ==
dependencies:
command-line-args "^5.2.0"
command-line-usage "^6.1.1"
Expand Down

0 comments on commit 54f0172

Please sign in to comment.