diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-12-23 13:21:12 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-12-23 13:21:12 +0000 |
| commit | 2745d85597f593d07a9b3a8b6cd9d23592d6fcc4 (patch) | |
| tree | 0783177476cccaef9b24ea32651cf03abce3f05e /src/UTMetadataPostDownloadHandler.cc | |
| parent | 9b933ca4061fa8d616a615ad89534291c931667a (diff) | |
2009-12-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --bt-save-metadata option. When true is given, it saves
metadata as .torrent file. This option has effect only when
BitTorrent Magnet URI is used. The filename is name in metadata
with suffix .torrent. The directory to be saved is the same
directory where download file is saved. If the same file already
exists, metdata is not saved.
* src/OptionHandlerFactory.cc
* src/UTMetadataPostDownloadHandler.cc
* src/UTMetadataPostDownloadHandler.h
* src/message.h
* src/prefs.cc
* src/prefs.h
* src/usage_text.h
* test/UTMetadataDataExtensionMessageTest.cc
Diffstat (limited to 'src/UTMetadataPostDownloadHandler.cc')
| -rw-r--r-- | src/UTMetadataPostDownloadHandler.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/UTMetadataPostDownloadHandler.cc b/src/UTMetadataPostDownloadHandler.cc index 024960c5..7d8f8dc0 100644 --- a/src/UTMetadataPostDownloadHandler.cc +++ b/src/UTMetadataPostDownloadHandler.cc @@ -41,11 +41,15 @@ #include "A2STR.h" #include "DownloadContext.h" #include "Logger.h" +#include "LogFactory.h" #include "util.h" #include "a2functional.h" #include "DiskAdaptor.h" #include "PieceStorage.h" #include "bencode.h" +#include "message.h" +#include "prefs.h" +#include "Option.h" namespace aria2 { @@ -63,7 +67,8 @@ bool UTMetadataPostDownloadHandler::Criteria::match return false; } -UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler() +UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler(): + _logger(LogFactory::getInstance()) { setCriteria(SharedHandle<Criteria>(new Criteria())); } @@ -82,6 +87,22 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups std::deque<std::string>(), torrent); requestGroup->followedBy(newRgs.begin(), newRgs.end()); groups.insert(groups.end(), newRgs.begin(), newRgs.end()); + + if(!newRgs.empty() && + requestGroup->getOption()->getAsBool(PREF_BT_SAVE_METADATA)) { + SharedHandle<DownloadContext> dctx = newRgs.front()->getDownloadContext(); + assert(dctx->hasAttribute(bittorrent::BITTORRENT)); + std::string filename = requestGroup->getOption()->get(PREF_DIR); + filename += A2STR::SLASH_C; + filename += + dctx->getAttribute(bittorrent::BITTORRENT)[bittorrent::NAME].s(); + filename += ".torrent"; + if(util::saveAs(filename, torrent)) { + _logger->notice(MSG_METADATA_SAVED, filename.c_str()); + } else { + _logger->notice(MSG_METADATA_NOT_SAVED, filename.c_str()); + } + } } } // namespace aria2 |
