diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-05-15 23:29:28 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-05-15 23:29:28 +0900 |
| commit | 8e8fb9ee36605a27463737aa803010afbadffec5 (patch) | |
| tree | 19c2d64e4fb2808587b1dce9cfb74e72afaeab42 /src/aria2api.cc | |
| parent | 4e8742597a12989a26ee15239e3c7c5af30d5b96 (diff) | |
Add addTorrent API
Diffstat (limited to 'src/aria2api.cc')
| -rw-r--r-- | src/aria2api.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/aria2api.cc b/src/aria2api.cc index 3159b655..f3634224 100644 --- a/src/aria2api.cc +++ b/src/aria2api.cc @@ -306,6 +306,50 @@ int addMetalink(Session* session, #endif // !ENABLE_METALINK } +int addTorrent(Session* session, + A2Gid* gid, + const std::string& torrentFile, + const std::vector<std::string>& webSeedUris, + const KeyVals& options, + int position) +{ +#ifdef ENABLE_BITTORRENT + const SharedHandle<DownloadEngine>& e = + session->context->reqinfo->getDownloadEngine(); + SharedHandle<Option> requestOption(new Option(*e->getOption())); + std::vector<SharedHandle<RequestGroup> > result; + try { + apiGatherRequestOption(requestOption.get(), options, + OptionParser::getInstance()); + requestOption->put(PREF_TORRENT_FILE, torrentFile); + createRequestGroupForBitTorrent(result, requestOption, webSeedUris, + torrentFile); + } catch(RecoverableException& e) { + A2_LOG_INFO_EX(EX_EXCEPTION_CAUGHT, e); + return -1; + } + if(!result.empty()) { + addRequestGroup(result.front(), e, position); + if(gid) { + *gid = result.front()->getGID(); + } + } + return 0; +#else // !ENABLE_BITTORRENT + return -1; +#endif // !ENABLE_BITTORRENT +} + +int addTorrent(Session* session, + A2Gid* gid, + const std::string& torrentFile, + const KeyVals& options, + int position) +{ + return addTorrent(session, gid, torrentFile, std::vector<std::string>(), + options, position); +} + int removeDownload(Session* session, const A2Gid& gid, bool force) { const SharedHandle<DownloadEngine>& e = |
