rss feed fixes

This commit is contained in:
Arvid Norberg 2012-02-20 23:44:34 +00:00
parent 75fce84ce4
commit d24a2e30fc
4 changed files with 25 additions and 14 deletions

View File

@ -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 ``<ttl>``
tag) and defaults to 30 minutes. The field specifies the number of

View File

@ -842,7 +842,7 @@ int save_file(std::string const& filename, std::vector<char>& 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<libtorrent::torrent_handle> const& non_files
, handles_t& files, std::set<libtorrent::torrent_handle>& non_files
, int* counters, boost::unordered_set<torrent_status>& all_handles
, std::vector<torrent_status const*>& 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<const std::string, torrent_handle>(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;

View File

@ -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<rss_alert>())
{
@ -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);

View File

@ -1414,8 +1414,8 @@ namespace aux {
m_feeds.reserve(settings->list_size());
for (int i = 0; i < settings->list_size(); ++i)
{
boost::shared_ptr<feed> f(new_feed(*this, feed_settings()));
if (settings->list_at(i)->type() != lazy_entry::dict_t) continue;
boost::shared_ptr<feed> 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
// --------------------------------------------------------------