From b53537b780fc73f5a764755b993ab95bf8fd36f1 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Thu, 21 Mar 2019 22:40:16 -0400 Subject: [PATCH] Implemented functionality to download songs from the Icarus music server --- src/Main.cpp | 5 +++++ src/Syncers/Download.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/Syncers/Download.h | 5 +++++ 3 files changed, 46 insertions(+) diff --git a/src/Main.cpp b/src/Main.cpp index 379b247..13e3d09 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -37,11 +37,16 @@ int main(int argc, char** argv) } cout<<"Song path: "< +#include + +#include + +using std::cout; +using std::endl; +using std::ofstream; +using std::string; + namespace Syncers { 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: "< +#include namespace Syncers { @@ -9,7 +10,11 @@ namespace Syncers { public: Download(); + Download(std::string); + + void downloadSong(int); private: + std::string downloadFilePath; }; }