我正在编写一个小脚本来分析音频 CD。我正在专门寻找一种从 CD 获取曲目计数的方法,无论是从 shell 脚本还是从 Python。是否有捷径可寻?
在 Ubuntu 12.04 衍生版本上。
答案1
偏执狂
您可以使用命令行工具 获取 CD 音轨列表cdparanoia
。
$ cdparanoia -sQ
例子
$ cdparanoia -sQ
cdparanoia III release 10.2 (September 11, 2008)
Table of contents (audio tracks only):
track length begin copy pre ch
===========================================================
1. 19497 [04:19.72] 0 [00:00.00] OK no 2
2. 20253 [04:30.03] 19497 [04:19.72] OK no 2
3. 29250 [06:30.00] 39750 [08:50.00] OK no 2
4. 34263 [07:36.63] 69000 [15:20.00] OK no 2
5. 28804 [06:24.04] 103263 [22:56.63] OK no 2
6. 21582 [04:47.57] 132067 [29:20.67] OK no 2
7. 33270 [07:23.45] 153649 [34:08.49] OK no 2
8. 29919 [06:38.69] 186919 [41:32.19] OK no 2
9. 29564 [06:34.14] 216838 [48:11.13] OK no 2
10. 18993 [04:13.18] 246402 [54:45.27] OK no 2
11. 35368 [07:51.43] 265395 [58:58.45] OK no 2
TOTAL 300763 [66:50.13] (audio only)
您可以计算包含字符串“OK”或以数字开头的行数,例如1.
。
$ cdparanoia -sQ |& grep OK | wc -l
11
-or-
$ cdparanoia -sQ |& grep -P "^\s+\d+\." | wc -l
11
CDDA2WAV
您还可以使用此命令行工具cdda2wav
.
$ cdda2wav -J -D /dev/cdrom
例子
$ cdda2wav -J -D /dev/cdrom
Type: ROM, Vendor 'Optiarc ' Model 'DVD RW AD-7930H ' Revision '1.D1' MMC+CDDA
569344 bytes buffer memory requested, 4 buffers, 55 sectors
#icedax version 1.1.11, real time sched., soundcard, libparanoia support
AUDIOtrack pre-emphasis copy-permitted tracktype channels
1-11 no yes audio 2
Table of Contents: total tracks:11, (total time 66:50.13)
1.( 4:19.72), 2.( 4:30.03), 3.( 6:30.00), 4.( 7:36.63), 5.( 6:24.04),
6.( 4:47.57), 7.( 7:23.45), 8.( 6:38.69), 9.( 6:34.14), 10.( 4:13.18),
11.( 7:51.43)
Table of Contents: starting sectors
1.( 0), 2.( 19497), 3.( 39750), 4.( 69000), 5.( 103263),
6.( 132067), 7.( 153649), 8.( 186919), 9.( 216838), 10.( 246402),
11.( 265395), lead-out( 300763)
CDINDEX discid: gteZIAUq3lgZlEmNg_HnbWL6cJc-
CDDB discid: 0x950faa0b
CD-Text: detected
CD-Extra: not detected
Album title: 'Hour of the Olympics' [from Mary Pope Osborne]
Track 1: 'Viking Ships at Sunrise Ch 3'
Track 2: 'Viking Ships at Sunrise Ch 4'
Track 3: 'Viking Ships at Sunrise Ch 5-6'
Track 4: 'Viking Ships at Sunrise Ch 7-8'
Track 5: 'Viking Ships at Sunrise Ch 9-10'
Track 6: 'Hour of the Olympics Ch 1'
Track 7: 'Hour of the Olympics Ch 2-3'
Track 8: 'Hour of the Olympics Ch 4-5'
Track 9: 'Hour of the Olympics Ch 6-8'
Track 10: 'Hour of the Olympics Ch 9'
Track 11: 'Hour of the Olympics Ch 10'
No media catalog number present.
scanning for ISRCs: 11 ...
index scan: 11...
您再次可以寻求帮助来grep
获取曲目数量:
# traditional way to parse output
$ cdda2wav -J -D /dev/cdrom |& grep index | sed 's#.*: \(.*\)...#\1#g'
11
# use grep's PCRE capability
$ cdda2wav -J -D /dev/cdrom |& grep -Po '(?<=index scan: )\d+' | tail -1
11
参考
答案2
CD光盘返回轨道数以及其他 CDDB 信息。
$ cd-discid
30087b04 4 150 78547 92953 112181 2173
^
number of tracks
要仅获取曲目数量:
$ tracktotal=$(cd-discid); tracktotal="${tracktotal#* }"; tracktotal="${tracktotal%% *}"; echo $tracktotal