From 4b6c26bd0b580b06950d11fe040f09634c2ffb2a Mon Sep 17 00:00:00 2001 From: luddens Date: Wed, 22 Jan 2020 15:44:10 +0100 Subject: [PATCH] add parameter option to start a download with aria2 Downloader::startDownload has a new parameter option which is a vector of pair that represents the options that can be set for adding a uri with aria2 with the function Aria2::addUri. Aria2::addUri uses this parameter to set the struct of parameters for the aria2 command --- include/downloader.h | 2 +- src/aria2.cpp | 5 ++++- src/aria2.h | 2 +- src/downloader.cpp | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/downloader.h b/include/downloader.h index b60e48136..c809423df 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -92,7 +92,7 @@ class Downloader void close(); - Download* startDownload(const std::string& uri); + Download* startDownload(const std::string& uri, const std::vector>& options = {}); Download* getDownload(const std::string& did); size_t getNbDownload() { return m_knownDownloads.size(); } diff --git a/src/aria2.cpp b/src/aria2.cpp index 9c6da41a9..efa9e3f3b 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -160,13 +160,16 @@ std::string Aria2::doRequest(const MethodCall& methodCall) throw std::runtime_error("Cannot perform request"); } -std::string Aria2::addUri(const std::vector& uris) +std::string Aria2::addUri(const std::vector& uris, const std::vector>& options) { MethodCall methodCall("aria2.addUri", m_secret); auto uriParams = methodCall.newParamValue().getArray(); for (auto& uri : uris) { uriParams.addValue().set(uri); } + for (auto& option : options) { + methodCall.newParamValue().getStruct().addMember(option.first).getValue().set(option.second); + } auto ret = doRequest(methodCall); MethodResponse response(ret); return response.getParamValue(0).getAsS(); diff --git a/src/aria2.h b/src/aria2.h index 898904a5d..9108d221e 100644 --- a/src/aria2.h +++ b/src/aria2.h @@ -34,7 +34,7 @@ class Aria2 virtual ~Aria2(); void close(); - std::string addUri(const std::vector& uri); + std::string addUri(const std::vector& uri, const std::vector>& options = {}); std::string tellStatus(const std::string& gid, const std::vector& statusKey); std::vector tellActive(); std::vector tellWaiting(); diff --git a/src/downloader.cpp b/src/downloader.cpp index 393810d2a..8f103df5b 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -163,7 +163,7 @@ std::vector Downloader::getDownloadIds() { return ret; } -Download* Downloader::startDownload(const std::string& uri) +Download* Downloader::startDownload(const std::string& uri, const std::vector>& options) { for (auto& p: m_knownDownloads) { auto& d = p.second; @@ -172,7 +172,7 @@ Download* Downloader::startDownload(const std::string& uri) return d.get(); } std::vector uris = {uri}; - auto gid = mp_aria->addUri(uris); + auto gid = mp_aria->addUri(uris, options); m_knownDownloads[gid] = std::unique_ptr(new Download(mp_aria, gid)); return m_knownDownloads[gid].get(); }