stephan-strate/php-cover-art-archive-api

PHP对CoverArtArchive api的封装。支持使用存储库和工厂进行面向对象访问。


README

CoverArtArchive

CoverArtArchive API包装器

CoverArtArchive是Internet ArchiveMusicBrainz的联合项目。该项目的目标是让封面艺术图片对每个人可用。

使用此API包装器,您可以使用MusicBrainz的发布MBID检索封面艺术图片。

建议与stephan-strate/php-music-brainz-api一起使用。

php-github-apiphp-tmdb的启发。

安装

使用composer

$ composer require stephan-strate/php-cover-art-archive-api php-http/guzzle7-adapter:^1.0 http-interop/http-factory-guzzle:^1.0

为什么使用php-http/guzzle7-adapter:^1.0?这个库使用HTTPlug与任何HTTP客户端解耦。

用法

首先创建客户端

$client = new \CoverArtArchive\Client();

使用此客户端,您可以检索所有其他对象/API。

存储库

存储库实现将解码的JSON响应映射到匹配的模型。这是使用库的首选方式。

$repository = new \CoverArtArchive\Repository\ReleaseGroupRepository($client);
$repository->coverArt('19e6209b-2ddc-30b8-9273-484bd075fe7b');

图片

由于CoverArtArchive提供的是图片,因此存储库还可以返回图片资源。

$repository = new \CoverArtArchive\Repository\ReleaseRepository($client);
$image = $repository->coverArtFront('7416e707-94b5-3810-b6b8-4229ab2182ec');

// outputs the image to the user
if ($image !== false) {
    header('Content-Type: image/png');
    imagepng($image);
    imagedestroy($image);
}

API

API实现返回端点的原始JSON响应。您可能想使用存储库实现来获取解析的对象。

$release = $client->release();
$release->coverArt('7416e707-94b5-3810-b6b8-4229ab2182ec');

贡献

帮助与捐赠

我非常好奇使用我的库的项目。请给我发一条简短的信息,说明您如何使用这个库。您可以在我的个人资料(LinkedIn,电子邮件)上找到我的联系信息。

如果这个项目为您节省了时间和金钱,或者您只是欣赏我所做的事情,请考虑赞助我 😊