I'm trying to learn (with no programming background) to create some custom bash scripts for converting selected files from Nautilus, but I hit an issue I can't understand.
For reference, this is a script that DOES work. It converts selected .MP4 files to .mkv, copies the time stamp and prints some feedback to the user.
#!/bin/bash
for i in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
ffmpeg -i "$i" -movflags use_metadata_tags -c:v libx265 -crf 26 -preset slow -c:a aac -b:a 160k "${i%.*}.mkv" && touch -r "$i" "${i%.*}.mkv" && notify-send "Converted '$(basename "$i")'" || notify-send "Failed converting '$(basename "$i")'"
done
notify-send "Conversion finished"
Now, this is a script that DOESN'T work. It should convert selected .m4a files to .mp3, add a cover image and some tags, copy the time stamp and give some feedback to the user.
#!/bin/bash
for i in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
ffmpeg -i "$i" "${i%.*}.mp3" && eyeD3 -a "Author" -A "Album" --add-image="cover.jpg":FRONT_COVER "${i%.*}.mp3" && touch -r "$i" "${i%.*}.mp3" && notify-send "Converted '$(basename "$i")'" || notify-send "Failed converting '$(basename "$i")'"
done
notify-send "Conversion finished"
When I run this one, I get multiple errors that say "Failed converting (a part of the path to the file)"... for some parts of the path to the file, like parts of folder and file names.
I'm not sure what I'm doing differently here. I'm using the same $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
parameter, but it doesn't work the same in the second script.
As a reference, this other script, which is the same as the second one but applies to all the files in the folder, does work perfectly, so I'm sure the commands inside do
do work.
#!/bin/bash
for i in *.m4a
do
ffmpeg -i "$i" "${i%.*}.mp3" && eyeD3 -a "Author" -A "Album" --add-image="cover.jpg":FRONT_COVER "${i%.*}.mp3" && touch -r "$i" "${i%.*}.mp3" && notify-send "Converted '$(basename "$i")'" || notify-send "Failed converting '$(basename "$i")'"
done
notify-send "Conversion finished"
What am I missing? Can the $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
only work with certain file types? Is the issue somewhere else?
IFS
suitablyfor
can be broken up into shorter, easier to read lines with<space>\<newline>
at the end (literal space and newline, not the bracketed text).