diff --git a/README.md b/README.md
index dd022342309f2c5c1f78bdbac25ecc697efc4e2b..196022b8d4a7e9650818b4a67920c75feb357e7d 100644
--- a/README.md
+++ b/README.md
@@ -40,3 +40,4 @@ - DateTime
- DateTime::Format::ISO8601
- HTML::Strip
- Python 3 for `gcat`
+- wget
diff --git a/orrg.pl b/orrg.pl
index de98956f87a350bc1cd6a85b1a46fa1c1585b325..8da5f714c55956f5e00bbf5cd8275a873249d2ae 100755
--- a/orrg.pl
+++ b/orrg.pl
@@ -38,21 +38,28 @@ {
my ( $qs ) = @_;
my @body = ();
- my $feed = feed_get($qs);
- if ( !defined($feed) ) {
+ my $content = feed_get($qs);
+ if ( !defined($content) || $content eq '' ) {
push @body, ('# orrg error', '', 'The requested feed could not be loaded. :(', '', '=> '. $qs .' open feed in browser');
- return @body;
- }
-
- push @body, '# '. trim_ws($feed->title);
- push @body, 'fetched '. strftime('%Y-%m-%dT%H:%M:%SZ', gmtime());
- push @body, '';
- $feed->description eq '' or push @body, trim_ws($feed->description);
- $feed->image eq '' or push @body, '=> '. $feed->image .' feed image';
- $feed->link eq '' or push @body, ('=> '.$feed->link.' open website', '');
+ } else {
+ my $feed = feed_parse($content);
+
+ if (defined($feed)) {
+ recent_add($qs, trim_ws($feed->title));
+ popular_add($qs, trim_ws($feed->title));
- foreach my $it ($feed->get_item()) { push @body, @{item($it)}; }
+ push @body, '# '. trim_ws($feed->title);
+ push @body, 'fetched '. strftime('%Y-%m-%dT%H:%M:%SZ', gmtime());
+ push @body, '';
+ $feed->description eq '' or push @body, trim_ws($feed->description);
+ $feed->image eq '' or push @body, '=> '. $feed->image .' feed image';
+ $feed->link eq '' or push @body, ('=> '.$feed->link.' open website', '');
+ foreach my $it ($feed->get_item()) { push @body, @{item($it)}; }
+ } else {
+ push @body, ('# orrg error', '', 'The requested feed could be loaded but not parsed. :(', '', '=> '. $qs .' open feed in native client');
+ }
+ }
push @body, ('', '', '=> ./index.pl [home]');
return @body;
}
@@ -101,17 +108,22 @@ sub feed_get
{
my ( $query ) = @_;
- my $feed;
- if ( $query =~ /^https\:\/\// ) { $feed = XML::FeedPP->new($query, utf8_flag => 1); }
+ my $content;
+ if ( $query =~ /^https\:\/\// ) { $content = `wget -qO - $query`; }
if ( $query =~ /^gemini\:\/\// ) {
- my $content = `./gcat $query`;
+ $content = `./gcat $query`;
$content =~ /20\W/ or return undef;
$content =~ s/^[0-9]{0,2}\W.+\r\n//;
- $feed = XML::FeedPP->new($content, -type => 'string', utf8_flag => 1);
}
-
- recent_add($query, $feed->title);
- popular_add($query, $feed->title);
- $feed->sort_item();
+
+ return $content;
+}
+
+sub feed_parse
+{
+ my ($content) = @_;
+
+ my $feed = XML::FeedPP->new($content, -type => 'string', utf8_flag => 1);
+ if (defined($feed)) { $feed->sort_item(); }
return $feed;
}