From d24a2e30fcb7fd6f0354840aa56580ba2ce6c2d8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 20 Feb 2012 23:44:34 +0000 Subject: [PATCH] rss feed fixes --- docs/manual.rst | 13 +++++++++++-- examples/client_test.cpp | 9 +++++---- src/rss.cpp | 12 +++++------- src/session_impl.cpp | 5 ++++- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index cc41a65c8..53c46d2fe 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1165,6 +1165,7 @@ appear. The feed is defined by the ``feed_settings`` object:: std::string url; bool auto_download; + bool auto_map_handles; int default_ttl; add_torrent_params add_args; }; @@ -1174,12 +1175,20 @@ the feed will be downloaded. Set this to false in order to manually add torrents to the session. You may react to the rss_alert_ when a feed has been updated to poll it for the new items in the feed when adding torrents manually. When torrents are added automatically, -you have to call ``session::get_torrents()`` to get the handles to -the new torrents. +an add_torrent_alert_ is posted which includes the torrent handle +as well as the error code if it failed to be added. You may also call +``session::get_torrents()`` to get the handles to the new torrents. Before adding the feed, you must set the ``url`` field to the feed's url. It may point to an RSS or an atom feed. +``auto_map_handles`` defaults to true and determines whether or +not to set the ``handle`` field in the ``feed_item``, returned +as the feed status. If auto-download is enabled, this setting +is ignored. If auto-download is not set, setting this to false +will save one pass through all the feed items trying to find +corresponding torrents in the session. + The ``default_ttl`` is the default interval for refreshing a feed. This may be overridden by the feed itself (by specifying the ```` tag) and defaults to 30 minutes. The field specifies the number of diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 9c874831f..903e4b705 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -842,7 +842,7 @@ int save_file(std::string const& filename, std::vector& v) // returns true if the alert was handled (and should not be printed to the log) // returns false if the alert was not handled bool handle_alert(libtorrent::session& ses, libtorrent::alert* a - , handles_t& files, std::set const& non_files + , handles_t& files, std::set& non_files , int* counters, boost::unordered_set& all_handles , std::vector& filtered_handles , bool& need_resort) @@ -902,6 +902,8 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a if (!filename.empty()) files.insert(std::pair(filename, h)); + else + non_files.insert(h); h.set_max_connections(max_connections_per_torrent); h.set_max_uploads(-1); @@ -1841,9 +1843,8 @@ int main(int argc, char* argv[]) feed_status st = i->get_feed_status(); if (st.url.size() > 70) st.url.resize(70); - snprintf(str, sizeof(str), "%-70s %c %4d (%2d) %s\n", st.url.c_str() - , st.updating? 'u' : '-' - , st.next_update + snprintf(str, sizeof(str), "%-70s %s (%2d) %s\n", st.url.c_str() + , st.updating ? "updating" : to_string(st.next_update).elems , int(st.items.size()) , st.error ? st.error.message().c_str() : ""); out += str; diff --git a/src/rss.cpp b/src/rss.cpp index 42a634dd2..586f9d670 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -374,12 +374,8 @@ void feed::on_feed(error_code const& ec error_code e; // #error session_impl::add_torrent doesn't support magnet links via url - m_ses.add_torrent(p, e); - - if (e) - { - // #error alert! - } + torrent_handle h = m_ses.add_torrent(p, e); + m_ses.m_alerts.post_alert(add_torrent_alert(h, p, e)); } } @@ -402,6 +398,7 @@ void feed::on_feed(error_code const& ec { TORRENT_SETTING(std_string, url) TORRENT_SETTING(boolean, auto_download) + TORRENT_SETTING(boolean, auto_map_handles) TORRENT_SETTING(integer, default_ttl) }; #undef TORRENT_SETTING @@ -505,6 +502,7 @@ void feed::update_feed() if (m_updating) return; m_last_attempt = time(0); + m_last_update = 0; if (m_ses.m_alerts.should_post()) { @@ -536,7 +534,7 @@ void feed::get_feed_status(feed_status* ret) const int feed::next_update(time_t now) const { - if (m_last_update == 0) return INT_MAX; + if (m_last_update == 0) return m_last_attempt + 60 * 5 - now; int ttl = m_ttl == -1 ? m_settings.default_ttl : m_ttl; TORRENT_ASSERT((m_last_update + ttl * 60) - now < INT_MAX); return int((m_last_update + ttl * 60) - now); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 07b52169e..3546ae2ae 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1414,8 +1414,8 @@ namespace aux { m_feeds.reserve(settings->list_size()); for (int i = 0; i < settings->list_size(); ++i) { - boost::shared_ptr f(new_feed(*this, feed_settings())); if (settings->list_at(i)->type() != lazy_entry::dict_t) continue; + boost::shared_ptr f(new_feed(*this, feed_settings())); f->load_state(*settings->list_at(i)); f->update_feed(); m_feeds.push_back(f); @@ -3001,6 +3001,9 @@ namespace aux { } #endif + // don't do any of the following while we're shutting down + if (m_abort) return; + // -------------------------------------------------------------- // RSS feeds // --------------------------------------------------------------