Skip to content

Commit

Permalink
feat: added add scene on theme
Browse files Browse the repository at this point in the history
Now is possible add a single scene to a OBS theme with all files
  • Loading branch information
salsan committed Jul 16, 2021
1 parent a6b6946 commit 8ffe6b6
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 5 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**otu** ( OBS themes utility ) is [Node.js](https://nodejs.org) script, an handle tool for work with your scenes of Open Broadcaster Software

# Description
otu is an utility to permit to export/import your theme with all files, and many features are added in the next release
otu is an utility to permit to export/import your theme with all files in an archive, add and extract scene from theme, and many features are added in the future

# Installation
```bash
Expand All @@ -11,19 +11,37 @@ npm i otu-tool
# Features
* Export OBS theme scene
* Import OBS theme scene
* Add single scene on OBS theme
* Extract single scene from OBS theme

# Usage

### Export
Create a zip archive (.otu) from scene.json with all files present on scenes

```bash
otu-tool export -i myscene.json -o myscenearchive.otu
otu-tool export -i mytheme.json -o mythemearchive.otu
```
### Import
Extract files from zip archive (.otu) and create scene.json for OBS

```bash
otu-tool import -i mythemearchive.otu -o mytheme.json
```

### Add
Add a single scene to your theme
```bash
otu-tool import -i myscenearchive.otu -o myscene.json
otu-tool add -i mytheme.json --scene myscenearchive.otu -o mynewtheme.json
```

### Extract
Extract single scene from theme
```bash
otu-tool extract -i mytheme.json --scene "NameOfScene" -o myscenearchive.otu
```


# Supported Broadcaster Sofware
* [OBS Studio](https://obsproject.com/)

Expand All @@ -32,7 +50,7 @@ otu-tool import -i myscenearchive.otu -o myscene.json

# Todo
- [ ] Check fonts ~~and install it if is required~~
- [ ] ~~Extract~~/Add single scene of your theme with relative files
- [x] ~~Extract/Add single scene of your theme with relative files~~
- [ ] Convert [Streamlabs OBS](https://streamlabs.com/streamlabs-obs-live-streaming-software) scenes to [OBS Broadcaster Software](https://obsproject.com/)

# License
Expand Down
116 changes: 116 additions & 0 deletions otu.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,126 @@ yargs(hideBin(process.argv))
return false;
}
})
.command('add [scene] [input] [output]', 'add scene to theme', {
input: {
description: 'insert path of theme want to add scene',
alias: 'i',
demandOption: true,
type: 'string',
requiresArg: true,
},
output: {
description: 'insert path where save new theme',
alias: 'o',
type: 'string',
requiresArg: true
},
scene: {
description: 'insert path of scene want add',
alias: 's',
type: 'string',
requiresArg: true
}
},
(argv) => {
if (fs.existsSync(argv.input)) {
addScene(argv.input, argv.output, argv.scene, argv);
} else {
console.log(argv.input + "file doesn't exist")
return false;
}
})
.help()
.alias('help', 'h')
.alias('version', 'v')
.argv;

/**
* @description addScene add scene to theme
* @param {string} fsource - source file
* @param {string} fdest - destination file
* @param {string} sceneName - name of scene archive want add
* @param {Object} options - Options
*/

function addScene(fsource, fdest, sceneArchive, options) {

fs.readFile(fsource, 'utf8', (err, data) => {
const zip = new Archive(sceneArchive);
const scene = JSON.parse(zip.getEntry('scene.json').getData().toString("utf8"));
const theme = JSON.parse(data);
const currentDir = path.dirname(fdest);
const fontDir = process.env.LOCALAPPDATA + '\\Microsoft\\Windows\\Fonts\\';

theme.scene_order.push({
"name": theme.name
});

scene.sources.forEach(src => {

if (typeof(src.settings.files) !== 'undefined') {
src.settings.files.forEach((item, index) => {
if ((fs.statSync(item.value).isFile()) && (zip.getEntry('files/' + path.win32.basename((item.value))))) {
zip.extractEntryTo("files/" + path.win32.basename(item.value), currentDir, true, true);
} else zip.extractEntryTo("files/" + path.win32.basename(item.value) + "/", currentDir, true, true);

src.settings.files[index].value = path.resolve(currentDir, 'files', path.win32.basename(src.settings.files[index].value));
})
}

if ((typeof(src.settings.file) !== 'undefined') && (zip.getEntry('files/' + path.win32.basename(src.settings.file)))) {
src.settings.file = path.resolve(currentDir, 'files', path.win32.basename(src.settings.file));
zip.extractEntryTo('files/' + path.win32.basename(src.settings.file), currentDir, true, true);
}

if ((typeof(src.settings.custom_font) !== 'undefined') && (zip.getEntry('files/' + path.win32.basename(src.settings.custom_font)))) {
let fontPath = fontDir + path.win32.basename(src.settings.custom_font);
src.settings.custom_font = fontPath;

if (!fs.existsSync(fontPath)) {
zip.extractEntryTo('files/' + path.win32.basename(src.settings.custom_font), fontDir, false, false);

let font = openType.loadSync(fontPath);
let fontFamilyName = font["tables"]["name"]["fontFamily"]["en"] + ' (TrueType)';
let strReg = 'reg add "HKCU\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" /v ' + '"' + fontFamilyName + '"' + ' /t REG_SZ /d ' + '"' + fontPath + '"' + ' /f';

const result = exec(strReg, (error, stdout, stderr) => {

if (error) {
console.error(`error: ${error.message}`);
return;
}

if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}

console.log(`stdout:\n${stdout}`);
})
} else console.log("File exist : " + fontPath);


}

if (typeof(src.settings.local_file) !== 'undefined') {
src.settings.local_file = path.resolve(currentDir, 'files', path.win32.basename(src.settings.local_file));
zip.extractEntryTo("files/" + path.win32.basename(src.settings.local_file), currentDir, true, true);
}

theme.sources.push(src);
});

fdest = fdest || theme.name;
fs.writeFile(fdest + '.json', JSON.stringify(theme), function(err) {
if (err) return console.log(err);
console.log('Completed!!! ==> ' + fdest + '.json');
return;
});

});

}
/**
* @description checkItemsRequired check all items required from scene
* @param {Object} theme - full source of original theme
Expand Down Expand Up @@ -180,6 +295,7 @@ function extractScene(fsource, fdest, sceneName, options) {

}

fdest = fdest || scene.name;
zip.addFile("scene.json", Buffer.from(JSON.stringify(scene), "utf8"));
zip.writeZip(fdest + ".otu");
console.log('Completed!!! ' + fdest + '.otu');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"keywords": [
"OBS",
"utility",
"tool"
"tool",
"cli"
],
"author": "Salvatore Santagati [email protected]",
"license": "GPL-3.0-or-later",
Expand Down

0 comments on commit 8ffe6b6

Please sign in to comment.