Debian Codegraph @

scripts/mpg123info

raw
1 #!/bin/bash
2
3 if test $# -eq 0; then
4 echo "Give me some MPEG 1.0/2.0/2.5 layer 1/2/3 audio file name(s) and I give you meta info about it in an easily-parseable format:
5
6 name=value
7
8 for simple value association and
9
10 name.=value
11
12 to add another line to existing value (multiline comments)."
13 fi
14
15 for i in "$@"
16 do
17 echo lp "$i"
18 echo tag
19 echo scan
20 echo format
21 echo sample
22 done |
23 mpg123 -t -R |
24 perl -e '
25 while(<STDIN>)
26 {
27 if(/\@T \{/)
28 {
29 print "# meta info for: ".(shift @ARGV)."\n";
30 $field = undef;
31 %count = ();
32 %linecount = ();
33 }
34 elsif(/\@T ID3:(.*)$/)
35 {
36 $field = undef;
37 print "ID3v1.title=".substr($1, 0, 30)."\n";
38 print "ID3v1.artist=".substr($1, 30, 30)."\n";
39 print "ID3v1.album=".substr($1, 60, 30)."\n";
40 print "ID3v1.year=".substr($1, 90, 4)."\n";
41 print "ID3v1.comment=".substr($1, 94, 30)."\n";
42 print "ID3v1.genre=".substr($1, 124)."\n";
43 }
44 elsif(/\@T ID3\.([^:]+):(.*)$/)
45 {
46 $field = undef;
47 print "ID3.$1=$2\n";
48 }
49 elsif(/\@T (ID3v2\.\S{4})(|\s+lang\(([^\(\)]*)\)\s+desc\(([^\(\)]*)\)):/)
50 {
51 $class = $1;
52 $field = ++$count{$class} > 1 ? "$class$count{$class}" : $class;
53 print "$field.lang=$3\n" if(defined $3);
54 print "$field.desc=$4\n" if(defined $4);
55 }
56 elsif(/\@T =(.*)$/)
57 {
58 next unless defined $field;
59 print "$field".(++$linecount{$field} > 1 ? ".=" : "=").$1."\n";
60 }
61 elsif(/\@FORMAT\s+(\d+)\s+(\d+)/)
62 {
63 print "format.rate=$1\n";
64 print "format.channels=$2\n";
65 }
66 elsif(/\@SAMPLE\s+(\d+)\s+(\d+)/)
67 {
68 print "samples=$2\n";
69 }
70 }
71 ' "$@"