utvarp / music-helper
该包已被 废弃 并不再维护。未建议替代包。
尝试将音乐来源统一到一个方便的包中 🎶
1.1.2
2017-04-30 12:24 UTC
Requires
- php: ^7.0
- akerbis/musixmatch: dev-master
- atomescrochus/laravel-string-similarities: ^1.1
- deezer/deezer-php-sdk: dev-master
- illuminate/support: ^5.4
Requires (Dev)
- phpunit/phpunit: 5.*
This package is auto-updated.
Last update: 2022-02-01 13:06:57 UTC
README
周围有很多音乐信息源。也许你只想搜索其中之一。也许你需要同时拥有许多。这个包就是为了你而存在的!
安装
您可以通过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
愿望单 / 路线图 / 求助 👷🚧👷♀️
- 缓存搜索,以便我们不会太快达到API速率限制
- 更多来源
- Gracenote (https://github.com/StukiOrg/GracenoteClient-PHP ?)
- Spotify (https://github.com/Shemahmforash/SpotifyWebApi ?)
- Discogs (https://github.com/ShaneCullinane/discogs ?)
- iTunes (https://github.com/jacoz/php-itunes-api ?)
- Musicbrainz (https://github.com/PBXg33k/MusicBrainz ?)
- Google Play Music
- 为来源添加更多信息 (?)
- 添加方法,以便在来源API中进行更精确的搜索(例如:通过基本搜索返回的ID进行搜索)?
来源
如何创建新的来源
这应该很简单。按照以下步骤操作,并查看对应的 deezer
来源文件,然后从中构建即可!
- 在
src\Searches\{SourceName}.php
中创建一个新的搜索类。此类应仅负责对源API进行搜索。 - 在
src\Models\{SourceName}Result.php
中创建一个新的模型类。此类应仅负责正确 格式化 通过API接收到的结果,并使用基Result
模型中的相应方法设置track
、artist
和album
值。 - 将
sourceName
添加到src\Music.php
构造函数中的possibleSources
集合。 - (如有需要)在
src\Music.php
的构造函数中添加一个设置源 API 密钥的方法,并将源添加到apiKeys
集合中。 - 测试您的操作,但现在应该一切正常!
现有源
- Deezer(API 密钥:不需要)
- Musixmatch(API 密钥:需要)
测试
$ composer test
更新日志
更改可以在仓库的发布页面找到。
贡献
欢迎贡献,感谢所有寄出东西的人 :)
许可
MIT 许可证(MIT)。请参阅许可文件获取更多信息。