1313
1414class PlaylistDiff extends SpotifyClient{
1515
16- public function diff (string $ playlistID1 , string $ playlistID2, bool $ createAsPlaylist = false ):array {
16+ public function diff (string $ playlistID1 , string $ playlistID2 ):array {
1717 $ p1 = array_keys ($ this ->getPlaylist ($ playlistID1 ));
1818 $ p2 = array_keys ($ this ->getPlaylist ($ playlistID2 ));
1919 $ diff = array_diff ($ p1 , $ p2 );
2020
21- if ($ createAsPlaylist ){
22- $ playlistID = $ this ->createPlaylist (
23- 'playlist diff ' ,
24- sprintf ('diff between playlists "spotify:playlist:%s" and "spotify:playlist:%s" ' , $ playlistID1 , $ playlistID2 )
25- );
26- $ this ->addTracks ($ playlistID , $ diff );
27- }
21+ $ playlistID = $ this ->createPlaylist (
22+ 'playlist diff ' ,
23+ sprintf ('diff between playlists "spotify:playlist:%s" and "spotify:playlist:%s" ' , $ playlistID1 , $ playlistID2 )
24+ );
25+
26+ $ this ->addTracks ($ playlistID , $ diff );
2827
2928 return $ diff ;
3029 }
3130
31+ public function merge (string $ targetID , string ...$ playlistIDs ):array {
32+ $ merged = $ this ->getPlaylist ($ targetID );
33+
34+ foreach ($ playlistIDs as $ playlistID ){
35+ $ merged = array_merge ($ merged , $ this ->getPlaylist ($ playlistID ));
36+ }
37+
38+ $ playlistID = $ this ->createPlaylist (
39+ 'playlist merge ' ,
40+ sprintf ('merged playlists "%s" into "spotify:playlist:%s" ' , implode ('", " ' , $ playlistIDs ), $ targetID )
41+ );
42+
43+ $ this ->addTracks ($ playlistID , array_keys ($ merged ));
44+
45+ return $ merged ;
46+ }
47+
3248}
3349
3450/**
@@ -37,4 +53,5 @@ public function diff(string $playlistID1, string $playlistID2, bool $createAsPla
3753 */
3854
3955$ spotify = $ factory ->getProvider (PlaylistDiff::class, OAuthExampleProviderFactory::STORAGE_FILE );
40- $ spotify ->diff ('37i9dQZF1DX4UtSsGT1Sbe ' , '37i9dQZF1DXb57FjYWz00c ' , true );
56+ $ spotify ->diff ('37i9dQZF1DX4UtSsGT1Sbe ' , '37i9dQZF1DXb57FjYWz00c ' );
57+ $ spotify ->merge ('37i9dQZF1DX4UtSsGT1Sbe ' , '37i9dQZF1DXb57FjYWz00c ' );
0 commit comments