summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-07-16 15:00:35 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-07-16 15:00:35 +0000
commit34036e58aff1deaafddf7736054bc65d163dcdb4 (patch)
treef01ce0112fab868804a18d7e2dcb06e0457b8cb8 /src
parentdb23e29ecfc98c6f5dbf1ffe5e0310a1228dec5a (diff)
2010-07-16 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --on-bt-download-complete=COMMAND option. For BitTorrent, a command specified in --on-download-complete is called when download completes and seeding is over. On the other hand, this option set the command to be executed when download completes but before seeding. * doc/aria2c.1.txt * src/DefaultPieceStorage.cc * src/OptionHandlerFactory.cc * src/prefs.cc * src/prefs.h * src/usage_text.h * src/util.cc * src/util.h
Diffstat (limited to 'src')
-rw-r--r--src/DefaultPieceStorage.cc13
-rw-r--r--src/OptionHandlerFactory.cc10
-rw-r--r--src/prefs.cc2
-rw-r--r--src/prefs.h2
-rw-r--r--src/usage_text.h8
-rw-r--r--src/util.cc6
-rw-r--r--src/util.h3
7 files changed, 44 insertions, 0 deletions
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index a0b0d415..29aa36d6 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -59,6 +59,9 @@
#include "array_fun.h"
#include "PieceStatMan.h"
#include "wallclock.h"
+#ifdef ENABLE_BITTORRENT
+# include "bittorrent_helper.h"
+#endif // ENABLE_BITTORRENT
namespace aria2 {
@@ -363,6 +366,16 @@ void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
} else {
logger_->info(MSG_DOWNLOAD_COMPLETED);
}
+#ifdef ENABLE_BITTORRENT
+ if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
+ SharedHandle<TorrentAttribute> torrentAttrs =
+ bittorrent::getTorrentAttrs(downloadContext_);
+ if(!torrentAttrs->metadata.empty()) {
+ util::executeHookByOptName(downloadContext_->getOwnerRequestGroup(),
+ option_, PREF_ON_BT_DOWNLOAD_COMPLETE);
+ }
+ }
+#endif // ENABLE_BITTORRENT
}
}
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index a0f8d00a..22da4b6b 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -1402,6 +1402,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
handlers.push_back(op);
}
{
+ SharedHandle<OptionHandler> op(new DefaultOptionHandler
+ (PREF_ON_BT_DOWNLOAD_COMPLETE,
+ TEXT_ON_BT_DOWNLOAD_COMPLETE,
+ NO_DEFAULT_VALUE,
+ "/path/to/command"));
+ op->addTag(TAG_ADVANCED);
+ op->addTag(TAG_HOOK);
+ handlers.push_back(op);
+ }
+ {
SharedHandle<NumberOptionHandler> op(new NumberOptionHandler
(PREF_PEER_CONNECTION_TIMEOUT,
NO_DESCRIPTION,
diff --git a/src/prefs.cc b/src/prefs.cc
index 44655a74..eee818e2 100644
--- a/src/prefs.cc
+++ b/src/prefs.cc
@@ -354,6 +354,8 @@ const std::string PREF_BT_TRACKER_TIMEOUT("bt-tracker-timeout");
const std::string PREF_BT_TRACKER_CONNECT_TIMEOUT("bt-tracker-connect-timeout");
// values: 1*digit
const std::string PREF_DHT_MESSAGE_TIMEOUT("dht-message-timeout");
+// values: string
+const std::string PREF_ON_BT_DOWNLOAD_COMPLETE("on-bt-download-complete");
/**
* Metalink related preferences
diff --git a/src/prefs.h b/src/prefs.h
index 273bb861..5beb93f7 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -358,6 +358,8 @@ extern const std::string PREF_BT_TRACKER_TIMEOUT;
extern const std::string PREF_BT_TRACKER_CONNECT_TIMEOUT;
// values: 1*digit
extern const std::string PREF_DHT_MESSAGE_TIMEOUT;
+// values: string
+extern const std::string PREF_ON_BT_DOWNLOAD_COMPLETE;
/**
* Metalink related preferences
diff --git a/src/usage_text.h b/src/usage_text.h
index bd34b847..4e017f8e 100644
--- a/src/usage_text.h
+++ b/src/usage_text.h
@@ -698,3 +698,11 @@
_(" --conditional-get[=true|false] Download file only when the local file is older\n" \
" than remote file. Currently, this function has\n" \
" many limitations. See man page for details.")
+#define TEXT_ON_BT_DOWNLOAD_COMPLETE \
+ _(" --on-bt-download-complete=COMMAND For BitTorrent, a command specified in\n" \
+ " --on-download-complete is called when download\n" \
+ " completes and seeding is over. On the other hand,\n" \
+ " this option sets the command to be executed when\n" \
+ " download completes but before seeding.\n" \
+ " See --on-download-start option for the\n" \
+ " requirement of COMMAND.")
diff --git a/src/util.cc b/src/util.cc
index ea708f31..9c12c6a3 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1395,6 +1395,12 @@ void executeHookByOptName
(const SharedHandle<RequestGroup>& group, const Option* option,
const std::string& opt)
{
+ executeHookByOptName(group.get(), option, opt);
+}
+
+void executeHookByOptName
+(const RequestGroup* group, const Option* option, const std::string& opt)
+{
if(!option->blank(opt)) {
executeHook(option->get(opt), group->getGID());
}
diff --git a/src/util.h b/src/util.h
index 4767d0c7..1cbfa546 100644
--- a/src/util.h
+++ b/src/util.h
@@ -402,6 +402,9 @@ void executeHookByOptName
(const SharedHandle<RequestGroup>& group, const Option* option,
const std::string& opt);
+void executeHookByOptName
+(const RequestGroup* group, const Option* option, const std::string& opt);
+
} // namespace util
} // namespace aria2