From 846e7c70f5278bcdfc518facd6a8f33ce71ce5b0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 13 Apr 2008 13:30:12 +0000 Subject: 2008-04-13 Tatsuhiro Tsujikawa Implemented auto protocol detection. Now you can do: aria2c -Z http://host/file file1.torrent file2.metalink (Note: -Z option is required for auto protcol detection.) Then aria2c downloads 3 files simultaneously: 1. http://host/file 2. file1.torrent <-- read local torrent file 3. file2.metalink <-- read local Metalink file. Same thing goes with -i option. Assume your uris.txt contans: http://host/file file1.torrent file2.metalink Then you can do: aria2c -i uris.txt (Note: -Z option is not needed if -i option is given.) * src/main.cc * src/ProtocolDetector.{cc, h} * test/ProtocolDetectorTest.cc --- src/ProtocolDetector.cc | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/ProtocolDetector.cc (limited to 'src/ProtocolDetector.cc') diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc new file mode 100644 index 00000000..9a01736f --- /dev/null +++ b/src/ProtocolDetector.cc @@ -0,0 +1,76 @@ +/* */ +#include "ProtocolDetector.h" +#include "Request.h" +#include +#include +#include + +namespace aria2 { + +ProtocolDetector::ProtocolDetector() {} + +ProtocolDetector::~ProtocolDetector() {} + +bool ProtocolDetector::isStreamProtocol(const std::string& uri) const +{ + return Request().setUrl(uri); +} + +bool ProtocolDetector::guessTorrentFile(const std::string& uri) const +{ + std::ifstream in(uri.c_str()); + if(in) { + char head; + in >> head; + return head == 'd'; + } else { + return false; + } +} + +bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const +{ + std::ifstream in(uri.c_str()); + if(in) { + char head[6]; + in >> std::setw(6) >> head; + return strcmp(head, "