utvarp/music-helper

该包已被 废弃 并不再维护。未建议替代包。

尝试将音乐来源统一到一个方便的包中 🎶

1.1.2 2017-04-30 12:24 UTC

This package is auto-updated.

Last update: 2022-02-01 13:06:57 UTC


README

Latest Version on Packagist Total Downloads Software License Build Status

周围有很多音乐信息源。也许你只想搜索其中之一。也许你需要同时拥有许多。这个包就是为了你而存在的!

安装

您可以通过composer安装此包

composer require utvarp/music-helper

用法

目前,此包将仅获取 基本信息

  • 请求来源的曲目名称和ID;
  • (如果可用) 请求来源的艺术家的名称和ID;
  • (如果可用) 请求来源的专辑名称和ID;

目前,您需要通过源API(使用ID)进行额外调用以获取更多详细信息。

除了源API的信息外,该包还将对结果的曲目和艺术家名称与实际搜索结果之间进行字符串相似性检查。这样,您可以选择不相信源的列表顺序,并通过相似度评分进行排序。

以下是您如何使用此包的示例

$music = new Utvarp\MusicHelper\Music();

// If the source you want to use needs an API key, you would include it like so
// You can see in the available source list in the readme if an API needs a key
$music->setMusixmatchAPiKey($key); // method names are in this fashion: set{Sourcename}APIKey

// You're not forced to chain the methods, but search should go at the end.
// You only need either an artist or a track, and call the search method to go.
// Source takes a string, an array or a collection of the possible sources, default is 'all'.
// The integer passes to search is the maximum result you want returned from an API, default is 25.
$search = $music->source('all')->artist('Lady Gaga')->track('Poker Face')->search(15);

// Now, out of all the source, if you wanted to get the Deezer results (but it could be any available source)
$deezerResults = $search->getResults('deezer');

$count = $deezerResults->count; // fetch the total results count
$results = $deezerResults->results; // get the actual result collection

// You could acccess a specific result
$result = $results->first(); // Since it's a collection, the usual methods are available
//or
$result = $results[0]; // But you can still access a collection like an array, if you prefer

// From the result, you have access to a track, artist and album object.
$trackId = $result->track->id;
$trackName = $result->track->name;
$albumName = $result->album->name;

// In those objects (except album), you also have access to a the similarity score from 3 different algorithms
$similarTextScore = $result->track->similarityScores->similar_text; // maximum score of 100.0
$smgScore = $result->track->similarityScores->smg; // Smith Waterman Gotoh score, maximum of 1.0
$levenshteinScore = $result->track->similarityScores->levenshtein; // Levenshtein score, maximum of 1

愿望单 / 路线图 / 求助 👷🚧👷‍♀️

来源

如何创建新的来源

这应该很简单。按照以下步骤操作,并查看对应的 deezer 来源文件,然后从中构建即可!

  1. src\Searches\{SourceName}.php 中创建一个新的搜索类。此类应仅负责对源API进行搜索。
  2. src\Models\{SourceName}Result.php 中创建一个新的模型类。此类应仅负责正确 格式化 通过API接收到的结果,并使用基 Result 模型中的相应方法设置 trackartistalbum 值。
  3. sourceName 添加到 src\Music.php 构造函数中的 possibleSources 集合。
  4. (如有需要)在 src\Music.php 的构造函数中添加一个设置源 API 密钥的方法,并将源添加到 apiKeys 集合中。
  5. 测试您的操作,但现在应该一切正常!

现有源

  • Deezer(API 密钥:不需要
  • Musixmatch(API 密钥:需要

测试

$ composer test

更新日志

更改可以在仓库的发布页面找到。

贡献

欢迎贡献,感谢所有寄出东西的人 :)

许可

MIT 许可证(MIT)。请参阅许可文件获取更多信息。