diff --git a/src/main.cpp b/src/main.cpp index c1eb766..2d9fca5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,13 @@ int main(int argc, const char* argv[]) { duck::TorrentRead torrent(argv[1], ""); std::cout << "Loaded file into string of size " << torrent.raw_data_size() << '\n'; + std::cout << "Torrent name: " << torrent.read_name() << '\n'; + std::cout << "Created by: " << torrent.read_created_by() << '\n'; + std::cout << "Creation date: " << torrent.read_creation_date() << '\n'; + std::cout << "Comment: " << torrent.read_comment() << '\n'; + std::cout << "Announce: " << torrent.read_announce() << '\n'; + std::cout << "Is private: " << std::boolalpha << torrent.read_is_private() << '\n'; + torrent.print(std::cout); const auto& values = torrent.parsed_values(); @@ -58,7 +65,7 @@ int main(int argc, const char* argv[]) { const std::size_t piece_length = torrent.read_piece_length(); if (0 == file_count) { - std::string file_name{torrent.read_file_name()}; + std::string file_name{torrent.read_name()}; std::cout << "Found file name \"" << file_name << "\"\n"; std::ifstream istream(file_name, std::ios::in|std::ios::binary); diff --git a/src/torrent_read.cpp b/src/torrent_read.cpp index 8c032d8..2ada100 100644 --- a/src/torrent_read.cpp +++ b/src/torrent_read.cpp @@ -115,7 +115,7 @@ const std::vector& TorrentRead::parsed_values() const { return m_parsed_values; } -std::string_view TorrentRead::read_file_name() const { +std::string_view TorrentRead::read_name() const { return find_string("/info/name", m_parsed_values); } @@ -203,6 +203,27 @@ std::size_t TorrentRead::read_file_size (std::size_t index) const { ); } +bool TorrentRead::read_is_private() const { + const auto val = find_int("/info/private", m_parsed_values); + return (val ? true : false); +} + +std::string_view TorrentRead::read_comment() const { + return find_string("/comment", m_parsed_values); +} + +std::string_view TorrentRead::read_created_by() const { + return find_string("/created by", m_parsed_values); +} + +std::string_view TorrentRead::read_announce() const { + return find_string("/announce", m_parsed_values); +} + +std::time_t TorrentRead::read_creation_date() const { + return find_int("/creation date", m_parsed_values); +} + const TorrentValue& TorrentRead::cached_info_files() const { constexpr char info_files[] = "/info/files"; if (not m_cached_info_files) { diff --git a/src/torrent_read.hpp b/src/torrent_read.hpp index b05c720..ab0e7ba 100644 --- a/src/torrent_read.hpp +++ b/src/torrent_read.hpp @@ -43,12 +43,17 @@ public: std::size_t raw_data_size() const; const std::vector& parsed_values() const; - std::string_view read_file_name() const; + std::string_view read_name() const; std::size_t read_piece_length() const; std::int_fast32_t read_file_count() const; std::vector read_file_path(std::size_t index) const; std::string read_joint_file_path(std::size_t index, char sep) const; std::size_t read_file_size(std::size_t index) const; + bool read_is_private() const; + std::string_view read_comment() const; + std::string_view read_created_by() const; + std::string_view read_announce() const; + std::time_t read_creation_date() const; private: const TorrentValue& cached_info_files() const;