#!/bin/sh
# wrapper.sh example
# Dep: youtube-dl, mpv, notify-send, dmenu
# This script will be a wrapper of the Go programming using handling pipe data.
# The idea is that this will allow keep the program to stick to doing one thing.
# While it is possible to use pipes in Golang, I find this approach to be better
# for integration into a Linux system. However, this could be changed in the
# future and integrated into the Go program. We'll see. THIS IS AN EXAMPLE.
# Set timeout to 4s
alias notify-send="notify-send -t 4000"
# Set dmenu prompt
alias dmenu="dmenu -p 'play >' -l 10"
add() {
yt-cli -add $1 && notify-send "YouTube CLI" "Added $1"
}
list() {
# todo: error check
id=$(yt-cli -list | dmenu)
# remove [date] and (id) for title
title=${id#\[*\]}
title=${title%(*)}
# get ID from title
id=${id#*(}
id=${id%)}
mpv "https://youtube.com/watch?v=$id" > /dev/null < /dev/null &
notify-send "YouTube CLI" "Playing $title"
}
usage() {
printf "Usage of %s\n" "$0"
printf " -a, add, -add <channelID>\n"
printf "\tAdd a channel to subscription list.\n"
printf " -l, list, -list\n"
printf "\tList subscriptions out to dmenu and play video.\n"
}
case $1 in
add|--add|-add|-a)
add $2
;;
list|--list|-list|-l)
list
;;
help|--help|-help|-h)
usage
;;
*)
usage
exit 1
;;
esac
exit