You are not logged in.

#1 2010-08-27 15:43:03

tsv
Member
From: UK
Registered: 2008-12-03
Posts: 71
Website

Convert OPML to Voracious' format

I just stumbled on Xyne's Voracious feed aggregator, and liked the look of it (I had thought of writing something similar). I had a big fat OPML file though, which I didn't want to move into this new format by hand, so I wrote a Perl script to do it.

I don't have anywhere nice to host it, so if someone wants to throw it up someplace, feel free. Otherwise, if you make use of it, it would be cool to hear any feedback, I haven't thrown many different files at it.

The first argument should be the OPML file to convert, an optional second argument says where to output, or by default it will put it in the default Voracious config location so be careful not to overwrite an existing config.

#!/usr/bin/env perl 

# Converts an OPML file to a format readable by Voracious.
# Written by Trevor Vallender <tsv AT tsv DOT me DOT uk>.
# Released into the public domain.

use warnings;
use strict;
use XML::XPath;

my $input;
my $output;

sub main {
    get_args( );

    open( OUTPUT, ">", $output ) or die $!;
    print( OUTPUT "[paths]\n/\n" );

    my $xp = XML::XPath->new( filename => $input );
    foreach my $outline ( $xp->find( '/opml/body/outline' )->get_nodelist ) {
        parse_outline( $outline, '', \*OUTPUT );
    }
    
    close( OUTPUT );
}

sub parse_outline {
    my ( $outline, $parent, $fref ) = @_;
    if ( $outline->find( '@type' )->string_value eq 'folder' ) {
        $parent .= '/'.$outline->find( '@title' )->string_value;
        $parent =~ s/ /_/g;
        print( $fref $parent . "\n");
        foreach my $subol ( $outline->find( 'outline' )->get_nodelist ) {
            parse_outline( $subol, $parent, $fref );
        }
    } elsif ( $outline->find( '@type' )->string_value eq 'vfolder' ) {
        # Ignore them
    } else {
        print( $fref "\t" . $outline->find( '@xmlUrl' )->string_value . "\n" );
    }
}

sub get_args {
    my $config_path = "/voracious/config.txt";

    if ( $#ARGV == 0 ) {
        $input = $ARGV[0];
        if ( $ENV{XDG_CONFIG_HOME} ) {
            $output = $ENV{XDG_CONFIG_HOME} . $config_path;
        } else{
            $output = "~/.config" . $config_path;
        }
    } elsif ( $#ARGV == 1 ) {
        $input = $ARGV[0];
        $output = $ARGV[1];
    } else {
        print STDERR "Invalid input\n";
        exit;
    }
}

main( );

Offline

Board footer

Powered by FluxBB