저는 오디오 CD를 분석하기 위한 작은 스크립트를 작성하고 있습니다. 저는 특히 쉘 스크립트나 Python에서 CD의 트랙 수를 얻는 방법을 찾고 있습니다. 찾을 수 있는 단축키가 있나요?
우분투 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