This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d9dfb5
commit 3dc281a
Showing
2 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* playlist-diff.php | ||
* | ||
* @created 31.08.2023 | ||
* @author smiley <[email protected]> | ||
* @copyright 2023 smiley | ||
* @license MIT | ||
*/ | ||
|
||
namespace chillerlan\OAuthExamples\Providers\Spotify; | ||
|
||
use function array_diff; | ||
use function array_keys; | ||
use function sprintf; | ||
|
||
/** | ||
* @var \chillerlan\OAuth\Providers\Spotify $spotify | ||
* @var \Psr\Http\Message\RequestFactoryInterface $requestFactory | ||
* @var \Psr\Log\LoggerInterface $logger | ||
* @var string $CFGDIR | ||
*/ | ||
require_once __DIR__.'/spotify-common.php'; | ||
|
||
$client = new class ($spotify, $logger) extends SpotifyClient{ | ||
|
||
public function playlistDiff(string $playlistID1, string $playlistID2, bool $createAsPlaylist = false):array{ | ||
$p1 = array_keys($this->getPlaylist($playlistID1)); | ||
$p2 = array_keys($this->getPlaylist($playlistID2)); | ||
|
||
$diff = array_diff($p1, $p2); | ||
|
||
if($createAsPlaylist){ | ||
$playlistID = $this->createPlaylist( | ||
'playlist diff', | ||
sprintf('diff between playlists "spotify:playlist:%s" and "spotify:playlist:%s"', $playlistID1, $playlistID2) | ||
); | ||
$this->addTracks($playlistID, $diff); | ||
} | ||
|
||
return $diff; | ||
} | ||
|
||
}; | ||
|
||
$client->playlistDiff('37i9dQZF1DX4UtSsGT1Sbe', '37i9dQZF1DXb57FjYWz00c', true); |