diff options
Diffstat (limited to '')
| -rwxr-xr-x | .local/bin/linkview | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/.local/bin/linkview b/.local/bin/linkview index 7cb1ba4..aba3993 100755 --- a/.local/bin/linkview +++ b/.local/bin/linkview @@ -61,17 +61,16 @@ sub notify sub vid { - my ($url, $article_name) = @_; + my ($url) = @_; my $pid; - $article_name = "some media" unless defined $article_name; $pid = fork(); if (not $pid) { setsid(); close_io(); - notify(' playing ' . $article_name); + notify('playing ' . $url . '...'); if (system(MPV_PATH, "--force-window=yes", $url) != 0) { - notify(' failed to open ' . $url); + notify('[!] failed to open ' . $url); } return; } @@ -80,7 +79,7 @@ sub vid sub img_pdf { - my ($url, $article_name, $key) = @_; + my ($url, $key) = @_; my $file_name; my $new_file_name; my $pid; @@ -89,7 +88,6 @@ sub img_pdf my $ug; my $uuid; - $article_name = "some media" unless defined $article_name; $pid = fork(); if (not $pid) { setsid(); @@ -98,19 +96,19 @@ sub img_pdf $file_name = $url; $file_name =~ s/.+\///g; if (is_yt($url) != 0) { - notify(' fetching thumbnail for ' . $article_name); + notify('fetching thumbnail...'); ($tmp, undef, $ret) = capture { system(YTDL_PATH, '--get-thumbnail', $url); }; chomp $tmp; if ($ret != 0) { - notify(' failed to get thumbail for ' . $article_name); + notify('[!] failed to get thumbail'); return; } $url = $tmp; } else { - notify(' fetching ' . $file_name . ' to /tmp'); + notify('fetching ' . $file_name . ' to /tmp'); } $file_name = $url; $file_name =~ s/.+\///g; @@ -132,7 +130,7 @@ sub img_pdf $ret = system(ZATHURA_PATH, $new_file_name); } if ($ret != 0) { - notify(' failed to open file /tmp/'. $new_file_name); + notify('[!] failed to open file /tmp/'. $new_file_name); } unlink($new_file_name); return; @@ -197,7 +195,7 @@ sub dl $file_name .= "[...]"; } $file_name =~ s/^[0-9]+/\[\.\.\.\]/; - notify(' downloading ' . $file_name); + notify('downloading ' . $file_name); if (is_yt($url) != 0) { $tmpfile = `mktemp`; chomp $tmpfile; @@ -205,31 +203,42 @@ sub dl if (not $pid2) { (undef, undef, $ret) = capture { if ($quality eq 'uncap') { - system(YTDL_PATH . ' --newline --add-metadata ' . $url . ' >' . $tmpfile); + system(YTDL_PATH . + ' --newline --add-metadata ' . + $url . ' >' . $tmpfile); } elsif ($quality eq '1440') { - system(YTDL_PATH . " -f '308+140' --newline --add-metadata " . $url . ' >' . $tmpfile); + system(YTDL_PATH . + " -f '308+140' --newline --add-metadata " . + $url . ' >' . $tmpfile); } elsif ($quality eq '1080') { - system(YTDL_PATH . " -f '299+140' --newline --add-metadata " . $url . ' >' . $tmpfile); + system(YTDL_PATH . + " -f '299+140' --newline --add-metadata " . + $url . ' >' . $tmpfile); } elsif ($quality eq '720') { - system(YTDL_PATH . " -f '298+140' --newline --add-metadata " . $url . ' >' . $tmpfile); + system(YTDL_PATH . + " -f '298+140' --newline --add-metadata " . + $url . ' >' . $tmpfile); } else { - system(YTDL_PATH . " -f '[height<=" . $quality . "]' --newline --add-metadata " . $url . ' >' . $tmpfile); + system(YTDL_PATH . + " -f '[height<=" . $quality . + "]' --newline --add-metadata " . + $url . ' >' . $tmpfile); } }; if ($ret == 0) { - notify(' ' . $file_name . ' downloaded successfully to ' . $pwd); + notify($file_name . ' downloaded successfully to ' . $pwd); } else { - notify(' failed to download ' . $file_name); + notify('[!] failed to download ' . $file_name); } return; } elsif ($pid2 < 0) { - notify(' failed to fork(2)'); + notify('[!] failed to fork(2)'); return; } else { @@ -237,9 +246,11 @@ sub dl while (1) { $val = `tail -n 1 "$tmpfile" | awk '{print \$2}' | tr -d '%'`; if (looks_like_number($val) != 0) { - notify(' downloading ' . $file_name . ': - ' . $val); - if ($val == 100 || system('pgrep yt-dlp >/dev/null 2>&1') != 0) { + chomp($val); + notify('downloading ' . $file_name . ': +' . $val . '%'); + if ($val == 100 || + system('pgrep yt-dlp >/dev/null 2>&1') != 0) { last; } } @@ -249,7 +260,7 @@ sub dl } $count += 1; } - sleep 2; + sleep 10; } unlink $tmpfile; } @@ -264,16 +275,16 @@ sub dl } }; if ($ret == 0) { - notify(' ' . $file_name . ' downloaded successfully to ' . $pwd); + notify($file_name . ' downloaded successfully to ' . $pwd); } else { - notify(' failed to download ' . $file_name); + notify('[!] failed to download ' . $file_name); } } return; } elsif ($pid < 0) { - notify(' failed to fork(2)'); + notify('[!] failed to fork(2)'); return; } return; @@ -281,14 +292,14 @@ sub dl sub audio { - my ($url, $article_name) = @_; + my ($url) = @_; my $pid; $pid = fork(); if (not $pid) { setsid(); close_io(); - notify(' playing ' . $article_name); + notify('playing ' . $url . '...'); if (system( TERMINAL_PATH, "-e", @@ -298,7 +309,7 @@ sub audio "--no-video", $url ) != 0) { - notify(' failed to open ' . $url); + notify('[!] failed to open ' . $url); } return; } @@ -315,7 +326,7 @@ sub w3m setsid(); close_io(); if (system(TERMINAL_PATH, '-e', W3M_PATH, $url) != 0) { - notify(' failed to open ' . $url); + notify('[!] failed to open ' . $url); } return; } @@ -367,7 +378,7 @@ sub clip exec(COPYQ_PATH, "copy", $url); } } - notify(' clipped url'); + notify('clipped url'); return; } @@ -399,7 +410,7 @@ sub get_yt_vid_name my ($url) = @_; my $file_name; - notify(' looking for video name'); + notify('looking for video name...'); $file_name = `yt-dlp -e $url`; if (not $file_name) { $file_name = "yt video"; |
