summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-05-22 22:48:10 -0400
committerAdam T. Carpenter <atc@53hor.net>2020-05-22 22:48:10 -0400
commitade76bb57b81f879e4a2d59709db84f874524bcd (patch)
tree5c6d02cd740542f70be931bd4bf8269f4c7800a6
parent89dd9a405009d74716fd82e4a0ea56d94273fd90 (diff)
downloadscripts-ade76bb57b81f879e4a2d59709db84f874524bcd.tar.xz
scripts-ade76bb57b81f879e4a2d59709db84f874524bcd.zip
updated yt script for stdin url, renamed
-rwxr-xr-xyt.sh (renamed from yt-player.sh)24
1 files changed, 12 insertions, 12 deletions
diff --git a/yt-player.sh b/yt.sh
index b0f4f51..823bb7c 100755
--- a/yt-player.sh
+++ b/yt.sh
@@ -4,6 +4,7 @@
TERMINAL=alacritty
DOWNLOAD_DIR=~/videos/youtube
PAGER="rofi -location 2 -width 41 -e"
+YOUTUBE_REGEX=".*((https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+)$"
## Exit codes
@@ -34,14 +35,7 @@ get_action_multi() {
## Check if url is a youtube url
check_if_youtube() {
url="$1"
- [ -z $url ] && return 1;
-
- count=$(echo "$1" | \
- grep -c -E "^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$"
- )
-
- [ "$count" -eq 1 ] && return 0;
- return 1;
+ echo $url | grep -qE "$YOUTUBE_REGEX" && return 0 || return 1
}
@@ -53,10 +47,9 @@ prompt_url() {
## Grab url from clipboard/primary selection, else get via prompt
grab_url() {
- local url
-
- if url=$(xclip -o -selection clipboard) && check_if_youtube $url; then
- elif url=$(xclip -o) && check_if_youtube $url; then
+ if url=$(grab_url_stdin) && check_if_youtube $url; then
+ elif url=$(xclip -o -selection clipboard 2>/dev/null || echo) && check_if_youtube $url; then
+ elif url=$(xclip -o 2>/dev/null || echo) && check_if_youtube $url; then
elif url=$(prompt_url) && check_if_youtube $url; then
else
exit $NO_YOUTUBE_URL
@@ -66,6 +59,12 @@ grab_url() {
}
+## Extract URL from stdin
+grab_url_stdin() {
+ sed -nE "s/$YOUTUBE_REGEX/\1/p"
+}
+
+
## Get title, description, and duration of URL
get_info() {
url="$1"
@@ -133,6 +132,7 @@ print_info() {
## Main
mkdir -p "$DOWNLOAD_DIR"
url=$(grab_url)
+
case "$(get_action_single)" in
5)
print_info $url