diff options
author | joe <rbo@gmx.us> | 2025-10-01 21:15:09 +0200 |
---|---|---|
committer | joe <rbo@gmx.us> | 2025-10-01 21:15:09 +0200 |
commit | 7c7fd8baf3c3525d413cc8862856c369efe51145 (patch) | |
tree | a06acc1035b94b8b6c7f9e480a362d3d1f0c9b5b /.local/bin/linkview | |
parent | up (diff) | |
download | dotfiles-bsd-7c7fd8baf3c3525d413cc8862856c369efe51145.tar.gz dotfiles-bsd-7c7fd8baf3c3525d413cc8862856c369efe51145.tar.bz2 dotfiles-bsd-7c7fd8baf3c3525d413cc8862856c369efe51145.tar.xz dotfiles-bsd-7c7fd8baf3c3525d413cc8862856c369efe51145.tar.zst dotfiles-bsd-7c7fd8baf3c3525d413cc8862856c369efe51145.zip |
up
Diffstat (limited to '')
-rwxr-xr-x | .local/bin/linkview | 108 |
1 files changed, 31 insertions, 77 deletions
diff --git a/.local/bin/linkview b/.local/bin/linkview index a4183c3..097d8be 100755 --- a/.local/bin/linkview +++ b/.local/bin/linkview @@ -48,6 +48,17 @@ use constant QUAL_LIST => "" . "240" . "\n" . "144" . "\n"; +sub notify +{ + my ($str) = @_; + + my $pid = fork(); + if (not $pid) { + exec(NOTIFYSEND_PATH, $str); + } + return; +}; + sub vid { my ($url, $article_name) = @_; @@ -58,15 +69,9 @@ sub vid if (not $pid) { setsid(); close_io(); - system( - NOTIFYSEND_PATH, - ' playing ' . $article_name - ); + notify(' playing ' . $article_name); if (system(MPV_PATH, "--force-window=yes", $url) != 0) { - exec( - NOTIFYSEND_PATH, - ' failed to open ' . $url - ); + notify(' failed to open ' . $url); } return; } @@ -93,28 +98,19 @@ sub img_pdf $file_name = $url; $file_name =~ s/.+\///g; if (is_yt($url) != 0) { - system( - NOTIFYSEND_PATH, - ' fetching thumbnail for ' . $article_name - ); + notify(' fetching thumbnail for ' . $article_name); ($tmp, undef, $ret) = capture { system(YTDL_PATH, '--get-thumbnail', $url); }; chomp $tmp; if ($ret != 0) { - system( - NOTIFYSEND_PATH, - ' failed to get thumbail for ' . $article_name - ); + notify(' failed to get thumbail for ' . $article_name); return; } $url = $tmp; } else { - system( - NOTIFYSEND_PATH, - ' fetching ' . $file_name . ' to /tmp' - ); + notify(' fetching ' . $file_name . ' to /tmp'); } $file_name = $url; $file_name =~ s/.+\///g; @@ -136,10 +132,7 @@ sub img_pdf $ret = system(ZATHURA_PATH, $new_file_name); } if ($ret != 0) { - system( - NOTIFYSEND_PATH, - ' failed to open file /tmp/'. $new_file_name - ); + notify(' failed to open file /tmp/'. $new_file_name); } unlink($new_file_name); return; @@ -204,10 +197,7 @@ sub dl $file_name .= "[...]"; } $file_name =~ s/^[0-9]+/\[\.\.\.\]/; - system( - NOTIFYSEND_PATH, - ' downloading ' . $file_name - ); + notify(' downloading ' . $file_name); if (is_yt($url) != 0) { $tmpfile = `mktemp`; chomp $tmpfile; @@ -231,24 +221,15 @@ sub dl } }; if ($ret == 0) { - system( - NOTIFYSEND_PATH, - ' ' . $file_name . ' downloaded successfully to ' . $pwd - ); + notify(' ' . $file_name . ' downloaded successfully to ' . $pwd); } else { - system( - NOTIFYSEND_PATH, - ' failed to download ' . $file_name - ); + notify(' failed to download ' . $file_name); } return; } elsif ($pid2 < 0) { - system( - NOTIFYSEND_PATH, - ' failed to fork(2)' - ); + notify(' failed to fork(2)'); return; } else { @@ -256,11 +237,8 @@ sub dl while (1) { $val = `tail -n 1 "$tmpfile" | awk '{print \$2}' | tr -d '%'`; if (looks_like_number($val) != 0) { - system( - NOTIFYSEND_PATH, - ' downloading ' . $file_name . ': - ' . $val - ); + notify(' downloading ' . $file_name . ': + ' . $val); if ($val == 100 || system('pgrep yt-dlp >/dev/null 2>&1') != 0) { last; } @@ -286,25 +264,16 @@ sub dl } }; if ($ret == 0) { - system( - NOTIFYSEND_PATH, - ' ' . $file_name . ' downloaded successfully to ' . $pwd - ); + notify(' ' . $file_name . ' downloaded successfully to ' . $pwd); } else { - system( - NOTIFYSEND_PATH, - ' failed to download ' . $file_name - ); + notify(' failed to download ' . $file_name); } } return; } elsif ($pid < 0) { - system( - NOTIFYSEND_PATH, - ' failed to fork(2)' - ); + notify(' failed to fork(2)'); return; } return; @@ -319,10 +288,7 @@ sub audio if (not $pid) { setsid(); close_io(); - system( - NOTIFYSEND_PATH, - ' playing ' . $article_name - ); + notify(' playing ' . $article_name); if (system( TERMINAL_PATH, "-e", @@ -332,10 +298,7 @@ sub audio "--no-video", $url ) != 0) { - exec( - NOTIFYSEND_PATH, - ' failed to open ' . $url - ); + notify(' failed to open ' . $url); } return; } @@ -352,10 +315,7 @@ sub w3m setsid(); close_io(); if (system(TERMINAL_PATH, '-e', W3M_PATH, $url) != 0) { - exec( - NOTIFYSEND_PATH, - ' failed to open ' . $url - ); + notify(' failed to open ' . $url); } return; } @@ -407,10 +367,7 @@ sub clip exec(COPYQ_PATH, "copy", $url); } } - system( - NOTIFYSEND_PATH, - ' clipped url' - ); + notify(' clipped url'); return; } @@ -442,10 +399,7 @@ sub get_yt_vid_name my ($url) = @_; my $file_name; - system( - NOTIFYSEND_PATH, - ' looking for video name' - ); + notify(' looking for video name'); $file_name = `yt-dlp -e $url`; if (not $file_name) { $file_name = "yt video"; |