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

Add title metadata #245

Open
Lastofthefirst opened this issue Jun 1, 2024 · 2 comments
Open

Add title metadata #245

Lastofthefirst opened this issue Jun 1, 2024 · 2 comments

Comments

@Lastofthefirst
Copy link

When I generate m4b files with epub2tts they have the album name set to the title, but the the title is left blank. In Voice the audiobook reader on android this results in the first chapter being listed as the title, which is often like introduction or part 4, its a bit off putting. I have been adding the title after generation, but it would be helpful if epub2tts just added that as well.

@Lastofthefirst
Copy link
Author

There may be a simpler approach, but this script does the job with ffmpeg:

#!/bin/bash

# Check if a file path is provided as an argument
if [ -z "$1" ]; then
    echo "Usage: $0 <audio_file>"
    exit 1
fi

# Assign the first command-line argument to audio_file
audio_file="$1"

# Check if the file exists
if [ ! -f "$audio_file" ]; then
    echo "File not found: $audio_file"
    exit 1
fi

# Get the base name and directory of the audio file
base_name=$(basename "$audio_file")
dir_name=$(dirname "$audio_file")

# Get the album metadata using ffprobe
album=$(ffprobe -v error -show_entries format_tags=album -of default=noprint_wrappers=1:nokey=1 "$audio_file")

# Check if album metadata was found
if [ -z "$album" ]; then
    echo "No album metadata found in $audio_file"
    exit 1
fi

# Create a temporary file in the same directory as the original file
temp_file="${dir_name}/temp_${base_name}"

# Set the title metadata to the album metadata using ffmpeg
ffmpeg -i "$audio_file" -metadata title="$album" -codec copy "$temp_file"

# Check if ffmpeg succeeded
if [ $? -ne 0 ]; then
    echo "Failed to update metadata for $audio_file"
    rm -f "$temp_file"
    exit 1
fi

# Replace the original file with the modified file
mv "$temp_file" "$audio_file"

echo "Title metadata updated to '$album' in $audio_file"

@aedocw
Copy link
Owner

aedocw commented Jun 1, 2024

I think the title in FFMETADATA should be properly set. Can you do a run (maybe of a shortened book for speed) with --debug and share the contents of FFMETADATA? If you're doing this from a text file and one of the first two lines has Title: <your title>, it should be in there.

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

No branches or pull requests

2 participants