aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/FairViewer/Utils.pm
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-03-13 16:22:25 +0200
committerJesús <heckyel@hyperbola.info>2020-03-14 12:03:00 -0500
commitd2c82222588f72f2313c2d1658b30ac611d69d06 (patch)
tree9c3ac0902495c810b0d88212b848433f4a649aeb /lib/WWW/FairViewer/Utils.pm
parentfa551c2d122cff235ef79e24833a1223fd7458d0 (diff)
downloadfair-viewer-d2c82222588f72f2313c2d1658b30ac611d69d06.tar.lz
fair-viewer-d2c82222588f72f2313c2d1658b30ac611d69d06.tar.xz
fair-viewer-d2c82222588f72f2313c2d1658b30ac611d69d06.zip
- Extract URLs in description from `descriptionHtml` field. (https://github.com/trizen/fair-viewer/issues/6) - Added the `--api-host=<...>` command-line option for changing the API host. - Fixed the `--info=<URL>` option.
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'lib/WWW/FairViewer/Utils.pm')
-rw-r--r--lib/WWW/FairViewer/Utils.pm25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/WWW/FairViewer/Utils.pm b/lib/WWW/FairViewer/Utils.pm
index 5ca1106..09c0174 100644
--- a/lib/WWW/FairViewer/Utils.pm
+++ b/lib/WWW/FairViewer/Utils.pm
@@ -452,8 +452,29 @@ Get description.
sub get_description {
my ($self, $info) = @_;
- my $desc = $info->{description};
- (defined($desc) and $desc =~ /\S/) ? $desc : 'No description available...';
+
+ my $desc = $info->{descriptionHtml} // '';
+
+ require URI::Escape;
+ require HTML::Entities;
+
+ $desc =~ s{<a href="/redirect\?(.*?)".*?>.*?</a>}{
+ my $url = $1;
+ if ($url =~ /(?:^|;)q=([^&]+)/) {
+ URI::Escape::uri_unescape($1);
+ }
+ else {
+ $url;
+ }
+ }segi;
+
+ $desc =~ s/<br>/\n/gi;
+ $desc =~ s{<a href=".*?".*?>(.*?)</a>}{$1}sgi;
+ $desc =~ s/<.*?>//gs;
+
+ $desc = HTML::Entities::decode_entities($desc);
+
+ ($desc =~ /\S/) ? $desc : 'No description available...';
}
=head2 get_title($info)