00001
00002
00003
00004
00005
00006
00007
00008 #include <iostream>
00009 #include <fstream>
00010 #include <iterator>
00011 #include <iomanip>
00012
00013 #include "libtorrent/entry.hpp"
00014 #include "libtorrent/bencode.hpp"
00015 #include "libtorrent/torrent_info.hpp"
00016
00017 int main(int argc, char* argv[])
00018 {
00019 using namespace libtorrent;
00020
00021 if (argc != 2)
00022 {
00023 std::cerr << "usage: dump_torrent torrent-file\n";
00024 return 1;
00025 }
00026
00027 boost::filesystem::path::default_name_check(boost::filesystem::no_check);
00028
00029 try
00030 {
00031 std::ifstream in(argv[1], std::ios_base::binary);
00032 in.unsetf(std::ios_base::skipws);
00033 entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
00034
00035 std::cout << "\n\n----- raw info -----\n\n";
00036 e.print(std::cout);
00037
00038 torrent_info t(e);
00039
00040
00041 std::cout << "\n\n----- torrent file info -----\n\n";
00042 std::cout << "nodes:\n";
00043 typedef std::vector<std::pair<std::string, int> > node_vec;
00044 node_vec const& nodes = t.nodes();
00045 for (node_vec::const_iterator i = nodes.begin(), end(nodes.end());
00046 i != end; ++i)
00047 {
00048 std::cout << i->first << ":" << i->second << "\n";
00049 }
00050 std::cout << "trackers:\n";
00051 for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
00052 i != t.trackers().end(); ++i)
00053 {
00054 std::cout << i->tier << ": " << i->url << "\n";
00055 }
00056
00057 std::cout << "number of pieces: " << t.num_pieces() << "\n";
00058 std::cout << "piece length: " << t.piece_length() << "\n";
00059 std::cout << "info hash: " << t.info_hash() << "\n";
00060 std::cout << "comment: " << t.comment() << "\n";
00061 std::cout << "created by: " << t.creator() << "\n";
00062 std::cout << "files:\n";
00063 for (torrent_info::file_iterator i = t.begin_files();
00064 i != t.end_files(); ++i)
00065 {
00066 std::cout << " " << std::setw(11) << i->size
00067 << " " << i->path.string() << "\n";
00068 }
00069
00070 }
00071 catch (std::exception& e)
00072 {
00073 std::cout << e.what() << "\n";
00074 }
00075
00076 return 0;
00077 }
00078