File: cdtext.pl

package info (click to toggle)
libdevice-cdio-perl 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,852 kB
  • sloc: ansic: 14,413; perl: 4,795; makefile: 19; sh: 3
file content (83 lines) | stat: -rwxr-xr-x 2,396 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl -w
# Program to show cdtext, similar to examples/cdtext.c
#
#  Copyright (C) 2012, 2017 Rocky Bernstein <rocky@gnu.org>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

# use Enbugger; Enbugger->load_debugger('trepan'); Enbugger->stop;

use strict;
use lib '../blib/lib';
use lib '../blib/arch';
use perlcdio;
use Device::Cdio;
use Device::Cdio::Device;

sub print_cdtext_track_info($$)
{
    my ($cdtext_ref, $t) = @_;

    if ($t != 0) {
	printf("Track #%2d\n", $t);
    } else {
	printf "CD-Text title for Disc\n";
    }

    foreach my $field (sort keys %{$cdtext_ref}) {
	printf "\t%s: %s\n", $Device::Cdio::CDTEXT_FIELD_by_id{$field},
	    $cdtext_ref->{$field} if defined($cdtext_ref->{$field});
    }
}

my $drive_name;
my $d;
if ($ARGV[0]) {
    $drive_name = $ARGV[0];
    $d = Device::Cdio::Device->new($drive_name);
    if (!$d) {
	print "Problem opening CD-ROM: $drive_name\n";
	exit 1;
    }
} else {
    $d = Device::Cdio::Device->new(undef, $perlcdio::DRIVER_UNKNOWN);
    if ($d) {
	$drive_name = $d->get_device();
    } else {
	print "Problem finding a CD-ROM\n";
	exit 1;
    }
}

my $i_tracks = $d->get_num_tracks();
my $first_track = $d->get_first_track;
my $last_track = $d->get_last_track();

$perlcdio::VERSION_NUM >= 10100 or die "Your version of libcdio is too old\n";

my $langs =  $d->cdtext_list_languages();
if ($langs) {
    foreach my $lang (@$langs) {
	if ($lang != $perlcdio::CDTEXT_LANGUAGE_UNKNOWN) {
	    printf "Language: %s\n", $Device::Cdio::CDTEXT_LANGUAGE_by_id{$lang};
	    my $text = $d->get_disc_cdtext();
	    print_cdtext_track_info($text, 0);

	    for (my $track=$first_track->{track}; $track <= $last_track->{track}; $track++) {
		my $text = $d->get_track_cdtext($track);
		print_cdtext_track_info($text, $track);
	    }
	}
    }
}