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 core functionality and restructure the codebase #8

Merged
merged 16 commits into from
Jun 30, 2024

Conversation

mitsuki31
Copy link
Owner

Overview

This pull request focuses on significant enhancements and refactoring across various modules of the project. These changes aim to improve the functionality, efficiency, and maintainability of the codebase. It includes new features, refactoring of existing functions, improvements in documentation, and several chore updates.

Changes Made

Features

YT URL Formats Module

Added a new module named yt-urlfmt which provides regular expressions for all supported YouTube URL formats including:

  • Standard video URLs
  • Shortened video URLs
  • Playlist URLs
  • Channel URLs
  • YouTube Music URLs

This module standardizes URL validation across the project, making it easier to handle different types of YouTube URLs consistently.

Utility Module

Introduced a new utility module that provides several helper functions for the core library, such as:

  • logger
    A namespace to log info, warning and error messages with ANSI color codes to the terminal, improving the visibility of process statuses and errors.

  • ProgressBar
    A class to create a progress bar for displaying download progress in the terminal, enhancing user experience by providing visual feedback during downloads.

  • createDirIfNotExist
    Checks if a specified directory exists and creates it if not, ensuring that necessary directories are available before file operations.
    Function implementation:

    async function createDirIfNotExist(dirpath);

Core Module

Added a core module named ytmp3 which provides all APIs related to downloading YouTube videos as audio files. Functions such as getVideosInfo, singleDownload, and batchDownload were moved from the main module to this core module. The download process was enhanced to handle all URLs sequentially, removing the previous limit of 15 URLs per batch.

This change centralizes download-related functionality, making the codebase more modular and easier to maintain. It also improves the download process by handling large batches of URLs more efficiently.

Refactors & Enhancements

Rename and Improve Options in Audio Converter

Renamed optionsMp3 to defaultOptions and introduced a new option deleteOld to decide whether to delete the old audio file.

This change improves clarity by using more descriptive names and adds flexibility by allowing users to choose whether to keep old audio files.

Audio Converter Enhancements

Refined and improved the audio converter module. Changes include:

  • Added progress information to the console, giving users real-time feedback on the conversion process.
  • Added an FFmpeg checker before performing audio conversion to ensure the required tool is available.
  • Renamed the function convertToMp3 to convertAudio to better reflect its functionality.
  • Improved exception handling to provide clearer error messages and prevent crashes.
  • Revised and improved documentation within the module for better understanding and maintainability.

Sequential Video Info Retrieval

Refactored the getVideosInfo(...urls) function to run sequentially instead of in parallel. This helps users with slow internet connections by reducing the load on the network and preventing potential timeouts.

This change ensures more reliable video info retrieval, particularly for users with limited bandwidth.

Main Module Enhancements

Enhanced the functionality of the main module by removing unused internal functions and renaming argumentParser to getInput. This function now checks if the given argument is a URL or a file path, improving input validation and processing.

These changes streamline the main module, removing unnecessary code and improving the clarity and functionality of the getInput function.

Chores & Maintenances

Change Indentation

Changed the indentation to two spaces for better readability, ensuring a consistent coding style across the project.

Ignore Directories in ESLint and Git

Updated ESLint and Git configurations to ignore the docs directory, reducing noise and potential conflicts during development.

Add JSDoc Dependency

Added jsdoc dependency and its configuration file.

Refactor the package.json

Refactored package.json to include several fields like files, exports, repository, keywords, and more. This change improves documentation generation and package configuration.

Documentation

Improve Utils Module Docs

Fixed and improved the documentation in the utils module, making it easier for developers to understand and use the provided functions.

Summary

This pull request introduces several significant enhancements and refactors across the project:

  • Added new modules for URL formats and utility functions.
  • Refined and improved the audio conversion process.
  • Enhanced the core module for better download management.
  • Improved documentation and added necessary dependencies.
  • Fixed multiple issues to ensure better functionality and reliability.

These changes aim to make the codebase more robust, efficient, and maintainable, providing a better user experience and easier future development.

mitsuki31 added 16 commits June 20, 2024 10:20
Module name: 'yt-urlfmt'
This module provides all supported YouTube URL formats in regular expression, including:
  - Standard video URL
  - Shortened video URL
  - Playlist URL
  - Channel URL
  - YouTube Music URL
This utility module provides several helper functions for the core library, such as:
  - `logger` : A logger object to log info messages and error messages with ANSI color codes to the terminal
  - `ProgressBar` : A class to create the progression bar, this is useful to bring the information during download process to the terminal
  - `createDirIfNotExist` : This function will checks the specified directory, if not exist then creates new using asynchronous operation
Additionally, introduce a new option called `deleteOld` to choose whether to delete the old audio file or not.
This enhancements includes:
  - Added the progress information to the console
  - Added FFmpeg checker before performing audio conversion
  - Renamed the function `convertToMp3` to `convertAudio`
  - Improved exceptions handler
  - Revised and improved all documentations within `acodecs-cvt` module
This change also improved the documentations within the module.
The core module named `ytmp3`, this module will provide all APIs related to downloads YouTube videos as audio files. Also, I've moved several functions from the main module (`index.js`) to this module, including:
  * `getVideosInfo`
  * `singleDownload`
  * `batchDownload`

This change also made the core module more robust and efficient, aiming at the download process. Previously, it only downloaded the first 15 URLs from the given file. Now, it downloads all of them sequentially and users can download more than 15 URLs in one batch. In addition, some internal functions has been defined to enhance the download process and make it more reliable, and also improved documentations and errors handling.
No new features added. But removed several internal functions in the main module as it was not used, such as:
  * `getVideosInfo` (moved to `ytmp3` module)
  * `singleDownload` (moved to `ytmp3` module)
  * `batchDownload` (moved to `ytmp3` module)
  * `normalizeYtMusicUrl` (removed permanently)

In addition, renamed the `argumentParser` function to `getInput`, remove its parameter and small refactor. The function checks whether the given argument is an URL or a file path. If URL is given, the function returns the URL as a `URL` object. Otherwise, if the argument is a file path, the function returns the file path as a string.
This change also refactored the package.json by adding several fields such as, `files`, `exports`, `repository`, `keywords`, and more.
This issue was due to unexpectedly call the `trim()` function on URL object. Now it checked first before trimming whitespace.
Refactored the `getVideosInfo(...urls)` function to ensure it runs sequential instead parallel. This quite helpful for users with slow internet connection.
Implemented a checker within `batchDownload` function to check the FFmpeg before converting the downloaded audios.
@mitsuki31 mitsuki31 self-assigned this Jun 30, 2024
@mitsuki31 mitsuki31 added refactor Refactor and enhancement changes chore Maintenance updates to improve project maintainability labels Jun 30, 2024
@mitsuki31 mitsuki31 changed the title refactor: Enhance core functionality and restructure the codebase Enhance core functionality and restructure the codebase Jun 30, 2024
@mitsuki31 mitsuki31 merged commit 4a3a384 into master Jun 30, 2024
8 checks passed
@mitsuki31 mitsuki31 deleted the refactor/enhance-and-refactor-everything branch June 30, 2024 10:38
@mitsuki31 mitsuki31 added the feature Bring new features label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance updates to improve project maintainability feature Bring new features refactor Refactor and enhancement changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant