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

Pull Request Summary: Enhancements to audio2tonie.sh #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

P1tt187
Copy link

@P1tt187 P1tt187 commented Jan 7, 2025

This pull request introduces several improvements to the audio2tonie.sh script to enhance its functionality, robustness, and user experience. Below is a summary of the changes:


1. Support for TeddyCloud Library Path

  • Added a new -p or --path option to specify the target directory in the TeddyCloud library where the .taf file should be uploaded.
  • If no path is provided, the script defaults to uploading the file to the root library folder (/).
  • Example usage:
    ./audio2tonie.sh -s /path/to/audio.mp3 -u https://teddycloud.local -p /custom/path

2. Improved File Naming for Directories

  • Fixed an issue where the script generated a .taf file with an incorrect or empty name when the input was a directory (e.g., /path/to/).
  • The script now uses the folder name as the base name for the .taf file (e.g., /path/to/ becomes /path/to/to.taf).
  • Example:
    ./audio2tonie.sh -s /path/to/
    Output:
    Creating TAF file:
      - Input: /path/to/
      - Output: /path/to/to.taf
    

3. Avoid Creating Empty .taf Files

  • Added a check to ensure the script does not create a .taf file if the input directory contains no valid audio files.
  • If no valid files are found, the script exits with an error message:
    Error: No valid audio files found in the directory: /path/to/
    

4. Improved Error Handling and Robustness

  • Added error handling for critical operations (e.g., curl, jq, python3) to ensure the script fails gracefully if something goes wrong.
  • Used set -euo pipefail to enable strict mode, which ensures the script exits on errors, unset variables, and pipeline failures.
  • Quoted all variables to prevent issues with filenames containing spaces or special characters.

5. Enhanced User Feedback

  • Added detailed output to inform users about the .taf file being created, including:
    • Input file or directory.
    • Output file path.
    • Number of chapters (files) being processed.
  • Example output:
    Creating TAF file:
      - Input: /path/to/audio.mp3
      - Output: /path/to/audio.taf
      - Number of chapters: 1
    

6. Support for Full TeddyCloud URIs

  • Updated the -u or --upload option to accept full URIs (e.g., https://teddycloud.local or http://192.168.1.100).
  • Added validation to ensure the URI starts with http:// or https://.
  • The script now handles permanent HTTPS redirections using curl's -L flag.

7. Code Refactoring and Modularization

  • Introduced functions to reduce redundant code and improve readability:
    • display_help: Displays the help message.
    • print_settings: Prints the current script settings.
    • upload_to_teddycloud: Handles file uploads to TeddyCloud.
    • normalize_teddycloud_uri: Validates and normalizes the TeddyCloud URI.
    • print_taf_creation_details: Prints details about the .taf file being created.
    • has_valid_audio_files: Checks if a directory contains valid audio files.
    • get_basename: Extracts the base name of a directory (without trailing slashes).

8. Improved Help Message

  • Updated the help message to include all available options and examples:
    Usage: $0 [options]
    
    Options:
      -s, --source SOURCE       Specify the source file or directory.
      -r, --recursive           Process directories recursively.
      -o, --output OUTPUT_FILE  Specify the output file name.
      -u, --upload URI          Upload the generated TAF file to a Teddycloud server.
      -p, --path PATH           Specify the target path in the Teddycloud library.
      -h, --help                Display this help message and exit.
    
    Examples:
      $0 -s /path/to/audio.mp3 -o /path/to/output.taf
      $0 -s /path/to/audio_folder -r -u https://teddycloud.local
      $0 -s /path/to/audio.mp3 -u https://teddycloud.local -p /custom/path

Why These Changes Matter:

  • Flexibility: Users can now specify the target directory in the TeddyCloud library and use full URIs for uploads.
  • Robustness: The script handles errors gracefully and avoids creating empty or incorrectly named .taf files.
  • User Experience: Improved feedback and help messages make the script easier to use and debug.
  • Maintainability: Modular functions and strict mode make the script easier to maintain and extend.

Testing:

  • The script has been tested with:
    • Single audio files.
    • Directories containing multiple audio files.
    • Recursive directory processing.
    • TeddyCloud uploads with custom paths.
    • Various edge cases (e.g., empty directories, invalid URIs).

Example Workflow:

  1. Convert a single audio file and upload it to a custom path:

    ./audio2tonie.sh -s /path/to/audio.mp3 -u https://teddycloud.local -p /custom/path
  2. Convert all audio files in a directory and upload them to the root library folder:

    ./audio2tonie.sh -s /path/to/audio_folder/ -r -u https://teddycloud.local

This pull request enhances the script's functionality and usability while maintaining backward compatibility. Feedback and suggestions are welcome! 🚀


Let me know if you need further adjustments!

@P1tt187 P1tt187 force-pushed the feature/improvements-for-script branch from 3430441 to b709fe3 Compare January 7, 2025 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant