From 9a270533a3bfc1610e05b2e54ec64849f3ce6605 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Tue, 7 Mar 2023 18:02:58 +0100 Subject: [PATCH] Added 'url' and 'download' functions --- APKBUILD | 8 ++++---- Makefile | 2 +- arbit | 41 +++++++++++++++++++++++++++++++++++++++-- arbit.1.scd | 13 ++++++++++++- zsh.completion | 2 +- 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/APKBUILD b/APKBUILD index a11a1fb..1c36b32 100644 --- a/APKBUILD +++ b/APKBUILD @@ -1,10 +1,10 @@ # Contributor: Marty Sluijtman # Maintainer: Marty Sluijtman 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 " diff --git a/Makefile b/Makefile index 1033a66..137f360 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/arbit b/arbit index 343fdac..9d1935f 100755 --- a/arbit +++ b/arbit @@ -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 < +Usage: $(basename $0) 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 diff --git a/arbit.1.scd b/arbit.1.scd index 6bb615e..d50f191 100644 --- a/arbit.1.scd +++ b/arbit.1.scd @@ -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* __ + Query YouTube using *pipe-viewer(1)* + +*url* + Open a given URL either in *pipe-viewer(1)* or directly in + *mpv(1)*. + +*download* __ + Open *yt-dlp(1)* with the contents of the given URL to download the resulting file. # SEE ALSO diff --git a/zsh.completion b/zsh.completion index 3dc2681..83d727b 100644 --- a/zsh.completion +++ b/zsh.completion @@ -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