Skip to content

Commit

Permalink
Add --keep and -k flags to the CLI. (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwronski authored Feb 20, 2019
1 parent 2d19fa0 commit 81930b5
Show file tree
Hide file tree
Showing 9 changed files with 701 additions and 664 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.DS_Store
dist
bin
.history
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.ref
.tmp
.DS_Store
.history
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ This utility can recover from most errors, and as such, it will continue to **se

A summary is displayed when the entire batch transcoding operation is finished. The summary includes the overall number of errors encountered and files successfully created.

### Before You Begin

**WARNING:** If the program cannot successfully transcode an input file, and then verify the output video file, it will be marked as _errored_ and the transcoded file (if one exists) will be deleted from the output directory. This is done to prevent partially-transcoded files from remaining in the output directory that then need to be manually deleted before retrying the transcoding operation.

If you run the program using an output directory containing previously-transcoded video, especially for source files that still exist in your input directory, you **must** use the `--diff` option to ensure sucessful transcodes from previous batches are not deleted from the output directory. In `--diff` mode, input files are skipped when their corresponding output files already exist in the output directory.

Alternatively, you can use the `--keep` option to ensure files are never deleted from the output directory, even if they have errors or failed to finish transcoding. However, subsequent runs, with or without using the `--diff` option, will not reprocess failed input files, unless the corresponding output files are manually deleted.

### Instructions

Recursively search for videos to transcode using [video_transcoding](https://github.com/donmelton/video_transcoding). If an `input` **directory** is not specified then the current directory will be used as the input directory.
Expand Down Expand Up @@ -118,6 +126,8 @@ batch.cli();
- Do not preserve relative directory structure in output directory. If this is enabled, the base output folder will contain all transcoded videos. Note: this option has no effect unless you specify an `output` directory.
- `--quiet` _Flag: does not accept a value_ (Default: `false`)
- Prevents **any** logging to stdout and will only exit `0` on success or `1` on error
- `--keep` _Flag: does not accept a value_ (Default: `false`) (Alias: `-k`)
- **Never delete any output files**, no matter what happens, **even if the encoding task fails** for the corresponding input file. If you use this option, input files that fail to encode correctly, or finish encoding, will not be deleted from the output folder. Subsequent runs, with or without using the `--diff` option, will not reprocess the failed input files, unless the corresponding output files are manually deleted.

### Providing options to transcode-video

Expand Down
5 changes: 3 additions & 2 deletions batch-transcode-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ let defs = {
mask: 'm',
help: 'h',
version: 'v',
force: 'f'
force: 'f',
keep: 'k'
},
boolean: [
'debug', 'quiet', 'flatten', 'diff', 'help', 'version'
'debug', 'quiet', 'flatten', 'diff', 'help', 'version', 'keep'
],
string: [
'input', 'output', 'mask', 'force'
Expand Down
2 changes: 1 addition & 1 deletion index-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class CliBatchTranscodeVideo extends BatchTranscodeVideo {
if (file.isRunning) {
file.status = VideoFile.ERRORED;
}
if (file.isErrored) {
if (file.isErrored && this.options['keep'] !== true) {
// Try and delete the destination file if it exists
unlinkSync(file.destFilePath);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
// Output folder
output: null,
// Search pattern for glob in input directory
mask: '**' + path.sep + '*.{mp4,avi,mkv,m4v,ts,mov}',
mask: '**' + path.sep + '*.{mp4,avi,mkv,m4v,ts,mov,vob}',
// Verbose logging
debug: false,
// Do not preserve relative directory structure in output directory
Expand All @@ -17,5 +17,7 @@ export default {
diff: false,
// If crop detection returns multiple values then take the least extreme crop
force: false,
// Never delete any output files, no matter what happens
keep: false,
help: false
};
5 changes: 5 additions & 0 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const args = [
{
arg: 'quiet',
desc: 'Do not log output messages to command line, only exit 0 if successful or 1 if there are errors. This will disable the progress bars that display the current progress and remaining time estimates and also the summary output (writes, errors, stats) at end of process.'
},
{
arg: 'keep',
desc: 'Never delete any output files, no matter what happens, even if the encoding task fails for the corresponding input file. If you use this option, input files that fail to encode correctly, or finish encoding, will not be deleted from the output folder. Subsequent runs, with or without using the --diff option, will not reprocess the failed input files, unless the corresponding output files are manually deleted.',
alias: 'k'
}
];

Expand Down
Loading

0 comments on commit 81930b5

Please sign in to comment.