如何在shell中读取mp3标签?
有没有办法从shell读取文件的mp3标签? 类似于: mp3tags MyFile.mp3 author
应输出mp3文件的author-tag。
您也可以使用ffprobe
,它是ffmpeg
一部分。
sudo apt-get install ffmpeg ffprobe file.mp3
如果您不想要其他信息,例如轨道长度等,您可以将输出与grep结合使用:
ffprobe file.mp3 2>&1 | grep -A90 'Metadata:'
或者只为了获得作者:
ffprobe -loglevel error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 file.mp3
您可以通过用逗号分隔它们来选择其他标签,例如format_tags=title,album
。
我想在文件夹中的所有mp3文件中搜索关键字。 该文件夹有486个文件,所以知道这里提到的哪个解决方案最快是很有趣的。 这是我使用的循环:
# sudo apt-get install ffmpeg lltag eyed3 mp3info id3v2 libimage-exiftool-perl libid3-tools id3tool keyword='fill_me_in' getTitleFF() { ffprobe "$1" 2>&1 | sed -E -n 's/^ *title *: (.*)/\1/p'; } getTitleLL() { lltag --show-tags title "$1" | sed -nE 's/^ TITLE=(.*)/\1/p'; } getTitleEyed() { eyeD3 2>&1 "$1" | grep 'title'; } getTitleInfo() { mp3info -p %t "$1"; } getTitleId3() { id3v2 -l "$1" | sed -nE 's/^TIT2 \([^)]*\): (.*)/\1/p'; } getTitleExif() { exiftool -title -b "$1"; } getTitleId3i() { id3info "$1" | sed -n 's/^=== TIT2 \(.*\): //p'; } getTitleTool() { id3tool "$1" | sed -n 's|^Song Title:\t||p'; } for prog in FF LL Eyed Info Id3 Exif Id3i Tool; do echo "=== getTitle${prog} ===" time \ for file in *.mp3; do if "getTitle${prog}" "$file" | grep -q "$keyword"; then echo "$file" fi done done
笔记:
-
lltag
和mp3info
找不到标题,因为我使用的文件有ID3v2标签,请参阅@ s-prasanth的评论: 如何在shell中读取mp3标签? -
eyeD3
以编程方式使用是有问题的,因为它使用颜色代码(粗体)。 -
eyeD3
和id3v2
(但仅限于ID3 v1标签)将标题和艺术家放在同一行上,这使事情变得更加复杂; 因此getTitleEyed
,有时getTitleId3
返回标题和艺术家,所以请不要复制粘贴这些function。 -
getTitleId3仅适用于ID3 v2标签,因为
id3v2
具有不同的ID3v1和ID3v2标签格式,即Title : Artist:
与ID3v2:
TIT2 (Title/songname/content description):
-
由于这5个
eyeD3
唯一的程序eyeD3
打印出两个文件的红色警告:Invalid mode/bitrate combination for layer II No ID3 v1.x/v2.x tag found!
看起来这两个文件有ID3v1标签,因为这两个文件是
lltag
和mp3info
可以获得标题的唯一文件。 我想知道这是不是eyeD3
一个错误,因为这里提到的其他程序没有这些文件的问题…
结果(实时):
Program | Version | Time / s ----------+------------+----------- exiftool | 10.25 | 49.5 ± 0.5 lltag | 0.14.5 | 41 ± 1.0 ffprobe | 3.1.3-1+b3 | 33 ± 0.5 eyeD3 | 0.6.18 | 24 ± 0.5 id3info | 3.8.3 | 4.2 ± 0.1 id3v2 | 0.1.12 | 2.9 ± 0.1 id3tool | 1.2a | 1.7 ± 0.1 mp3info | 0.8.5a | 1.4 ± 0.1
时间方面,赢家在这里是id3tool
(mp3info更快,但不适用于ID3 v2)。 id3v2
也很快,但getTitleId3
函数需要调整才能使用ID3v1标签,这可能最坏的情况是减慢因子2。
好的,我自己找到了一个程序。 它被称为mp3info并由安装
sudo apt-get install mp3info
要从文件中获取单个mp3标签,必须调用
mp3info -p %a file.mp3
这给了艺术家的文件。 %a表示想要获得艺术家,而其他标签还有其他键。
你可以使用eyed3 。 首先,从终端安装:
sudo apt-get install eyed3
然后,运行:
eyeD3 song.mp3
将它与grep
结合使用可以在一行中获取特定标记。
eyeD3 song.mp3 | grep artist
(删除所有mp3标签,请参阅此处 )
我更喜欢使用id3v2,只需输入id3v2 -l somefile.mp3
。 您还可以查看id3v2手册页以获取更具体的用途。
您可以尝试exiftool(在文件中读取和写入元信息)。
“ExifTool是一个独立于平台的Perl库,另外还有一个命令行应用程序,用于读取,编写和编辑各种文件中的元信息.ExifTool支持许多不同的元数据格式,包括EXIF,GPS,IPTC,XMP,JFIF,GeoTIFF,ICC Profile,Photoshop IRB,FlashPix,AFCP和ID3,以及Canon,Casio,FLIR,FujiFilm,GE,HP,JVC / Victor,Kodak,Leaf,Minolta / Konica-Minolta,Motorola等许多数码相机的制造商笔记,尼康,任天堂,奥林巴斯/爱普生,松下/徕卡,宾得/朝日,第一期,Reconyx,理光,三星,三洋,Sigma / Foveon和索尼。“ – Phil Harvey的ExifTool
以下是该命令的示例:
exiftool test.mp3 ExifTool Version Number : 10.00 File Name : test.mp3 Directory : . File Size : 8.2 MB File Modification Date/Time : 2016:03:02 21:44:58+01:00 File Access Date/Time : 2016:04:06 21:34:01+02:00 File Inode Change Date/Time : 2016:03:02 21:45:36+01:00 File Permissions : rw-rw-r-- File Type : MP3 File Type Extension : mp3 MIME Type : audio/mpeg MPEG Audio Version : 1 Audio Layer : 3 Sample Rate : 44100 Channel Mode : Stereo MS Stereo : Off Intensity Stereo : Off Copyright Flag : False Original Media : False Emphasis : None VBR Frames : 9544 VBR Bytes : 8467680 ID3 Size : 115419 Band : Tech N9ne Collabos Album : Strangeulation (Deluxe Edition) Composer : Tech N9ne Collabos Genre : Rap & Hip-Hop Copyright : 2014 Strange Music, Inc Title : American Horror Story (feat. Ces Cru) Artist : Tech N9ne Collabos Track : 10 Year : 2014 Comment : Lyrics : Private : (Binary data 8192 bytes, use -b option to extract) Picture MIME Type : image/jpeg Picture Type : Front Cover Picture Description : Picture : (Binary data 104371 bytes, use -b option to extract) Audio Bitrate : 272 kbps Date/Time Original : 2014 Duration : 0:04:09 (approx)
如果您正在寻找不仅仅支持mp3 / ID3的解决方案,请查看lltag
。
安装它:
sudo apt-get install lltag
用它查看所有标签:( – -S
代表节目)
lltag -S somefile.mp3
用它查看某些标签:
lltag --show-tags artist,album,title,number somefile.mp3