Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance CLI with custom FFmpeg I/O options and improved logging #30

Merged
merged 7 commits into from
Aug 20, 2024

Conversation

mitsuki31
Copy link
Owner

@mitsuki31 mitsuki31 commented Aug 20, 2024

Overview

This pull request introduces new command-line options for audio conversion, enhances error logging capabilities, and refactors several utility functions within the project. The improvements aim to provide users with greater flexibility when using FFmpeg options, while also ensuring better error handling and logging mechanisms.

Notable Changes

New Features

  • Audio Conversion Options:

    • Added the ability to specify custom FFmpeg input and output options via new command-line arguments. This change empowers users to fine-tune their audio conversion processes according to specific needs.
  • Logging Enhancements:

    • Introduced a new helper function for log file creation, allowing more consistent log management.
    • Added a dedicated error logging function during the audio conversion process to ensure that errors are properly recorded and accessible for troubleshooting.

Refactoring

  • Refactored the createLogFile function to the utils module, centralizing the log file creation process and removing redundant code from the ytmp3 module.
  • Improved the FFmpeg checker to issue warnings only if the FFMPEG_PATH environment variable is set and not empty.

Testing

  • Updated test suites to include the new audio conversion options and improved the FFmpeg checker tests for more comprehensive coverage.

Summary

This update brings more flexibility to the command-line interface by introducing new options that allow users to specify custom FFmpeg input and output parameters. Enhanced logging and error handling functionalities improve the overall user experience by making the software more reliable and easier to debug. Key changes include the addition of inputOptions and outputOptions, along with the refactoring of logging mechanisms to the utils module.


New Command-Line Options

Option Name Aliases Description
--input-options --inputOptions, --addInputOptions, --add-input-options, --inOpt Specifies custom FFmpeg input options for audio conversion.
--output-options --outputOptions, --addOptions, --add-options, --addOutputOptions, --add-output-options, --outOpt Specifies custom FFmpeg output options for audio conversion.

These options allow users to customize how input files are processed and how output files are generated, offering more granular control over the audio conversion process.

Warning

Using any of these I/O options will take precedence over the other audio conversion options (e.g., --bitrate, --frequency, etc).

But you can still specify the output format or file extension using --format flag by combining them, like this:

ytmp3 <URL> -o ~/Downloads -C --format opus --output-options "-acodec libopus -ar 28000"

Example Usage

Syntaces

--input-options "<option> <value>..."
--output-options "<option> <value>..."

ytmp3 <URL> -C --output-options "-ar 48000 -b:a 238k"

This above command equivalent to:

ytmp3 <URL> -C --frequency 48000 --bitrate 238k

* Added a new helper function to create log file with optional parameter for prefix name
* Switched the log file creation in `ytmp3` module to `utils.createLogFile`
* Removed the old `createLogFile` function in `ytmp3` module
* Added a function called `writeErrorLog` to log errors to a specific log file
* Integrated the `writeErrorLog` function with 'error' event during audio conversion
* Synchronized the callback function in 'end' event
* Added a function that split and resolve the `inputOptions` and `outputOptions` options called `splitOptions`
* Added `inputOptions` and `outputOptions` options to the default options object with value of an empty array
* Added resolver for `inputOptions` and `outputOptions` options in the `audioconv.resolveOptions` function
* Added new parser arguments for `inputOptions` and `outputOptions` options in main module
* Added new command-line options:
  - `--input-options` (aliases, `--inputOptions`, `--addInputOptions`, `--add-input-options`)
  - `--output-options` (aliases, `--outputOptions`, `--addOptions`, `--add-options`, `--addOutputOptions`, `--add-output-options`)
  - `--inOpt` (a simple alias for `--input-options`)
  - `--outOpt` (a simple alias for `--output-options`)
* Added a logic to prevent FFmpeg crash due to write to the same file in the same time, the output file will be suffixed with '(copy)'
...and if the FFMPEG_PATH env variable is not an empty string.
This prevent confusion when an error occurs in the program and want to trace the error, especially while processing audio files.
* Improved the custom FFmpeg checker in `before` hook
* Re-enabled the verbose parameter in `checkFfmpeg` call
@mitsuki31 mitsuki31 added refactor Refactor and enhancement changes feature Bring new features minor Minor changes labels Aug 20, 2024
@mitsuki31 mitsuki31 self-assigned this Aug 20, 2024
@mitsuki31 mitsuki31 changed the title Enhance CLI with custom FFmpeg I/O options and improved logging and error handling Enhance CLI with custom FFmpeg I/O options and improved logging Aug 20, 2024
@mitsuki31 mitsuki31 merged commit cb1b441 into master Aug 20, 2024
15 checks passed
@mitsuki31 mitsuki31 deleted the feature/introduce-new-audio-converter-options branch August 20, 2024 15:21
mitsuki31 added a commit that referenced this pull request Aug 20, 2024
* Added the description for new command-line options (see #30)
* Changed all options' description to use third perspective description
mitsuki31 added a commit that referenced this pull request Aug 20, 2024
* Added the description for new command-line options (see #30)
* Changed all options' description to use third perspective description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Bring new features minor Minor changes refactor Refactor and enhancement changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant