hansott/lastify

此包已被废弃,不再维护。未建议替代包。

Lastify 同步 Spotify 播单与您的 last.fm 顶级曲目。

1.0.2 2016-03-12 13:56 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:54:12 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Lastify 是一个同步 Last.fm、Spotify 等平台音乐之间的 PHP 库。

安装

通过 Composer

$ composer require hansott/lastify

使用方法

  1. 生成 Spotify 访问令牌:[Spotify API 控制台](https://developer.spotify.com/web-api/console/get-current-user/)(OAuth 范围:playlist-read-private, playlist-modify-public & playlist-modify-private)
  2. 创建 last.fm API 账户并复制 API 密钥:[创建 API 账户](http://www.last.fm/api/account/create)(注意:创建后无法查看您的 API 账户。)
<?php

error_reporting(-1);
ini_set('display_errors', 'On');

require_once __DIR__.'/../vendor/autoload.php';

use HansOtt\Lastify\TrackInfo;
use HansOtt\Lastify\Synchronizer;
use HansOtt\Lastify\Services\LastFm;
use HansOtt\Lastify\Services\Spotify;
use HansOtt\Lastify\SyncProgressCallback;

$lastFm = LastFm::connect('your-lastfm-api-key');
$spotify = Spotify::connect('your-spotify-access-token');

$synchronizer = new Synchronizer($spotify);
$topTracks = $lastFm->getTopTracks('your-lastfm-username', 20);
$lovedTracks = $lastFm->getLovedTracks('your-lastfm-username', 20);

class ProgressCallback implements SyncProgressCallback {
    public function onProgress($current, $total, TrackInfo $currentItem)
    {
        echo sprintf("[%s/%s] Syncing %s \n", $current, $total, $currentItem->toString());
    }
}

$synchronizer->syncToPlaylist('Top Tracks', $topTracks, new ProgressCallback());
$synchronizer->syncToPlaylist('Loved Tracks', $lovedTracks, new ProgressCallback());
~/Code/lastify master $ php examples/syncTopTracks.php
[1/20] Syncing This Is the Life - Amy Macdonald
[2/20] Syncing Banquet - Bloc Party
[3/20] Syncing The Passenger - Iggy Pop
[4/20] Syncing A Forest - The Cure
[5/20] Syncing Not Alone - Time
[6/20] Syncing Somebody Told Me - The Killers
[7/20] Syncing This Modern Love - Bloc Party
[8/20] Syncing Ex's & Oh's - Elle King
[9/20] Syncing Octopus - Bloc Party
[10/20] Syncing Ratchet - Bloc Party
[11/20] Syncing Comptine d'un autre été, l'après-midi - Yann Tiersen
[12/20] Syncing Soft Spoken Words - Trixie Whitley
[13/20] Syncing Back to Black - Amy Winehouse
[14/20] Syncing Pocket Piano - DJ Mehdi
[15/20] Syncing Lucky Boy - DJ Mehdi
[16/20] Syncing Starblazer - Deetron
[17/20] Syncing Wappy Flirt - Original Mix - Hi-Lo
[18/20] Syncing Signatune (Thomas Bangalter edit) - DJ Mehdi
[19/20] Syncing Slowly - Festival Mix - Dropout
[20/20] Syncing The Aviating - Alec Troniq

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

测试

$ composer test

贡献

请参阅CONTRIBUTINGCONDUCT 获取详细信息。

安全

如果您发现任何安全相关的问题,请通过电子邮件 hansott at hotmail be 报告,而不是使用问题跟踪器。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件