If this command is entered while a song is playing in Audacious:
songdir=$(echo -n $(audtool current-song-filename) | cut -d'/' -f-5);for entry in "$songdir"/*.mp3; do echo "$entry";done
The command produces a list of all of the songs from that album by complete path and filename:
/media/sdc2/stereophonics/graffiti_on_the_train/01_-_stereophonics_-_we_share_the_same_sun.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/02_-_stereophonics_-_graffiti_on_the_train.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/03_-_stereophonics_-_indian_summer.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/04_-_stereophonics_-_take_me.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/05_-_stereophonics_-_catacomb.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/06_-_stereophonics_-_roll_the_dice.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/07_-_stereophonics_-_violins_and_tambourines.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/08_-_stereophonics_-_been_caught_cheating.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/09_-_stereophonics_-_in_a_moment.mp3
/media/sdc2/stereophonics/graffiti_on_the_train/10_-_stereophonics_-_no-ones_perfect.mp3
The command (that will update each tag) itself has to be built in three parts before it can be used to execute on each file listed above. (We will assume the variable name $song_path_var
is used for each iteration of the above list).
Here are the three parts:
Part 1 of the command can be a text file (pt1newcomm.txt) or variable with the first part of the command:
id3ted --COMM "
Part 2 is built by selecting and copying text to the clipboard in X, then running the below command to save the clipboard contents to the Part 2 text file (pt2newcomm.txt) or variable. This can be done easily with xclip:
xclip -out -selection clipboard > ~/data/mmdata/pt2newcomm.txt
The result of the above command produces a text file with the actual comment to be added to each tag:
Stereophonics are a Welsh rock band that formed in 1992 in the village of Cwmaman in the Cynon Valley. The band consists of Kelly Jones (lead vocals and lead guitar), Richard Jones (bass guitar, piano and backing vocals), Adam Zindani (rhythm guitar and backing vocals), Jamie Morrison (drums) and touring member Tony Kirkham (keyboards). The group previously included Stuart Cable (1992–2003) and then Javier Weyler (2004–2012) on drums. Stereophonics have released ten studio albums, including six UK number one albums, their latest album being Scream Above the Sounds (2017). A successful compilation album, Decade in the Sun, was released in November 2008 and charted at number two in the United Kingdom.
Part 3 of the command can be a text file (pt3newcomm.txt) or variable with the third and last part of the command:
:" $song_path_var
So, when we combine all three parts with:
paste ~/data/mmdata/pt1newcomm.txt ~/data/mmdata/pt2newcomm.txt ~/data/mmdata/pt3newcomm.txt > ~/data/mmdata/pt4newcomm.txt
it produces a text file (pt4newcomm.txt) or variable with the following command, which will then need to be executed in bash:
id3ted -c " Stereophonics are a Welsh rock band that formed in 1992 in the village of Cwmaman in the Cynon Valley. The band consists of Kelly Jones (lead vocals and lead guitar), Richard Jones (bass guitar, piano and backing vocals), Adam Zindani (rhythm guitar and backing vocals), Jamie Morrison (drums) and touring member Tony Kirkham (keyboards). The group previously included Stuart Cable (1992–2003) and then Javier Weyler (2004–2012) on drums. Stereophonics have released ten studio albums, including six UK number one albums, their latest album being Scream Above the Sounds (2017). A successful compilation album, Decade in the Sun, was released in November 2008 and charted at number two in the United Kingdom. :" $(audtool --current-song-filename)
The above command correctly updates the comment frame of the id3 tag for a given mp3 file, but has to be done manually for each file in the directory. How do you assign each one to the variable $song_path_var
, then run these command automatically for all of the files?
I assume we can use a: for OUTPUT in $(bash line command)
format:
#!/bin/bash
#The comment from the clipboard need only be executed once, so it is run first before the loop begins
xclip -out -selection clipboard > ~/data/mmdata/pt2newcomm.txt
#Next is the for loop
for song_path_var in $(songdir=$(echo -n $(audtool current-song-filename) | cut -d'/' -f-5);for entry in "$songdir"/*.mp3; do echo "$entry";done)
do
paste ~/data/mmdata/pt1newcomm.txt ~/data/mmdata/pt2newcomm.txt $song_path_var > ~/data/mmdata/pt4newcomm.txt
#command to execute pt4newcomm.txt here?
done
This generates an output of the lines of bash commands, bit it does not actually process them, so how do you make them run in command mode within this same script?
UPDATE: The following script generates a file containg each command line:
#!/bin/bash
#
truncate -s 0 ~/data/mmdata/test*.txt
xclip -out -selection clipboard > ~/data/mmdata/pt2newcomm.txt
songdir=$(echo -n $(audtool current-song-filename) | cut -d'/' -f-5);for entry in "$songdir"/*.mp3; do echo "$entry">> ~/data/mmdata/test1.txt;done
sed -e 's/^/\:\" /' ~/data/mmdata/test1.txt > test2.txt
commtxt=$(cat ~/data/mmdata/pt2newcomm.txt);file=~/data/mmdata/test2.txt; while read -r line; do echo "${commtxt}$line"; done <$file > test3.txt
sed -e 's/^/id3ted --COMM \"/' ~/data/mmdata/test3.txt > test4.txt
$COMMAND `cat ~/data/mmdata/test4.txt`
$COMMAND
The file with commands looks like this:
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/10_-_feeder_-_dove_grey_sands.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/1_-_feeder_-_feeling_a_moment.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/2_-_feeder_-_bitter_glass.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/3_-_feeder_-_tumble_and_fall.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/4_-_feeder_-_tender.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/5_-_feeder_-_pushing_the_senses.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/6_-_feeder_-_frequency.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/7_-_feeder_-_morning_life.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/8_-_feeder_-_pilgrim_soul.mp3
id3ted --COMM "Pushing the Senses is the fifth album by the British rock band Feeder. It was released on Echo, Liberation Music and PIAS on 31 January 2005:" /media/sdc2/feeder/pushing_the_senses/9_-_feeder_-_pain_on_pain.mp3
When entering each line manually in the terminal it works, but when run in the script, it fails, likely due to quotation marks in the command string.
SOLVED:
Changed the end of this script to run in a separate bash instance:
#!/bin/bash
#
truncate -s 0 ~/data/mmdata/test*.txt
xclip -out -selection clipboard > ~/data/mmdata/pt2newcomm.txt
songdir=$(echo -n $(audtool current-song-filename) | cut -d'/' -f-5);for entry in "$songdir"/*.mp3; do echo "$entry">> ~/data/mmdata/test1.txt;done
sed -e 's/^/\:\" /' ~/data/mmdata/test1.txt > test2.txt
commtxt=$(cat ~/data/mmdata/pt2newcomm.txt);file=~/data/mmdata/test2.txt; while read -r line; do echo "${commtxt}$line"; done <$file > test3.txt
sed -e 's/^/id3ted --COMM \"/' ~/data/mmdata/test3.txt > test4.txt
bash ~/data/mmdata/test4.txt
bash
to execute them.done
todone | bash
.