在 Perl 中获取音频 CD 的 CDDB 信息的最佳方法是什么?

发布于 2024-08-21 18:02:14 字数 1016 浏览 2 评论 0原文

从音频 CD 获取 CD 标题和 CD 曲目名称的最佳方法是什么? 我尝试了这个模块,但它不起作用。

#!/usr/bin/env perl
use warnings;
use strict;
use CDDB_get qw( get_cddb );

my %config;
$config{CDDB_HOST} = "freedb.freedb.org";
$config{CDDB_PORT} = 8880;
$config{CDDB_MODE} = "cddb";
$config{CD_DEVICE} = "/dev/sr1";

# user interaction welcome?
$config{input} = 1;

my %cd = get_cddb( \%config ); # line 16

print "$_ : $cd{$_}\n" for keys %cd;

unless( defined $cd{title} ) {
    die "no cddb entry found";
}

print "artist: $cd{artist}\n";
print "title: $cd{title}\n";
print "category: $cd{cat}\n";
print "cddbid: $cd{id}\n";
print "trackno: $cd{tno}\n";

my $n = 1;
for my $i ( @{$cd{track}} ) {
    print "track $n: $i\n";
    $n++;
}

# OUT:
# Odd number of elements in hash assignment at ./cddb_get.pl line 16.
# Use of uninitialized value in list assignment at ./cddb_get.pl line 16.
# Use of uninitialized value in concatenation (.) or string at ./cddb_get.pl line 18.
#  :
# no cddb entry found at ./cddb_get.pl line 21.

What is the best way to get the cd-title and the cd-track-names from an audio CD?
I tried this module, but it didn't work.

#!/usr/bin/env perl
use warnings;
use strict;
use CDDB_get qw( get_cddb );

my %config;
$config{CDDB_HOST} = "freedb.freedb.org";
$config{CDDB_PORT} = 8880;
$config{CDDB_MODE} = "cddb";
$config{CD_DEVICE} = "/dev/sr1";

# user interaction welcome?
$config{input} = 1;

my %cd = get_cddb( \%config ); # line 16

print "$_ : $cd{$_}\n" for keys %cd;

unless( defined $cd{title} ) {
    die "no cddb entry found";
}

print "artist: $cd{artist}\n";
print "title: $cd{title}\n";
print "category: $cd{cat}\n";
print "cddbid: $cd{id}\n";
print "trackno: $cd{tno}\n";

my $n = 1;
for my $i ( @{$cd{track}} ) {
    print "track $n: $i\n";
    $n++;
}

# OUT:
# Odd number of elements in hash assignment at ./cddb_get.pl line 16.
# Use of uninitialized value in list assignment at ./cddb_get.pl line 16.
# Use of uninitialized value in concatenation (.) or string at ./cddb_get.pl line 18.
#  :
# no cddb entry found at ./cddb_get.pl line 21.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何以畏孤独 2024-08-28 18:02:14

尝试将其放在

BEGIN { $CDDB_get::debug = 1 }

use CDDB_get 行之前,以获得 STDERR 的调试输出。

Try putting

BEGIN { $CDDB_get::debug = 1 }

before the use CDDB_get line in order to get debugging output to STDERR.

眼眸里的快感 2024-08-28 18:02:14

您确定模块中 FreeDB 的 API URL 正确吗?

您可以尝试使用 HTTP 而不是 CDDBP 吗?

来自 FreeDB 文档

配置您的 CDDB1 或 freedb 感知型
指向 freedb.freedb.org 的软件
(随机 freedb 服务器)作为您的
CDDB/freedb-服务器。

所有官方 f​​reedb 服务器都是
在端口 8880 运行 cddbp 并在以下位置运行 http
端口80。http访问的路径是
/~cddb/cddb.cgi。

Are you sure the API URL to FreeDB is correct in the module?

Can you try HTTP instead of CDDBP?

From the FreeDB documentation:

Configure your CDDB1- or freedb-aware
software to point to freedb.freedb.org
(Random freedb server) as your
CDDB/freedb-server.

All official freedb servers are
running cddbp at port 8880 and http at
port 80. The path for http-access is
/~cddb/cddb.cgi.

橘亓 2024-08-28 18:02:14

我会考虑在 musicbrainz.org 上查找信息。

使用 MusicBrainz::DiscID 查找 CD 的光盘 ID 并使用 WebService::MusicBrainz 检索数据非常简单:

#!/usr/bin/perl

use strict;
use warnings;

use MusicBrainz::DiscID;
use WebService::MusicBrainz;

my $discid=MusicBrainz::DiscID->new;
if ( !$discid->read ) {
    print STDERR "Error: " . $discid->error_msg . "\n";
    exit 1;
}
print "DiscID: " . $discid->id . "\n";

my $service=WebService::MusicBrainz->new_release;
my $response=$service->search({ DISCID=>$discid->id });
my $release=$response->release;

print "ARTIST: " . $release->artist->name . "\n";
print "ALBUM:  " . $release->title . "\n";

I would consider looking information up on musicbrainz.org instead.

Using MusicBrainz::DiscID to find the discid of a cd and WebService::MusicBrainz to retrieve the data is quite easy:

#!/usr/bin/perl

use strict;
use warnings;

use MusicBrainz::DiscID;
use WebService::MusicBrainz;

my $discid=MusicBrainz::DiscID->new;
if ( !$discid->read ) {
    print STDERR "Error: " . $discid->error_msg . "\n";
    exit 1;
}
print "DiscID: " . $discid->id . "\n";

my $service=WebService::MusicBrainz->new_release;
my $response=$service->search({ DISCID=>$discid->id });
my $release=$response->release;

print "ARTIST: " . $release->artist->name . "\n";
print "ALBUM:  " . $release->title . "\n";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文