使用电子表格中的数据标记音频文件

时间:2015-09-29 15:01:00

标签: linux bash loops unix audio

我在我的音乐库中将所有由beatles录制的音乐分成专辑目录。大多数是* .flac。当我在音乐播放器中打开文件时(Linux.Ubuntu.14.04上的rhythmbox)。我想写一个简单的bash循环来根据电子表格设置composer标签,其中包含从https://en.wikipedia.org/wiki/List_of_songs_recorded_by_the_Beatles中提取的所有数据。 所以我可以从那里创建一个* .csv或* .tsv文件。

到目前为止,我还学会了如何使用名为flacsudo apt-get install flac)的包和命令metaflac。 不幸的是,我在编写循环方面没有任何经验,但我知道它看起来应该是这样的:

for{all files in the current directory}do
 metaflac --remove-tag=composer
done
for{untill reaching the end of file "The-Beatles.db.tsv"}do
 {locate file named as in left part of line x}
 metaflac --set-tag=composer=${right part of line x in file "The-Beatles.db.tsv"}
done

1 个答案:

答案 0 :(得分:0)

# https://docs.google.com/spreadsheets/d/1AnhIblgyA8yXRo-s5_zBpYEtgyFtkgqnLw_6eP5grMI/edit?usp=sharing
# URL above is the source of the .tsv file located in the same folder of this script
# **I've copied all the first 2 columns of the spreadsheet to "songs-composers.tsv"**

while read line; do
 IFS=$'\t'
 val=($(echo "$line"))
 # "${val[0]}" is the name of the song
 # "${val[1]}" is the name of the composer
 echo locating song: "${val[0]}"...
  IFS=$'\n'
 file=($(find -iname ""${val[0]}"*.flac"))
 echo "located files are:"
 for j in `seq 1 "${#file[@]}"`; do
  echo "    "${file[$((j-1))]}""
 done
 for j in `seq 1 "${#file[@]}"`; do # for every string in the array 'file'
  echo removing composer-tag for file:        "${file[$((j-1))]}"
  metaflac --remove-tag=composer "${file[$((j-1))]}"
  echo setting-up correct composer-tag as     "${val[1]}"
  metaflac --set-tag=COMPOSER="${val[1]}" "${file[$((j-1))]}"
 done
done < "songs-composers.tsv"