Skip to content

Commit

Permalink
Add ability to save cover image with options.coverPath (#19)
Browse files Browse the repository at this point in the history
* Add ability to save cover image with options.coverPath

* Fix for multiline fields - data appended to the last keyed field

* Add info about coverPath to readme

* Define key var

* Edit readme
  • Loading branch information
xidb authored and parshap committed Feb 1, 2018
1 parent c6cb960 commit c0e1e81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ invoked and instead an array of the arguments that *would* have been
used to invoke ffmpeg is returned synchronously. The `callback`
argument is not used in this case.

`options.coverPath`: Option to provide a path, where `ffmpeg` will save cover image. Unfortunately, `ffmpeg` will always convert resulted image, based on extension in provided `coverPath`.

### `ffmetadata.write(file, data, [options], callback)`

Write metadata to `file` and optionally append additional attachments
Expand Down
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports.read = function(src, options, callback) {
options = {};
}

var args = getReadArgs(src);
var args = getReadArgs(src, options);

if (options.dryRun) {
return args;
Expand Down Expand Up @@ -123,7 +123,15 @@ function getTempPath(src) {

// -- Child process helpers

function getReadArgs(src) {
function getReadArgs(src, options) {
if (typeof options.coverPath !== 'undefined' ) {
return [
'-i',
src,
options.coverPath
];
}

return [
"-i",
src,
Expand Down Expand Up @@ -198,10 +206,19 @@ function parseini(callback) {

return stream;

var key;

function parseLine(data) {
data = unescapeini(data);
var index = data.indexOf("=");
stream.data[data.slice(0, index)] = data.slice(index + 1);

if (index === -1) {
stream.data[key] += data.slice(index + 1);
stream.data[key] = stream.data[key].replace('\\', '\n');
} else {
key = data.slice(0, index);
stream.data[key] = data.slice(index + 1);
}
}
}

Expand Down

0 comments on commit c0e1e81

Please sign in to comment.