Если эта команда введена во время воспроизведения песни в 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 используется для каждой итерации приведенного выше списка).

Вот три части:

Первая часть команды может быть текстовым файлом (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 , а затем автоматически выполнить эти команды для всех файлов?

Я предполагаю, что мы можем использовать: для OUTPUT в формате for OUTPUT in $(bash line command) :

   #!/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

1 ответ1

0

Команда для выполнения pt4newcomm.txt здесь?

Сделай это:

$COMMAND=`cat pt4newcomm.txt`
$COMMAND

Очевидно, вы должны быть уверены, что pt4newcomm.txt содержит допустимые команды, не удалит ненужные файлы и т.д.

Вероятно, есть пять лучших способов сделать это, но вышесказанное должно работать.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .