summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2021-02-26 21:17:24 -0500
committerAdam T. Carpenter <atc@53hor.net>2021-02-26 21:17:24 -0500
commitfef48aa78c305db6b5be81bff5facacba0a76f5f (patch)
treefa377e83d338a5a52a214bd2ab5dda0fcb255904
parent98fbc511035711d8aa9aecf9e588ad4677d017df (diff)
downloadscripts-fef48aa78c305db6b5be81bff5facacba0a76f5f.tar.xz
scripts-fef48aa78c305db6b5be81bff5facacba0a76f5f.zip
moved all yt.sh into url_handler, added searching
-rwxr-xr-xabraham-porter.sh7
-rwxr-xr-xi3blocks-updates.sh2
-rwxr-xr-xurl_handler.sh101
-rwxr-xr-xyt.sh84
4 files changed, 98 insertions, 96 deletions
diff --git a/abraham-porter.sh b/abraham-porter.sh
index 0669391..033ffb0 100755
--- a/abraham-porter.sh
+++ b/abraham-porter.sh
@@ -21,11 +21,8 @@ NO_WANT_ANOTHER_PROVIDED=6
## Gets a port name from the user with dmenu
get_port() {
- cwd=$(pwd)
- cd "$ports_dir"
- printf "%s\n" */* > /tmp/ports.list
- dmenu -p "Port" < /tmp/ports.list
- cd "$cwd"
+ fetch -o /tmp/ports.txt -i /tmp/ports.txt https://pkg.53hor.net/ports.txt
+ dmenu -p "Port" < /tmp/ports.txt
}
diff --git a/i3blocks-updates.sh b/i3blocks-updates.sh
index 02d3a60..1da50ca 100755
--- a/i3blocks-updates.sh
+++ b/i3blocks-updates.sh
@@ -1,5 +1,5 @@
#!/bin/sh
icon=󰣠
-freebsd-update updatesready > /dev/null
+doas freebsd-update updatesready > /dev/null
[ $? -eq 2 ] || printf "%sUpdates are available" $icon && notify-send "Updates are ready to install"
diff --git a/url_handler.sh b/url_handler.sh
index 858a8fb..5ae6c59 100755
--- a/url_handler.sh
+++ b/url_handler.sh
@@ -1,10 +1,99 @@
#!/bin/sh
-echo $1
+# Everything I would ever need to do with a URL.
-case $1 in
- *youtube.com*) yt.sh $1 ;;
- *youtu.be*) yt.sh $1 ;;
- *mailto*) mutt $1 ;;
- *) $BROWSER $1 ;;
+DOWNLOAD_DIR=$HOME/downloads
+
+# Prompt for a URL or search term
+get_url() {
+ dmenu -p "URL or search"
+}
+
+# Action for YouTube URLs
+get_action() {
+ action=$(dmenu -p "YouTube action" << EOF
+1. watch
+2. video download
+3. audio download
+EOF
+ )
+ echo "$action" | cut -d'.' -f1
+}
+
+
+# Get title, description, and duration of YouTube URL
+toast_info() {
+ info=$(youtube-dl --get-title --get-description --get-duration "$1")
+ title=$(echo "$info" | head -n 1)
+ description=$(echo "$info" | sed '1d;$d')
+ duration=$(echo "$info" | tail -n 1)
+ notify-send "($duration) $title" "$description"
+}
+
+
+## Download video
+video_download() {
+ mkdir -p "$DOWNLOAD_DIR"
+ youtube-dl \
+ -q \
+ --add-metadata \
+ -o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \
+ "$1" && notify-send "Video download done." &
+ notify-send "Downloading video:"
+}
+
+
+## Download audio
+audio_download() {
+ mkdir -p "$DOWNLOAD_DIR"
+ youtube-dl \
+ -q \
+ --add-metadata \
+ -o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \
+ -x \
+ --audio-format flac \
+ --audio-quality 0 \
+ "$1" && notify-send "Audio download done." &
+ notify-send "Downloading audio:"
+}
+
+
+## Play video
+play() {
+ URL="${1#http?://}"
+ mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" "ytdl://$URL" &
+ notify-send "Playing:"
+}
+
+# Handle YouTube URLs
+handle_youtube() {
+ URL=$1
+ toast_info "$URL" &
+
+ case "$(get_action)" in
+ 1)
+ play "$URL"
+ ;;
+ 2)
+ video_download "$URL"
+ ;;
+ 3)
+ audio_download "$URL"
+ esac
+}
+
+# Main
+URL=$1
+[ -n "$URL" ] || URL=$(get_url)
+[ -n "$URL" ] || exit
+echo "$URL"
+
+case $URL in
+ *youtube.com*) handle_youtube "$URL" ;;
+ *youtu.be*) handle_youtube "$URL" ;;
+ *ytsearch:*) handle_youtube "$URL" ;;
+ *mailto*) mutt "$URL" ;;
+ *http?*) $BROWSER "$URL" ;;
+ *)
+ $BROWSER --search "$URL"
esac
diff --git a/yt.sh b/yt.sh
deleted file mode 100755
index 16f7247..0000000
--- a/yt.sh
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/sh
-## Do things with a YouTube URL. Assumes a valid YouTube URL. Doesn't do any
-## grabbing or scraping, use urlview for that.
-
-## Config:
-TERMINAL=alacritty
-DOWNLOAD_DIR=~/videos/youtube
-
-## Exit codes
-NO_URL=3
-NO_ACTION=4
-
-## Get action for a single URL
-get_action() {
- action=$(dmenu -p "YouTube" << EOF
-1. watch
-2. video download
-3. audio download
-EOF
- )
- echo "$action" | cut -d'.' -f1
-}
-
-## Get title, description, and duration of URL
-toast_info() {
- info=$(youtube-dl --get-title --get-description --get-duration "$1")
- title=$(echo "$info" | head -n 1)
- description=$(echo "$info" | sed '1d;$d')
- duration=$(echo "$info" | tail -n 1)
- notify-send "($duration) $title" "$description"
-}
-
-
-## Download video
-video_download() {
- mkdir -p "$DOWNLOAD_DIR"
- youtube-dl \
- -q \
- --add-metadata \
- -o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \
- "$1" && notify-send "Video download done." &
- notify-send "Downloading video:"
-}
-
-
-## Download audio
-audio_download() {
- mkdir -p "$DOWNLOAD_DIR"
- youtube-dl \
- -q \
- --add-metadata \
- -o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \
- -x \
- --audio-format flac \
- --audio-quality 0 \
- "$1" && notify-send "Audio download done." &
- notify-send "Downloading audio:"
-}
-
-
-## Play video
-play() {
- mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" "$1" &
- notify-send "Playing:"
-}
-
-
-## Main
-[ -n "$1" ] || exit NO_URL
-toast_info "$1" &
-
-case "$(get_action)" in
- 1)
- play "$1"
- ;;
- 2)
- video_download "$1"
- ;;
- 3)
- audio_download "$1"
- ;;
- *)
- exit $NO_ACTION
-esac