-# quvi handles the --exec correctly and escapes the input.
-exec quvi --format best --exec 'wget --no-clobber -O %t.%e %u' "$@"
+use strict;
+use warnings;
+
+use IPC::Run ();
+use JSON ();
+
+
+if (scalar @ARGV != 1) {
+ print STDERR "Usage: $0 <url>\n";
+ exit 1;
+}
+
+
+my ($out, $err);
+my @cmd = ('quvi', $ARGV[0]);
+if (not IPC::Run::run(\@cmd, \undef, \$out, \$err)) {
+ die "'@cmd' died:\n$err";
+}
+
+my $data = JSON::decode_json($out);
+
+my $url = $data->{link}[0]{url};
+my $suffix = $data->{link}[0]{file_suffix};
+
+my $name = $data->{page_title};
+# Strip all non-ASCII characters including "/" which is illegal in file names.
+$name =~ s{[^\x20-\x2E\x30-\x7e]}{-}g;
+
+@cmd = ('wget', '--no-clobber', '--progress=bar:force',
+ '-O', "$name.$suffix", $url);
+exec { $cmd[0] } @cmd or die $!;