├── .gitattributes
├── example.php
├── LICENSE
├── README.md
└── function.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/example.php:
--------------------------------------------------------------------------------
1 | tryLogin($username, $password);
11 | $token = $spotify->getToken($login[1]);
12 |
13 | $json = json_decode($token[1], true);
14 |
15 | $token = $json['accessToken'];
16 |
17 | print_r($spotify->followUser($token, "osyduck"));
18 | print_r($spotify->isFollowUser($token, "osyduck"));
19 | ?>
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Janu Yoga
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Welcome to UnOfficial-Spotify-API 👋
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | > UnOfficial Spotify API Wrapper
13 |
14 | ### 🏠 [Homepage](https://github.com/osyduck/UnOfficial-Spotify-API)
15 |
16 | ### ✨ [Demo](https://github.com/osyduck/UnOfficial-Spotify-API)
17 |
18 | ## Install
19 |
20 | ```sh
21 | git clone https://github.com/osyduck/UnOfficial-Spotify-API.git
22 | ```
23 |
24 | ## Function status
25 | | Function | Status |
26 | |------------------------- |---------------------- |
27 | | `tryLogin` | OK |
28 | | `getToken` | OK |
29 | | `followUser` | OK |
30 | | `isFollowUser` | OK |
31 | | `unfollowUser` | OK |
32 | | `followArtist` | OK |
33 | | `isFollowArtist` | OK |
34 | | `unfollowArtist` | OK |
35 | | `followPlaylist` | OK |
36 | | `isFollowPlaylist` | OK |
37 | | `unfollowPlaylist` | OK |
38 | | `createAccount` | OK |
39 |
40 | ## Usage
41 |
42 | ```sh
43 | php example.php
44 | ```
45 |
46 | ## Author
47 |
48 | 👤 **Janu Yoga**
49 |
50 | * Website: https://januy.co.id
51 | * Github: [@osyduck](https://github.com/osyduck)
52 |
53 | ## 🤝 Contributing
54 |
55 | Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/osyduck/UnOfficial-Spotify-API/issues). You can also take a look at the [contributing guide](https://github.com/osyduck/UnOfficial-Spotify-API/issues).
56 |
57 | ## Show your support
58 |
59 | Give a ⭐️ if this project helped you!
60 |
61 | ## 📝 License
62 |
63 | Copyright © 2020 [Janu Yoga](https://github.com/osyduck).
64 | This project is [MIT](https://github.com/osyduck/UnOfficial-Spotify-API/blob/master/LICENSE) licensed.
65 |
66 | ***
67 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_
--------------------------------------------------------------------------------
/function.php:
--------------------------------------------------------------------------------
1 | ch = curl_init();
9 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
10 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
11 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
12 | }
13 |
14 | private function getCookies()
15 | {
16 | $headers = array();
17 | $headers[] = "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4";
18 | $headers[] = "Upgrade-Insecure-Requests: 1";
19 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
20 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
21 | $headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
22 | $headers[] = "Cache-Control: max-age=0";
23 | $headers[] = "Connection: keep-alive";
24 | curl_setopt($this->ch, CURLOPT_URL, 'https://accounts.spotify.com/');
25 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
26 | curl_setopt($this->ch, CURLOPT_HEADER, true);
27 | $result = curl_exec($this->ch);
28 | preg_match('/^Set-Cookie:\s*(csrf[^;]*)/mi', $result, $m);
29 | parse_str($m[1], $cookies);
30 | $token = $cookies['csrf_token'];
31 | return $token;
32 | }
33 |
34 | public function tryLogin($username, $password)
35 | {
36 | $token = $this->getCookies();
37 | $bon_cookie = base64_encode("0|0|0|0|1|1|1|1");
38 | $headers = array();
39 | $headers[] = "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4";
40 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
41 | $headers[] = "Accept: application/json, text/plain";
42 | $headers[] = "Cookie: sp_t=; sp_new=1; __bon=$bon_cookie; _gat=1; __tdev=VV4fjDj7; __tvis=BGWgw2Xk; spot=; csrf_token=$token; remember=7n4qwa5jrogiu7bysts679i3d";
43 | curl_setopt($this->ch, CURLOPT_URL, 'https://accounts.spotify.com/api/login');
44 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, "remember=false&username=$username&password=$password&csrf_token=$token&continue=https%3A%2F%2Fopen.spotify.com%2F");
45 | curl_setopt($this->ch, CURLOPT_POST, 1);
46 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
47 | curl_setopt($this->ch, CURLOPT_HEADER, true);
48 |
49 | $result = curl_exec($this->ch);
50 |
51 | if(preg_match('/result":"ok/', $result)){
52 | preg_match_all('/^Set-Cookie:\s*([^;\r\n]*)/mi', $result, $kue);
53 | $cookie = "";
54 | for($i=0; $ich, CURLOPT_URL, 'https://open.spotify.com/get_access_token?reason=transport&productType=web_player');
71 | curl_setopt($this->ch, CURLOPT_POST, 0);
72 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
73 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
74 |
75 | $result = curl_exec($this->ch);
76 | if(preg_match("/accessToken/", $result)){
77 | return array(true, $result);
78 | }else{
79 | return array(false);
80 | }
81 | }
82 |
83 | public function followUser($token, $ids)
84 | {
85 | $headers = array();
86 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
87 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
88 | $headers[] = "Accept: text/plain";
89 | $headers[] = "Spotify-App-Version: 8.5.51";
90 | $headers[] = "Authorization: Bearer $token";
91 | $headers[] = "Host: api.spotify.com";
92 | $headers[] = "Connection: keep-alive";
93 |
94 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/me/following?type=user&ids='.$ids);
95 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, '');
96 | curl_setopt($this->ch, CURLOPT_POST, 1);
97 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "PUT");
98 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
99 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
100 |
101 | $result = curl_exec($this->ch);
102 | return $result;
103 | }
104 |
105 | public function isFollowUser($token, $ids)
106 | {
107 | $headers = array();
108 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
109 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
110 | $headers[] = "Accept: text/plain";
111 | $headers[] = "Spotify-App-Version: 8.5.51";
112 | $headers[] = "Authorization: Bearer $token";
113 | $headers[] = "Host: api.spotify.com";
114 | $headers[] = "Connection: keep-alive";
115 |
116 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/me/following/contains?type=user&ids='.$ids);
117 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
118 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
119 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
120 |
121 | $result = curl_exec($this->ch);
122 | return $result;
123 | }
124 |
125 | public function unfollowUser($token, $ids)
126 | {
127 | $headers = array();
128 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
129 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
130 | $headers[] = "Accept: text/plain";
131 | $headers[] = "Spotify-App-Version: 8.5.51";
132 | $headers[] = "Authorization: Bearer $token";
133 | $headers[] = "Host: api.spotify.com";
134 | $headers[] = "Connection: keep-alive";
135 |
136 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/me/following?type=user&ids='.$ids);
137 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, '');
138 | curl_setopt($this->ch, CURLOPT_POST, 1);
139 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE");
140 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
141 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
142 |
143 | $result = curl_exec($this->ch);
144 | return $result;
145 | }
146 |
147 | public function followArtist($token, $ids)
148 | {
149 | $headers = array();
150 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
151 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
152 | $headers[] = "Accept: text/plain";
153 | $headers[] = "Spotify-App-Version: 8.5.51";
154 | $headers[] = "Authorization: Bearer $token";
155 | $headers[] = "Host: api.spotify.com";
156 | $headers[] = "Connection: keep-alive";
157 |
158 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/me/following?type=artist&ids='.$ids);
159 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, '');
160 | curl_setopt($this->ch, CURLOPT_POST, 1);
161 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "PUT");
162 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
163 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
164 |
165 | $result = curl_exec($this->ch);
166 | return $result;
167 | }
168 |
169 | public function isFollowArtist($token, $ids)
170 | {
171 | $headers = array();
172 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
173 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
174 | $headers[] = "Accept: text/plain";
175 | $headers[] = "Spotify-App-Version: 8.5.51";
176 | $headers[] = "Authorization: Bearer $token";
177 | $headers[] = "Host: api.spotify.com";
178 | $headers[] = "Connection: keep-alive";
179 |
180 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/me/following/contains?type=artist&ids='.$ids);
181 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
182 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
183 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
184 |
185 | $result = curl_exec($this->ch);
186 | return $result;
187 | }
188 |
189 | public function unfollowArtist($token, $ids)
190 | {
191 | $headers = array();
192 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
193 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
194 | $headers[] = "Accept: text/plain";
195 | $headers[] = "Spotify-App-Version: 8.5.51";
196 | $headers[] = "Authorization: Bearer $token";
197 | $headers[] = "Host: api.spotify.com";
198 | $headers[] = "Connection: keep-alive";
199 |
200 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/me/following?type=artist&ids='.$ids);
201 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, '');
202 | curl_setopt($this->ch, CURLOPT_POST, 1);
203 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE");
204 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
205 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
206 |
207 | $result = curl_exec($this->ch);
208 | return $result;
209 | }
210 |
211 | public function followPlaylist($token, $playlist_id)
212 | {
213 | $headers = array();
214 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
215 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
216 | $headers[] = "Accept: text/plain";
217 | $headers[] = "Spotify-App-Version: 8.5.51";
218 | $headers[] = "Authorization: Bearer $token";
219 | $headers[] = "Host: api.spotify.com";
220 | $headers[] = "Connection: keep-alive";
221 |
222 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/playlists/'.$playlist_id.'/followers');
223 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, '{"public":false}');
224 | curl_setopt($this->ch, CURLOPT_POST, 1);
225 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "PUT");
226 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
227 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
228 |
229 | $result = curl_exec($this->ch);
230 | return $result;
231 | }
232 |
233 | public function isFollowPlaylist($token, $playlist_id, $ids)
234 | {
235 | $headers = array();
236 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
237 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
238 | $headers[] = "Accept: text/plain";
239 | $headers[] = "Spotify-App-Version: 8.5.51";
240 | $headers[] = "Authorization: Bearer $token";
241 | $headers[] = "Host: api.spotify.com";
242 | $headers[] = "Connection: keep-alive";
243 |
244 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/playlists/'.$playlist_id.'/followers/contains?ids='.$ids);
245 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
246 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
247 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
248 |
249 | $result = curl_exec($this->ch);
250 | return $result;
251 | }
252 |
253 | public function unfollowPlaylist($token, $playlist_id)
254 | {
255 | $headers = array();
256 | $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36";
257 | $headers[] = "Content-Type: application/x-www-form-urlencoded";
258 | $headers[] = "Accept: text/plain";
259 | $headers[] = "Spotify-App-Version: 8.5.51";
260 | $headers[] = "Authorization: Bearer $token";
261 | $headers[] = "Host: api.spotify.com";
262 | $headers[] = "Connection: keep-alive";
263 |
264 | curl_setopt($this->ch, CURLOPT_URL, 'https://api.spotify.com/v1/playlists/'.$playlist_id.'/followers');
265 | curl_setopt($this->ch, CURLOPT_POSTFIELDS, '');
266 | curl_setopt($this->ch, CURLOPT_POST, 1);
267 | curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "DELETE");
268 | curl_setopt($this->ch, CURLOPT_HEADER, 0);
269 | curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
270 |
271 | $result = curl_exec($this->ch);
272 | return $result;
273 | }
274 |
275 | public function createAccount($email, $name, $pass)
276 | {
277 |
278 | $curl = curl_init();
279 | curl_setopt_array($curl, array(
280 | CURLOPT_URL => "https://spclient.wg.spotify.com:443/signup/public/v1/account/",
281 | CURLOPT_RETURNTRANSFER => true,
282 | CURLOPT_ENCODING => "",
283 | CURLOPT_MAXREDIRS => 10,
284 | CURLOPT_TIMEOUT => 0,
285 | CURLOPT_SSL_VERIFYHOST => 0,
286 | CURLOPT_SSL_VERIFYPEER => 0,
287 | CURLOPT_FOLLOWLOCATION => true,
288 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
289 | CURLOPT_CUSTOMREQUEST => "POST",
290 | CURLOPT_POST => 1,
291 | CURLOPT_POSTFIELDS => "email=$email&password_repeat=$pass&password=$pass&key=142b583129b2df829de3656f9eb484e6&gender=male&platform=Android-ARM&creation_point=client_mobile&birth_day=12&birth_month=5&iagree=true&app_version=849800892&birth_year=1990&displayname=$name",
292 | CURLOPT_HTTPHEADER => array(
293 | "Host: spclient.wg.spotify.com",
294 | "User-Agent: Spotify/8.4.98 Android/26 (Custom Tablet)",
295 | "Connection: keep-alive",
296 | "Content-Type: application/x-www-form-urlencoded"
297 | ),
298 | ));
299 |
300 | $response = curl_exec($curl);
301 | return $response;
302 |
303 | }
304 | }
305 | ?>
306 |
--------------------------------------------------------------------------------