aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-08-16 18:36:08 -0300
committerEuAndreh <eu@euandre.org>2022-08-16 18:36:12 -0300
commitdc91445255bab20bf8efb3f90a836520eb2764f9 (patch)
treeefc184972976bd897474305d71c280b6176bb4fe /bin
parentbin/update: Add almost-working script (diff)
downloaddotfiles-dc91445255bab20bf8efb3f90a836520eb2764f9.tar.gz
dotfiles-dc91445255bab20bf8efb3f90a836520eb2764f9.tar.xz
bin/playlist: Add working version
Diffstat (limited to 'bin')
-rwxr-xr-xbin/playlist103
1 files changed, 103 insertions, 0 deletions
diff --git a/bin/playlist b/bin/playlist
new file mode 100755
index 0000000..bd01d23
--- /dev/null
+++ b/bin/playlist
@@ -0,0 +1,103 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ playlist ACTION
+ playlist -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+ ACTION one of:
+ - prompt
+ - run
+
+
+ Manage the playlist.
+
+
+ Examples:
+
+ Enqueue a video:
+
+ $ playlist prompt
+
+
+ Play the next video in the queue:
+
+ $ playlist run
+ EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+ACTION="${1:-}"
+
+eval "$(assert-arg "$ACTION" 'ACTION')"
+
+F="$XDG_DATA_HOME"/euandreh/playlist.txt
+
+prompt() {
+ ENTRY="$(zenity --text 'URL of the video to enqueue:' --entry ||:)"
+ if [ -n "$ENTRY" ]; then
+ echo "$ENTRY" >> "$F"
+ fi
+}
+
+run() {
+ next="$(head -n1 "$F")"
+ if [ -z "$next" ]; then
+ return
+ fi
+ mpv "$next"
+ echo "$next" >> "queue.$F"
+ tail -n+2 "$F" | sponge "$F"
+}
+
+case "$ACTION" in
+ prompt)
+ prompt
+ ;;
+ run)
+ run
+ ;;
+ *)
+ printf 'Bad ACTION: %s.\n\n' "$ACTION" >&2
+ usage >&2
+ exit 2
+ ;;
+esac