使用电子表格中的数据标记音频文件
Posted
技术标签:
【中文标题】使用电子表格中的数据标记音频文件【英文标题】:Tagging audio-files with data from spreadsheet 【发布时间】:2015-09-29 15:01:00 【问题描述】:在我的音乐库中,甲壳虫乐队录制的所有音乐都被划分到专辑目录中。其中大部分是 *.flac。当我在音乐播放器(Linux.Ubuntu.14.04 上的节奏盒)中打开文件时。我想编写一个简单的 bash 循环来根据电子表格设置作曲家标签,其中所有数据提取自:https://en.wikipedia.org/wiki/List_of_songs_recorded_by_the_Beatles 所以我可以从那里创建一个 *.csv 或 *.tsv 文件。
到目前为止,我还学习了如何使用名为 flac
(sudo apt-get install flac
) 的包和命令 metaflac
。
不幸的是,我没有任何编写循环的经验,但我知道它应该看起来像这样:
forall files in the current directorydo
metaflac --remove-tag=composer
done
foruntill 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
【问题讨论】:
我不认为 vim 是您正在寻找的工具。也许像id3v2 或eyed3 这样的工具在脚本中使用会更有趣。 我已经学会了如何使用 id3v2 和 eyeD3,它们对于 *.mp3 非常有用,但对于 *.flac 则没有。如果我更改某个 *.flac 文件中的标签,当我在节奏盒音乐播放器中查看该文件时,该标签似乎没有更改。有什么建议吗? 我从来没有自己做过,快速的谷歌搜索将我指向flack,但我不确定你是否可以在脚本中以非交互方式使用它。我的意思是让你注意到你需要一个非交互式工具而不是 vim :-) 也许你会找到你需要的工具感谢software recommendation 【参考方案1】:# 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"
【讨论】:
在这里转储整个数据库几乎没有意义。实际脚本似乎花费了大部分时间来回更改目录。 你是完全正确的@tripleee,我已经编辑了脚本,所以我希望你会发现新的更有效率。 好多了,是的;但是为什么需要将整个 TSV 读入内存呢?您是否有理由不能一次只阅读一个条目、处理它并忘记它,然后继续阅读下一个条目? 感谢您的鼓励@tripleee,我已经设法改进了脚本,使其运行的文件比以前更多(在之前的脚本中,它“遗漏”了一些文件,因为电子表格中的歌曲名称与我系统上的文件不完全相同)无论如何我希望你会发现它足够好并为我的答案投票,这样我就会获得声誉;)以上是关于使用电子表格中的数据标记音频文件的主要内容,如果未能解决你的问题,请参考以下文章