diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-11-02 17:03:41 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-11-02 17:03:41 +0100 |
commit | 1112136fc283b4a169ae49ed3a6d8345b45b7447 (patch) | |
tree | bc2fb03cfb1b2693153b6b83b32b49c59c5906a8 /.local/bin/linkview | |
parent | linkview fix (diff) | |
download | dotfiles-bsd-1112136fc283b4a169ae49ed3a6d8345b45b7447.tar.gz dotfiles-bsd-1112136fc283b4a169ae49ed3a6d8345b45b7447.tar.bz2 dotfiles-bsd-1112136fc283b4a169ae49ed3a6d8345b45b7447.tar.xz dotfiles-bsd-1112136fc283b4a169ae49ed3a6d8345b45b7447.tar.zst dotfiles-bsd-1112136fc283b4a169ae49ed3a6d8345b45b7447.zip |
Async dl is cool
Diffstat (limited to '.local/bin/linkview')
-rwxr-xr-x | .local/bin/linkview | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/.local/bin/linkview b/.local/bin/linkview index 908841c..53ad829 100755 --- a/.local/bin/linkview +++ b/.local/bin/linkview @@ -4,6 +4,8 @@ use strict; use warnings; use Scalar::Util qw(looks_like_number); use File::HomeDir qw(home); +use File::Basename qw(basename); +use Cwd qw(cwd); use Term::ReadKey; use Term::ANSIColor qw(colored); @@ -15,12 +17,17 @@ use constant { SXIV_PATH => '/usr/local/bin/sxiv', ZATHURA_PATH => '/usr/local/bin/zathura', W3M_PATH => '/usr/local/bin/w3m', - FIREFOX_PATH => '/usr/local/bin/firefox' + FIREFOX_PATH => '/usr/local/bin/firefox', + NOTIFYSEND_PATH => '/usr/local/bin/notify-send' }; sub open_link { my ($a, $url) = @_; + my $pid; + my $file_name; + my $pwd; + my $ret; if ($a == 1) { exec( @@ -29,20 +36,59 @@ sub open_link ); } elsif ($a == 2 || $a == 3) { - chdir home() . "/dl" or - chdir home() . "/Downloads" or - chdir home() or die $!; - if ($a == 2) { - exec( - YTDL_PATH, - $url - ); - } - else { - exec( - FETCH_PATH, - $url + $pid = fork(); + if ($pid == 0) { + chdir home() . "/dl" or + chdir home() . "/Downloads" or + chdir home() or die $!; + if (basename(cwd()) eq basename(home())) { + $pwd = '~/'; + } + else { + $pwd = '~/' . basename(cwd()); + } + $file_name = $url; + $file_name =~ s/.+\///g; + system( + NOTIFYSEND_PATH, + '-u', + 'normal', + '-t', + '10000', + ' download started', + '<b>' . $file_name . '</b> started downloading' ); + $ret = -1; + if ($a == 2) { + $ret = system(YTDL_PATH . " -q '" . $url . "' 2>/dev/null"); + } + else { + $ret = system(FETCH_PATH . " -q '" . $url . "' 2>/dev/null"); + } + if ($ret == 0) { + system( + NOTIFYSEND_PATH, + '-u', + 'normal', + '-t', + '10000', + ' download complete', + '<b>' . $file_name . '</b> downloaded successfully to ' + . '<b>' . $pwd . '</b>' + ); + } + else { + system( + NOTIFYSEND_PATH, + '-u', + 'critical', + '-t', + '10000', + ' download failed', + 'failed to download <b>' . $file_name . '</b>' + ); + } + exit 0; } } elsif ($a == 4) { |