Improve and fix issue in audioconv
module
#40
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This pull request addresses several issues and enhancements within the
audioconv
module. The focus is on improving the reliability of theffmpeg
binary check, ensuring consistent error logging even when thequiet
option is enabled, and enhancing the JSDoc documentation for better clarity and maintainability.Changes Made
Fixes
Improvement to
ffmpeg
Binary Check and Error Handlingexec
call to check theffmpeg
version, replacing it with the more reliablespawnSync
approach, which prevents asynchronous issues and race conditions.FFMPEG_PATH
, adding checks to ensure it is neithernull
norundefined
before proceeding with the binary check.splitOptions
function to properly handle options that do not have associated values, ensuring that they are not accidentally concatenated with the next option in the list.ffmpeg
check, making the logging process clearer and more consistent.Ensuring Error Logging Works with
quiet
Option EnabledwriteErrorLog
function to return a promise, improving the handling of errors during the log-writing process.convertAudio
function to ensure that error logs are still written even when thequiet
option is enabled, improving reliability in quiet modes.quiet
option to provide better control over the reporting process.finish
and properly rejects onerror
, enhancing the reliability of the logging process.Documentation Updates
Enhancements to JSDoc Documentation and Type Definitions
inputOptions
andoutputOptions
fields within theConvertAudioOptions
typedef, improving the clarity of the optional parameters and their usage.FFmpegInfo
typedef to document the progress data emitted by FFmpeg during the conversion process, aiding in better understanding and usage of theprogress
event.writeErrorLog
function, providing detailed documentation on the format of error logs, and specifying that the function now returns a Promise.resolveOptions
function’s JSDoc to include a module reference, improving the overall documentation structure and accessibility.createConversionProgress
, detailing the function’s parameters and return values, and ensuring that it is correctly documented for future use.defaultOptions
object as readonly in the documentation, clearly defining its role in the conversion process and preventing unintended modifications.Fixed Issue
Example Issue with
splitOptions
Before FixBefore the fix, when an option was provided without a corresponding value, it could get concatenated with the next option, leading to incorrect behavior:
Expected output:
Actual output before fix:
In this case,
-f
and-acodec
get concatenated, leading to an invalid option.Example Corrected Behavior After Fix
After the fix,
splitOptions
correctly handles options without values, ensuring they remain separate:Correct output:
Now, each option is treated as an individual entry, preserving the integrity of the options passed to FFmpeg.
Impact
audioconv
module, addressing key issues that could lead to unreliable behavior in production environments.