spotify api to get playlists of a user

孤者浪人 提交于 2019-12-19 04:02:13

问题


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


回答1:


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();
            }
        }
    }
}



回答2:


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



来源:https://stackoverflow.com/questions/6490137/spotify-api-to-get-playlists-of-a-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!