spotify api to get playlists of a user

2019-02-15 09:32发布

i need to use the api of Spotify my client needs to have a spotify application that will connect to the spotify on behalf of the registered user and will fetch all the playlist names and their songs in those playlist, and will make a txt file of those playlist, thats it. please help me where should i start , i need to get it done with php.

Thanks

标签: php spotify
2条回答
时光不老,我们不散
2楼-- · 2019-02-15 09:43

As mentioned in the comments, there is a lot of code circling around using the unfortunate not open source libspotify. The API examples provided, carefully omitting a way to iterate over all playlists.

You mention that you want something that can connect to spotify (the online API is certainly what Spotify would like everyone to use) but I'm pretty sure the same can be done offline. As you said yourself, the files can be backed up.

Located in:

~/.config/spotify/Users/name/

or

{USER_APP_DATA}/Spotify/Users/{USER_ID}

You can probably already tell I'm not a fan of proprietary libraries restricting access to what I can or can not do. So I came up with a simple program that can print the names of all stored playlists. This is helpful enough because I usually add one album per playlist.

I'm pretty sure it can be developed further to include individual tracks.

#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>

int main(int argc, char *argv[]) {
    std::vector<char> vbuf;
    unsigned int len;
    std::vector<char>::iterator bpos,dpos,epos;

    std::ifstream in("playlist.bnk", std::ios::in|std::ios::binary);
    if (in) {
        in.seekg(0,std::ios::end);
        len = in.tellg();
        vbuf.resize(len);
        in.seekg(0,std::ios::beg);
        in.read(&vbuf[0],len);

        for(std::vector<char>::iterator it = vbuf.begin(); it != vbuf.end(); ++it) {
            if (*it == (char)0x02 && *(it+1) == (char)0x09) {
                bpos = it+3;
            }                                                                                          
            if (*it == (char)0xE2 && *(it+1) == (char)0x80 && *(it+2) == (char)0x93 && bpos != vbuf.end()) {
                dpos = it;
            }                                                                                          
            if (*it == (char)0x18 && *(it+1) == (char)0x01 && *(it+2) == (char)0x19 && dpos != vbuf.end()) {
                epos = it;
            }                                                                   
            if (bpos != vbuf.end() && dpos != vbuf.end() && epos != vbuf.end()) {
                for(std::vector<char>::iterator it2 = bpos; it2 < dpos; ++it2) {
                    std::cout << *it2;
                }                                                              
                for(std::vector<char>::iterator it2 = dpos; it2 < epos; ++it2) {
                    std::cout << *it2;
                }
                std::cout << std::endl;
                bpos = vbuf.end();
                dpos = vbuf.end();
                epos = vbuf.end();
            }
        }
    }
}
查看更多
Summer. ? 凉城
3楼-- · 2019-02-15 10:01

The Problem was solved by just backing up the playlist.bnk file. which contains the files for playslists

查看更多
登录 后发表回答