Якщо ця команда введена під час відтворення пісні в Audacious:
songdir=$(echo -n $(audtool current-song-filename) | cut -d'/' -f-5);for entry in "$songdir"/*.mp3; do echo "$entry";done
Команда створює список усіх пісень із цього альбому за повним шляхом та назвою файлу:
/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
Команда (яка буде оновлювати кожен тег) сама має бути побудована у трьох частинах, перш ніж її можна буде використовувати для кожного переліченого вище файлу. (Будемо вважати, що ім'я змінної $song_path_varвикористовується для кожної ітерації вищевказаного списку).
Ось три частини:
Частина 1 команди може бути текстовим файлом (pt1newcomm.txt) або змінною з першою частиною команди:
id3ted --COMM "
Частина 2 будується шляхом вибору та копіювання тексту до буфера обміну в X, після чого виконується команда нижче, щоб зберегти вміст буфера обміну до текстового файлу частини 2 (pt2newcomm.txt) або змінної. Це легко зробити за допомогою xclip:
xclip -out -selection clipboard > ~/data/mmdata/pt2newcomm.txt
Результат вищевказаної команди створює текстовий файл із фактичним коментарем, який слід додати до кожного тегу:
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.
Частина 3 команди може бути текстовим файлом (pt3newcomm.txt) або змінною з третьою та останньою частиною команди:
:" $song_path_var
Отже, коли ми поєднуємо всі три частини з:
paste ~/data/mmdata/pt1newcomm.txt ~/data/mmdata/pt2newcomm.txt ~/data/mmdata/pt3newcomm.txt > ~/data/mmdata/pt4newcomm.txt
він створює текстовий файл (pt4newcomm.txt) або змінну із наступною командою, яку потім потрібно виконати в 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)
Наведена вище команда правильно оновлює рамку коментарів тегу id3 для даного файлу mp3, але це потрібно зробити вручну для кожного файлу в каталозі. Як призначити кожну з змінних $song_path_var, а потім виконати цю команду автоматично для всіх файлів?
Я припускаю, що ми можемо використовувати: 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
Це генерує вихід рядків команд bash, біт насправді їх не обробляє, так як змусити їх працювати в командному режимі в рамках цього ж сценарію?
ОНОВЛЕННЯ: Наступний скрипт генерує файл, що стосується кожного командного рядка:
#!/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
Файл із командами виглядає приблизно так:
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
При введенні кожного рядка в терміналі він працює, але при запуску в скрипті він виходить з ладу, ймовірно, через лапки в командному рядку.
РІШЕНО:
Змінено кінець цього сценарію для запуску в окремому екземплярі bash:
#!/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
doneна done | bash.
bashїх виконати.