13
13
14
14
class PlaylistDiff extends SpotifyClient{
15
15
16
- public function diff (string $ playlistID1 , string $ playlistID2, bool $ createAsPlaylist = false ):array {
16
+ public function diff (string $ playlistID1 , string $ playlistID2 ):array {
17
17
$ p1 = array_keys ($ this ->getPlaylist ($ playlistID1 ));
18
18
$ p2 = array_keys ($ this ->getPlaylist ($ playlistID2 ));
19
19
$ diff = array_diff ($ p1 , $ p2 );
20
20
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 );
28
27
29
28
return $ diff ;
30
29
}
31
30
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
+
32
48
}
33
49
34
50
/**
@@ -37,4 +53,5 @@ public function diff(string $playlistID1, string $playlistID2, bool $createAsPla
37
53
*/
38
54
39
55
$ 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