summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-12-28 15:04:01 -0500
committerAdam T. Carpenter <atc@53hor.net>2020-12-28 15:04:01 -0500
commit96140b0354597ca0b535e55e250c0b4d89fb1766 (patch)
tree322e6eb1ba8e79cfac8175fe081cd64f43a72124
parent5ac1d40fe8a9f968d7937d3a30824883d0547d21 (diff)
downloadscripts-96140b0354597ca0b535e55e250c0b4d89fb1766.tar.xz
scripts-96140b0354597ca0b535e55e250c0b4d89fb1766.zip
finished yt.sh and url_handler.sh
-rwxr-xr-xdockd.sh2
-rwxr-xr-xurl_handler.sh2
-rwxr-xr-xyt.sh72
3 files changed, 30 insertions, 46 deletions
diff --git a/dockd.sh b/dockd.sh
index b77494d..2ac4ef6 100755
--- a/dockd.sh
+++ b/dockd.sh
@@ -8,7 +8,6 @@
# - disable laptop lid close sleep
# - disable auto locking and sleeping
dock() {
- notify-send Docking...
xrandr \
--output DP-0 --off \
--output DP-1 --off \
@@ -30,7 +29,6 @@ dock() {
# - enable laptop lid close sleep
# - enable auto locking and sleeping
undock() {
- notify-send Undocking...
xrandr \
--output DP-0 --off \
--output DP-1 --off \
diff --git a/url_handler.sh b/url_handler.sh
index 931fce6..858a8fb 100755
--- a/url_handler.sh
+++ b/url_handler.sh
@@ -4,7 +4,7 @@ echo $1
case $1 in
*youtube.com*) yt.sh $1 ;;
*youtu.be*) yt.sh $1 ;;
- *mailto*) echo Mail ;;
+ *mailto*) mutt $1 ;;
*) $BROWSER $1 ;;
esac
diff --git a/yt.sh b/yt.sh
index f270bc6..16f7247 100755
--- a/yt.sh
+++ b/yt.sh
@@ -1,56 +1,51 @@
#!/bin/sh
-## Do things with a YouTube URL.
+## 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_YOUTUBE_URL=3
+NO_URL=3
NO_ACTION=4
-
## Get action for a single URL
-get_action_single() {
- action=$(dmenu -p "yt-player" << EOF
-1. watch in player
-2. listen in player
-3. download video
-4. download audio
+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
-get_info() {
- url=$1
- info=$(youtube-dl --get-title --get-description --get-duration $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)
- printf "(%s) %s\n\n%s" "$duration" "$title" "$description"
+ notify-send "($duration) $title" "$description"
}
## Download video
-download_video() {
- url=$1
- info=$(get_info $url)
- notify-send "Downloading video..." "$info" &
+video_download() {
+ mkdir -p "$DOWNLOAD_DIR"
youtube-dl \
-q \
--add-metadata \
-o "$DOWNLOAD_DIR/%(title)s_%(id)s.%(ext)s" \
- "$url" && notify-send "Video download done." "$info" &
+ "$1" && notify-send "Video download done." &
+ notify-send "Downloading video:"
}
## Download audio
-download_audio() {
- url=$1
- info=$(get_info $url)
- notify-send "Downloading audio..." "$info"
+audio_download() {
+ mkdir -p "$DOWNLOAD_DIR"
youtube-dl \
-q \
--add-metadata \
@@ -58,40 +53,31 @@ download_audio() {
-x \
--audio-format flac \
--audio-quality 0 \
- "$url" && notify-send "Audio download done." "$info" &
+ "$1" && notify-send "Audio download done." &
+ notify-send "Downloading audio:"
}
## Play video
-play_video() {
- url=$1
- notify-send "Playing video..." "$(get_info $url)" &
- mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" $url &
+play() {
+ mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" "$1" &
+ notify-send "Playing:"
}
-## Play audio
-play_audio() {
- url=$1
- notify-send "Playing audio..." "$(get_info $url)" &
- $TERMINAL -t "Streaming from YouTube" -e mpv --no-video $url &
-}
-
## Main
-mkdir -p "$DOWNLOAD_DIR"
+[ -n "$1" ] || exit NO_URL
+toast_info "$1" &
-case "$(get_action_single)" in
+case "$(get_action)" in
1)
- play_video $url
+ play "$1"
;;
2)
- play_audio $url
+ video_download "$1"
;;
3)
- download_video $url
- ;;
- 4)
- download_audio $url
+ audio_download "$1"
;;
*)
exit $NO_ACTION