Skip to content

Instantly share code, notes, and snippets.

@ryochin
Created September 21, 2012 07:55
Show Gist options
  • Save ryochin/3760259 to your computer and use it in GitHub Desktop.
Save ryochin/3760259 to your computer and use it in GitHub Desktop.
recover incomplete feed url for Fresh Reader broken OPML
#!/usr/bin/perl --
# fill real rss feed url for Fresh Reader broken OPML
use strict;
use warnings;
use Path::Class qw(file);
use CGI;
use Feed::Find;
use utf8;
use Encode ();
my $file = shift @ARGV or die;
my $fh = file( $file )->openr or die $!;
my $n = 0;
while( defined( my $line = $fh->getline ) ){
chomp $line;
$line = Encode::decode_utf8( $line );
$n++;
if( $line !~ m{xmlUrl="(.+?(rss|xml|atom|rdf|opml)|(/(feed|rss)/?))"} ){ # "
if( $line !~ /Delicious/ and $line =~ s{xmlUrl="([^"]+?)"}{xmlUrl="__URL__"}o ){ # "
my $url = $1;
if( my @feed = Feed::Find->find( $url ) ){
my $feed = CGI::escapeHTML( $feed[0] );
$line =~ s{__URL__}{$feed};
}
else{
( my $title = $line ) =~ s{^.+?text="([^"]+?)".+?$}{$1}; # "
printf STDERR "feed not found: %d: %s: %s\n", $n, Encode::encode_utf8( $title ), $url;
next;
}
}
}
print Encode::encode_utf8( $line ), "\n";
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment