Implemented functionality to download songs from the Icarus music server

This commit is contained in:
amazing-username
2019-03-21 22:40:16 -04:00
parent e8f2bbcb48
commit b53537b780
3 changed files with 46 additions and 0 deletions
+5
View File
@@ -37,11 +37,16 @@ int main(int argc, char** argv)
} }
cout<<"Song path: "<<songPath<<endl; cout<<"Song path: "<<songPath<<endl;
/**
FileManager fm{songPath}; FileManager fm{songPath};
fm.saveFile(newSongPath); fm.saveFile(newSongPath);
Upload upS{songPath}; Upload upS{songPath};
upS.uploadSong(); upS.uploadSong();
*/
Download df{newSongPath};
df.downloadSong(1);
+36
View File
@@ -1,6 +1,42 @@
#include"Download.h" #include"Download.h"
#include<iostream>
#include<fstream>
#include<cpr/cpr.h>
using std::cout;
using std::endl;
using std::ofstream;
using std::string;
namespace Syncers namespace Syncers
{ {
Download::Download() { } Download::Download() { }
Download::Download(string filePath)
{
downloadFilePath = filePath;
}
void Download::downloadSong(const int id)
{
string urlRoot = "http://192.168.1.5";
int port = 9349;
string endpoint = "api/song/data/" + std::to_string(id);
string url = urlRoot + ":" + std::to_string(port) + "/" +
endpoint;
auto r = cpr::Get(cpr::Url{url});
const char* newBuff = r.text.c_str();
int bufferLength = r.text.size();
ofstream saveSong{downloadFilePath, ofstream::binary};
saveSong.write(newBuff, bufferLength);
cout<<"HTTP status code: "<<r.status_code<<endl;
cout<<"Header info: "<<r.header["content-type"]<<endl;
cout<<"Header info: "<<endl;
cout<<r.header["content-type"]<<endl;
cout<<r.header["content-disposition"]<<endl;
}
} }
+5
View File
@@ -2,6 +2,7 @@
#define DOWNLOAD_H_ #define DOWNLOAD_H_
#include<iostream> #include<iostream>
#include<string>
namespace Syncers namespace Syncers
{ {
@@ -9,7 +10,11 @@ namespace Syncers
{ {
public: public:
Download(); Download();
Download(std::string);
void downloadSong(int);
private: private:
std::string downloadFilePath;
}; };
} }