mrfeathers/acoustid
Composer 安装命令:
composer require mrfeathers/acoustid
包简介
Object Oriented PHP Wrapper for acoustid.org API
README 文档
README
This package is an object oriented PHP wrapper for acoustid.org API.
Installation
Just require this package using Composer:
composer require mrfeathers/acoustid
Usage
Create an instance of AcoustIdClient:
$apiKey = 'here is your api key'; $acoustidClient = AcoustidFactory::create($apiKey);
Also, you can create client without api key. In this case, you are able to use
listByMBIdmethod, that doesn't need api key. All other methods throws an exception in this case.
Now you're ready!
So, acoustid.org has some available actions, that are represented in the package client:
- Lookup by fingerprint
If you have an audio fingerprint generated by Chromaprint, you can use this method to lookup the MusicBrainz metadata associated with this fingerprint.
$fingerPrintContent = 'fingerprint string generated by Chromaprint'; $fingerPrintDuration = 100; //meta can be empty, it's not required $meta = [ Meta::RECORDINGS, Meta::RELEASES, ]; $resultCollection = $acoustidClient->lookupByFingerPrint($fingerPrintContent, $fingerPrintDuration, $meta);
You will get an instance of class ResultCollection, contains several (or one) objects of Result class.
ResultCollection is iterable, so you can just use it as array:
foreach($resultCollection as $result) { //do something }
- Lookup by track id
You can also look up data connected to a track ID, witch is a cluster of fingerprints.
//track id is a simple uuid string $trackId = '08268577-90f3-4ed5-8154-5768e2091554'; //meta can be empty, it's not required $meta = [ Meta::RECORDINGS, Meta::RELEASES, ]; $resultCollection = $acoustidClient->lookupByTrackId($trackId, $meta);
The result also will be ResultCollection.
- Submit fingerprint
The AcoustID database depends on user-submitted content. This method can be used to submit new audio fingerprints and their corresponding metadata to the database. Multiple fingerprints can be submitted in one call.
Submissions are processed asynchronously by a background job. However, this normally only takes a few
seconds, so if your application needs to get the imported AcoustIDs back, you can use the wait parameter
to wait until the submissions are imported. It is not guaranteed that the submissions will be imported
on time, so your application must be able to handle the case when the submission is still in the
"pending" status. You can look up the status of the pending submissions later (use method getSubmissionStatus).
While you can submit a fingerprint without any metadata, it is not very useful to do so. If the file has embedded MusicBrainz tags, please send the MusicBrainz recording ID. Otherwise you can send the textual metadata.
Use FingerPrintCollection instance as argument. This class is just a wrapper under array of FingerPrint objects.
//create collection of fingerprints $fingerPrintCollection = new FingerPrintCollection([ new FingerPrint('fingerprint string generated by Chromaprint', 100), new FingerPrint('fingerprint string generated by Chromaprint', 121), ]); //also you can add FingerPrint later by addFingerPrint method $fingerPrint = new FingerPrint('....', 200); //FingerPrint object has a lot of additional fields, that you can set calling setters $fingerPrint->setArtist('artist name') ->setAlbum('album name'); $fingerPrintCollection->addFingerPrint($fingerPrint); $userApiKey = 'here is your personal user key'; //wait is not required and equls 1 by default. Use it if you need to wait until the submissions are imported $wait = 1; $submissionCollection = $acoustidClient->submit($fingerPrintCollection, $userApiKey, $wait);
You will get an instance of SubmissionCollection as a result. It's also iterable and contains one or more Submission objects.
- Get submission status
If you submitted an fingerprint and it was imported immediately, you can check the status of the submission
by looking up the ID from the submit call.
//let's get submisstionCollection from the previous example $submission = array_shift($submissionCollection); $result = $acoustidClient->getSubmissionStatus($submission->getId());
The result also will be an instance of SubmissionCollection.
- List AcoustIDs by MBID
This method will return you a list of AcoustId id that are corresponding to MusicBrainz id.
Api key is not required for this method, so you can use client without key to call it
You can send one or more mbids. If you send one, than you'll get the result as instance of TrackCollection.
If you send more than one - instance of MBIdCollection. Both are iterable.
$mbids = ['83b3d37d-8c3d-4a7b-ae9a-d635e4e3374f']; $trackCollection = $acoustidClient->listByMBId($mbids); //add one more mbid $mbids[] = 'b00db402-51d2-4125-912b-c0eab9c6edd1'; //and you'll get MBIdCollection, each MBId object for each sent mbid $mbidCollection = $acoustidClient->listByMBId($mbids);
Response models and Meta
Response models contain all known fields acoustid.org API can return. Unfortunately, acoustid.org doesn't have a full documentation
for all possible response structures. So if you get an AcoustidSerializerException exception, please open an issue and provide
method and parameters you used to call it.
Here's the descriptions of all response models:
Collection response models:
NB! Response models has a lot of fields, but some of them can be empty. It's because of scope of meta parameters you send to the method. Different scope of meta values can return different results. All available meta values you can find in the class
Meta. It's highly recommended to use constants fromMetaclass for creating meta array.
mrfeathers/acoustid 适用场景与选型建议
mrfeathers/acoustid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「library」 「music」 「Fingerprint」 「acoustid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mrfeathers/acoustid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrfeathers/acoustid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mrfeathers/acoustid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Inbox pattern process implementation for your Laravel Applications
Core library that defines common interfaces used by the rest of the intahwebz..
Amqp classes
Provides command to manage a web library directory
Alfabank REST API integration
统计信息
- 总下载量: 75
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-19