Skip to content

Commit

Permalink
cross-platform live preview
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptofuture committed Feb 13, 2019
1 parent 18948d8 commit 529e8b3
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 33 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Control recording
* Control and display camera live preview
* Camera live preview using [hydra](https://github.com/gnd/hydra) (Linux only)
* Control shooting
* Save pictures
* Control various request values
Expand Down Expand Up @@ -33,11 +34,7 @@ Package name: hx50ripper

### Preferences

You can set most preferences using Settings Menu in HX50 Photo Ripper. But you need to preset envs for [hydra](https://github.com/gnd/hydra). Hydra used for Live Preview Window and works only in Linux.

Export liveview path for ex.: `export CAM_LV="http://10.0.0.1:60152"`

Export save folder path for ex.: `export SAVE_LV="/mnt/LV/sony_%05d.jpeg"`
You can set most preferences using Settings Menu in HX50 Photo Ripper.

### How It Works

Expand All @@ -52,10 +49,10 @@ You can check [light version](https://github.com/cryptofuture/hx50ripper/tree/ma
* `actions.stopMovieRec` - Stops Recording
* `setShootMode` - Switch Shoot Mode

Live Preview Window works using [hydra](https://github.com/gnd/hydra)

### Building Cross-platform Releases

First activate submodule with `git submodule init` and `git submodule update`

Use `npm run prod` for Windows >= 7 and macOS, `npm run prod-xp` for Windows XP binaries, and `npm run prod-linux` for Linux binaries

### Donation
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"scripts": {
"dev": "nw src/",
"prod": "nwbuild --platforms win32,win64,osx64 --buildDir dist/ src/",
"prod-linux": "nwbuild --platforms linux32,linux64 --buildDir dist/ src/ && cp -R src/bin/ dist/hx50ripper/linux64/ && cp -R src/bin/ dist/hx50ripper/linux32/",
"prod-xp": "nwbuild --platforms win32,win64 --version 0.14.7 --buildDir dist-xp/ src/"
"prod": "nwbuild --platforms win32,win64,osx64 --buildDir dist/ src/ && cp -R src/bin/liveView/liveView/win32/liveView/ dist/hx50ripper/win32/bin/ && cp -R src/bin/liveView/liveView/win32/liveView/ dist/hx50ripper/win64/bin/ && rm -rf dist/hx50ripper/osx64/hx50ripper.app/Contents/Resources/app.nw/bin/ && cp -R src/bin/liveView/liveView/osx64/liveView/ dist/hx50ripper/osx64/hx50ripper.app/Contents/Resources/app.nw/bin/",
"prod-linux": "nwbuild --platforms linux32,linux64 --buildDir dist/ src/ && cp -R src/bin/liveView/liveView/linux64/liveView/ dist/hx50ripper/linux64/bin/ && cp src/bin/hydra-x64 dist/hx50ripper/linux64/bin/ && cp -R src/bin/liveView/liveView/linux32/liveView/ dist/hx50ripper/linux32/bin/ && cp src/bin/hydra-x32 dist/hx50ripper/linux32/bin/",
"prod-xp": "nwbuild --platforms win32,win64 --version 0.14.7 --buildDir dist-xp/ src/ && cp -R src/bin/liveView/liveView/win32/liveView/ dist-xp/hx50ripper/win32/bin/ && cp -R src/bin/liveView/liveView/win32/liveView/ dist-xp/hx50ripper/win64/bin/"
}
}
96 changes: 80 additions & 16 deletions src/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,34 @@ const fs = require('fs-extra');
const path = require('path');
const os = require('os');
const platform = os.platform();
const exec = require('child_process').exec;

if (platform.includes("win32")) {
var hxripper = process.env.APPDATA + '\\hxripper';
var configFolderHome = hxripper + '\\config';
var settingsFile = configFolderHome + '\\settings.json';
var homeFolder = process.env.APPDATA;
} else if (platform.includes("darwin")) {
var hxripper = process.env.HOME + '/Library/hxripper';
var configFolderHome = hxripper + '/config';
var settingsFile = configFolderHome + '/settings.json';
var homeFolder = process.env.HOME;
} else if (platform.includes("linux")) {
var hxripper = process.env.HOME + "/.hxripper";
var configFolderHome = hxripper + '/config';
var settingsFile = configFolderHome + '/settings.json';
var homeFolder = process.env.HOME;
}

const lang = require('../app/lang');
const settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
if (settings.savePictureLocation == "") {
var savePicLocation = path.normalize(homeFolder + '/') + (new Date().toISOString() + '.jpg').split(':').join('-');
var saveLivePicLocation = path.normalize(homeFolder + '/');
} else {
var savePicLocation = path.normalize(settings.savePictureLocation + '/') + (new Date().toISOString() + '.jpg').split(':').join('-');
var saveLivePicLocation = path.normalize(settings.savePictureLocation + '/');
}
const iconPath = 'file://' + nw.__dirname + '/assets/icon.png';
var mRequestId = 1;

Expand All @@ -42,16 +53,6 @@ function setShootMode(mode) {
module.exports = {
actTakePicture: function () {
setShootMode("still");
if (platform.includes("win32")) {
var homeFolder = process.env.APPDATA;
} else {
var homeFolder = process.env.HOME;
}
if (settings.savePictureLocation == "") {
var savePicLocation = path.normalize(homeFolder + '/') + (new Date().toISOString() + '.jpg').split(':').join('-');
} else {
var savePicLocation = path.normalize(settings.savePictureLocation + '/') + (new Date().toISOString() + '.jpg').split(':').join('-');
}
const options = {
uri: settings.cameraUrl,
timeout: settings.connectionTimeout,
Expand Down Expand Up @@ -111,6 +112,63 @@ module.exports = {
method: 'POST',
json: true
};
if (settings.liveViewUrl == undefined) {
var liveViewUrl = 'http://10.0.0.1:60152';
} else {
var liveViewUrl = settings.liveViewUrl;
}
request(options, function (error, response, body) {
//console.log(body.result[0]);
try {
if (typeof body.result == 'undefined') {
alert("Connection was successful, but camera returned error");
} else {
if (platform.includes("win32")) {
process.env.CAM_LV = liveViewUrl;
exec((process.execPath).slice(0, -15) + '\\bin\\liveView.exe');
const alert = {
icon: iconPath,
body: lang.echo("Live preview started")
};
new Notification(lang.echo("Live preview activated"), alert);
} else if (platform.includes("darwin")) {
process.env.CAM_LV = liveViewUrl;
exec(global.__dirname + '/bin/liveView');
const alert = {
icon: iconPath,
body: lang.echo("Live preview started")
};
new Notification(lang.echo("Live preview activated"), alert);
} else if (platform.includes("linux")) {
process.env.CAM_LV = liveViewUrl;
exec((process.execPath).slice(0, -11) + '/bin/liveView');
const alert = {
icon: iconPath,
body: lang.echo("Live preview started")
};
new Notification(lang.echo("Live preview activated"), alert);
}
}
} catch (e) {
if (e) {
alert(lang.echo("Connection timeout.\nCheck Wi-Fi connection and/or Camera URL settings"));
}
}
});
},
startLiveHydra: function () {
const options = {
uri: settings.cameraUrl,
timeout: settings.connectionTimeout,
body: { "method": "startLiveview", "params": [], "id": id(), "version": "1.0" },
method: 'POST',
json: true
};
if (settings.liveViewUrl == undefined) {
var liveViewUrl = 'http://10.0.0.1:60152';
} else {
var liveViewUrl = settings.liveViewUrl;
}
request(options, function (error, response, body) {
//console.log(body.result[0]);
try {
Expand All @@ -130,10 +188,13 @@ module.exports = {
};
new Notification(lang.echo("Live preview activated"), alert);
} else if (platform.includes("linux")) {
liveViewUrl = liveViewUrl.replace('http://', '');
var newSaveLivePicLocation = saveLivePicLocation + path.normalize(new Date().toISOString().split(':').join('-') + '/');
fs.mkdirSync(newSaveLivePicLocation);
if (process.arch == "x64") {
require('child_process').exec((process.execPath).slice(0, -11) + '/bin/hydra-x64 --primary-res 640x480');
exec((process.execPath).slice(0, -11) + '/bin/hydra-x64 --primary-res 640x480 --cam-link ' + liveViewUrl + ' --save-file sony_%05d.jpeg --save-dir ' + newSaveLivePicLocation);
} else {
require('child_process').exec((process.execPath).slice(0, -11) + '/bin/hydra-x64 --primary-res 640x480');
exec((process.execPath).slice(0, -11) + '/bin/hydra-x32 --primary-res 640x480 --cam-link ' + liveViewUrl + ' --save-file sony_%05d.jpeg --save-dir ' + newSaveLivePicLocation);
}
const alert = {
icon: iconPath,
Expand Down Expand Up @@ -164,27 +225,30 @@ module.exports = {
alert(lang.echo("Connection was successful, but camera returned error"));
} else {
if (platform.includes("win32")) {
exec('taskkill /F /IM liveView.exe');
const alert = {
icon: iconPath,
body: lang.echo("Live preview stopped")
};
new Notification(lang.echo("Live preview deactivated"), alert);
} else if (platform.includes("darwin")) {
exec('killall -9 liveView');
const alert = {
icon: iconPath,
body: lang.echo("Live preview stopped")
};
new Notification(lang.echo("Live preview deactivated"), alert);
} else if (platform.includes("linux")) {
var killAll = require('child_process');
if (process.arch == "x64") {
killAll.exec('killall -15 hydra-x64');
exec('killall -9 liveView');
exec('killall -15 hydra-x64');
} else {
killAll.exec('killall -15 hydra-x32');
exec('killall -9 liveView');
exec('killall -15 hydra-x32');
}
const alert = {
icon: iconPath,
body: lang.echo("hydra was terminated")
body: lang.echo("Live preview stopped")
};
new Notification(lang.echo("Live preview process terminated"), alert);
}
Expand Down
17 changes: 17 additions & 0 deletions src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if (platform.includes("darwin")) {
}

let mSLP = lang.echo('Start Live Preview');
let mHydra = lang.echo('Start Live Preview via Hydra');
let mFLP = lang.echo('Stop Live Preview');
let mQuit = lang.echo('Quit');
let mPreview = lang.echo('Preview');
Expand All @@ -55,6 +56,7 @@ let mSR = lang.echo('Configure Shooting Response');
let mRR = lang.echo('Configure Recording Response');
let mTimeout = lang.echo('Configure Request Timeout');
let mSCURL = lang.echo('Set Camera URL');
let mliveView = lang.echo('Set Live Preview URL');
let mISC = lang.echo('Image Saving Configuration');
let mSettings = lang.echo('Settings');
let mCGHI = lang.echo('Create New GitHub Issue');
Expand All @@ -71,6 +73,15 @@ preview.append(new nw.MenuItem({
actions.startLive();
}
}));
if (platform.includes("linux")) {
preview.append(new nw.MenuItem({
label: mHydra,
click: function () {
actions.startLiveHydra();
}
}));
} else {
}
preview.append(new nw.MenuItem({
label: mFLP,
key: 'l',
Expand Down Expand Up @@ -168,6 +179,12 @@ settings.append(new nw.MenuItem({
prefs.cameraUrlWindow();
}
}));
settings.append(new nw.MenuItem({
label: mliveView,
click: function () {
prefs.liveViewUrlWindow();
}
}));
settings.append(new nw.MenuItem({
label: mISC,
click: function () {
Expand Down
26 changes: 26 additions & 0 deletions src/app/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ module.exports = {
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2), 'utf-8');
alert(lang.echo("Camera URL is: ") + settings.cameraUrl + lang.echo(" (default)"));
},
setLiveViewUrl: function () {
settings.liveViewUrl = global.liveViewUrl;
if (global.liveViewUrl.startsWith("http")) {
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2), 'utf-8');
alert(lang.echo("Live Preview URL is: ") + global.liveViewUrl);
}
else {
alert(lang.echo("Doesn't look like valid Live Preview URL"));
}
},
liveViewUrlWindow: function () {
gui.Window.open('views/liveViewUrl.html', {
focus: true,
position: 'center',
width: 800,
height: 600
});
},
showCurrentLiveViewUrl: function () {
alert(settings.liveViewUrl);
},
setLiveViewUrlDefault: function () {
settings.liveViewUrl = 'http://10.0.0.1:60152';
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2), 'utf-8');
alert(lang.echo("Live Preview URL is: ") + settings.liveViewUrl + lang.echo(" (default)"));
},
setShootingResponse: function () {
settings.takePictureResponse = global.shootingResponse;
if (isPositiveInteger(global.shootingResponse) == true) {
Expand Down
1 change: 1 addition & 0 deletions src/app/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cameraUrl": "http://10.0.0.1:10000/camera",
"liveViewUrl": "http://10.0.0.1:60152",
"takePictureResponse": 1200,
"recMovieResponse": 1000,
"autoSavePicture": true,
Expand Down
Binary file added src/assets/hydra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/bin/hydra-x32
Binary file not shown.
Binary file modified src/bin/hydra-x64
Binary file not shown.
10 changes: 8 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"Live preview started, but hydra not supported": "Live preview started, but hydra not supported",
"Configure Request Timeout": "Configure Request Timeout",
"Request Timeout Configuration": "Request Timeout Configuration",
"For ex.: 8000 (8 seconds)": "For ex.: 8000 (8 seconds)"

"For ex.: 8000 (8 seconds)": "For ex.: 8000 (8 seconds)",
"Live Preview URL is: ": "Live Preview URL is: ",
"Live Preview URL": "Live Preview URL",
"Live Preview URL Configuration": "Live Preview URL Configuration",
"For ex.: http://10.0.0.1:60152": "For ex.: http://10.0.0.1:60152",
"Set Live Preview URL": "Set Live Preview URL",
"Live preview started": "Live preview started",
"Start Live Preview via Hydra": "Start Live Preview via Hydra"
}
9 changes: 8 additions & 1 deletion src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,12 @@
"Live preview started, but hydra not supported": "Пред. просмотр запущен, но hydra не поддерживается",
"Configure Request Timeout": "Настройка timeout запроса",
"Request Timeout Configuration": "Настройка timeout запроса",
"For ex.: 8000 (8 seconds)": "Например: 8000 (8 секунд)"
"For ex.: 8000 (8 seconds)": "Например: 8000 (8 секунд)",
"Live Preview URL is: ": "URL пред. просмотра: ",
"Live Preview URL": "URL пред. просмотра",
"Live Preview URL Configuration": "Настройка URL пред. просмотра",
"For ex.: http://10.0.0.1:60152": "Например: http://10.0.0.1:60152",
"Set Live Preview URL": "Изменить URL пред. просмотра",
"Live preview started": "Пред. просмотр запущен",
"Start Live Preview via Hydra": "Начать пред. просмотр в Hydra"
}
8 changes: 4 additions & 4 deletions src/styles/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ body {
margin-left: 408px;
}
#recordingControl {
margin-top: 55px;
margin-left: 54px;
margin-top: 55px;
margin-left: 54px;
}
#takePictureControl {
margin-top: 75px;
margin-left: 44px;
margin-top: 75px;
margin-left: 44px;
}
38 changes: 38 additions & 0 deletions src/views/liveViewUrl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../styles/minstyle.io.css"> <!-- https://minstyle.io v0.2.3 -->
<link rel="stylesheet" href="../styles/light.css">
<script src="../app/light.js"></script>
</head>

<body>
<form>
<fieldset>
<div class="col-s-12">
<span class="ms-badge ms-gradient">
<script>echo("Live Preview URL")</script></span>
<input type="url" id="liveViewUrl" class="ms-yellow" style="background-color:#d4ebcd">
</div>
<div class="col-s-12">
<input class="ms-btn ms-yellow ms-large" type="submit" id="set" onclick="global.liveViewUrl = document.getElementById('liveViewUrl').value;prefs.setLiveViewUrl();nw.Window.get().close();">
<a class="ms-btn ms-blue ms-large" onclick="prefs.setLiveViewUrlDefault();nw.Window.get().close();">
<script>echo("Default")</script></a>
<a class="ms-btn ms-green ms-large" onclick="prefs.showCurrentLiveViewUrl();">
<script>echo("Current Value")</script></a>
<a class="ms-btn ms-border-bottom ms-red ms-large" onclick="nw.Window.get().close()">
<script>echo("Cancel")</script></a>
</div>
</fieldset>
</form>
<script>
document.getElementById("set").value = lang.echo("Set");
document.title = lang.echo("Live Preview URL Configuration");
document.getElementById("liveViewUrl").placeholder = lang.echo("For ex.: http://10.0.0.1:60152");
</script>
</body>

</html>

0 comments on commit 529e8b3

Please sign in to comment.