Added 'url' and 'download' functions

This commit is contained in:
Nox Sluijtman 2023-03-07 18:02:58 +01:00
parent 6904cfdd84
commit 9a270533a3
5 changed files with 57 additions and 9 deletions

View file

@ -1,10 +1,10 @@
# Contributor: Marty Sluijtman <marty.wanderer@disroot.org>
# Maintainer: Marty Sluijtman <marty.wanderer@disroot.org>
pkgname=arbit
pkgver=1.0
pkgrel=2
pkgver=1.2
pkgrel=0
pkgdesc="A wrapper around yt-dlp, mpv and pipe-viewer to watch aribtrary videos without a browser"
url="https://alpine.voidcruiser.nl"
url="https://gitlab.com/EternalWanderer/arbit"
arch="noarch"
license="GPL-3.0"
depends="mpv yt-dlp pipe-viewer"
@ -23,5 +23,5 @@ package() {
install -Dm 644 zsh.completion "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}
sha512sums="
8f59c38d32d6f7ab1b1eece9e8e83eb09ec047ea2435fcce362d1b9528f6b5f54df7d13167f7004259494a35f48c14a934afde1eca7b973bb0b0d77831a57a7e arbit-1.0.tar.gz
3bfb46e8ec224d8a8b05a9efa74852a027dd2b89af2f31fab15109f073eaf87c2aca37038f523969a6ea8913c731b7f3574c4dd01e2419863254a6fd2253d33d arbit-1.2.tar.gz
"

View file

@ -1,6 +1,6 @@
NAME = arbit
PREFIX = /usr/local
VERSION = 1.0
VERSION = 1.2
DIRNAME= $(NAME)-$(VERSION)
MANPAGE = $(NAME).1
MANPREFIX = $(PREFIX)/share/man

41
arbit
View file

@ -4,7 +4,6 @@
videoDir="${XDG_VIDEOS_DIR:-$HOME/Videos}"
downloadDir="${ARBITDIR:-$videoDir/YouTube}"
clipboardContent="$(xclip -o)"
[ -d $downloadDir ] || mkdir -p downloadDir
@ -16,7 +15,12 @@ die(){
exit 1
}
getClip(){
clipboardContent="$(xclip -o)"
}
mpvClip(){
getClip
if $(echo "${clipboardContent}" | grep -qE 'youtube|youtu.be'); then
notify-send "Arbit" "Opening clipboard content with 'pipe-viewer'..."
pipe-viewer --player=mpv "${clipboardContent}" || die "Failed to parse URL"
@ -27,24 +31,54 @@ mpvClip(){
}
clipboardQuery(){
getClip
notify-send "Arbit" "Searching YouTube with:\n\n${clipboardContent}"
pipe-viewer --player=mpv "${clipboardContent}"
}
downloadClipUrl(){
getClip
notify-send "Arbit" "Downloading video to ${downloadDir}"
yt-dlp -o "${downloadDir}/%(title)s - %(uploader)s.%(ext)s" ${clipboardContent} \
&& notify-send "Arbit" "Finished downloading video." \
|| die "Failed to download file"
}
search(){
pipe-viewer --player=mpv "$(echo "$*" | sed 's/search //')"
}
viewUrl(){
url="$(echo $*|sed 's/url //')"
if $(echo "${url}" | grep -qE 'youtube|youtu.be'); then
notify-send "Arbit" "Opening clipboard content with 'pipe-viewer'..."
pipe-viewer --player=mpv "${url}" || die "Failed to parse URL"
else
notify-send "Arbit" "Opening clipboard content with 'mpv'..."
mpv --force-window "${url}" || die "Failed to parse URL"
fi
}
download(){
url="$(echo $*|sed 's/url //')"
notify-send "Arbit" "Downloading video to ${downloadDir}"
yt-dlp -o "${downloadDir}/%(title)s - %(uploader)s.%(ext)s" ${url} \
&& notify-send "Arbit" "Finished downloading video." \
|| die "Failed to download file"
}
usage(){
cat >&2 <<EOF
Usage: $(basename $0) <clipboard-url|clipboard-content|download-url>
Usage: $(basename $0) <clipboard-url|clipboard-content|download-url|url|download>
clipboard-url: open the contents of clipboard in either 'pipe-viewer' or 'mpv'
clipboard-content: open pipe-viewer with clipboard content as search query
download-url: open 'yt-dlp' with clipboard content and save the result to
${downloadDir}
search: use any other given arguments as search query
url: open a given URL in pipe-viewer or mpv
download: open a given URL using 'yt-dlp' and save the result to
${downloadDir}
EOF
}
@ -52,5 +86,8 @@ case $1 in
clipboard-url) mpvClip;;
clipboard-content) clipboardQuery;;
download-url) downloadClipUrl;;
search) search "$*";;
url)viewUrl $*;;
download)download $*;;
*) usage;;
esac

View file

@ -30,7 +30,18 @@ This can be changed by setting the *$ARBITDIR* environment variable.
Open *pipe-viewer(1)* with the contents of the clipboard as search query.
*download-url*
open *yt-dlp(1)* with the contents of the clipboard to download the
Open *yt-dlp(1)* with the contents of the clipboard to download the
resulting file.
*search* _<search-query>_
Query YouTube using *pipe-viewer(1)*
*url*
Open a given URL either in *pipe-viewer(1)* or directly in
*mpv(1)*.
*download* _<url>_
Open *yt-dlp(1)* with the contents of the given URL to download the
resulting file.
# SEE ALSO

View file

@ -1,6 +1,6 @@
#compdef arbit _arbit
_arguments -C \
"1: :(clipboard-url clipboard-content download-url)" \
"1: :(clipboard-url clipboard-content download-url search url download)" \
"*::args:->args"
_arguments : $arguments