I've been using the Liferea RSS news reader to aggregate headlines from news sites, blogs, and comics for a while now, usually content with the non-automated method of copying the target of the RSS link from a web page and pasting it into Liferea's new subscription dialog.

But today, I decided to sign up for InformationWeek's feed, and found out that they were way too cool to just have a plain RSS link; instead they have several specialized links for many desktop and online news readers, along with a generic one called USM. Liferea doesn't seem to support this format natively, so I decided to read about the format and write some kind of wrapper.

A USM feed is just a normal RSS feed, with two special parts: first, it uses the application/rss+xml content type to signal a browser that it's a special feed, and second, an Atom link element containing the URL that points to the feed. Finding this element and extracting its link target requires just a few lines of XML::Parser-based code to match the element name and attributes in a start tag handler

Once I have that URL, I can use Liferea's D-Bus interface to tell the running process to subscribe to the feed. Liferea comes with a little bash script to do this, which i ported to Perl and Net::DBus:

dbus-send --session --dest=org.gnome.feed.Reader /org/gnome/feed/Reade +r org.gnome.feed.Reader.Subscribe string:$URL

And here is the Perl script to put all this together. It takes a filename on the command line (and is thus suitable for calling from a web browser) and starts parsing it as XML. Once it finds a link that matches its criterea, it sends the URL to Liferea then exits, so as not to waste time walking through the rest of the feed.

#!/usr/bin/perl use strict; use warnings; use XML::Parser; use Net::DBus; sub start_handler { my ($expat, $elem, %attr) = @_; return unless $elem =~ /link/ && exists $attr{rel}; if ($attr{rel} eq 'self' || $attr{rel} eq 'start') { register_feed($attr{href}); exit 0; } } my $xp = new XML::Parser(Handlers => {Start => \&start_handler}); $xp->parsefile($ARGV[0]); exit 1; sub register_feed { my $url = shift; my $bus = Net::DBus->session; my $service = $bus->get_service('org.gnome.feed.Reader'); my $liferea = $service->get_object('/org/gnome/feed/Reader', 'org.gnome.feed.Reader'); $liferea->Subscribe($url); }

In reply to Universal Subscription Mechanism wrapper for RSS reader by ailivac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.