#!/bin/bash
# /usr/local/bin/qyou
# https://crystalfaeries.net/posix/bin/qyou
# celeste:crystalfaery QYOU 2017-12-05 23:20:16+00:00
# if invoked without arguments, display the existing youtubedownload queue
# if invoked with ususal version or help arguments, deliver that info and quit
# if invoked with argument -p, display any running youtube-dl processes and quit
# if invoked with argument -l, display the tail of the youtubedownload log and quit
# if invoked with argument -l n, display the tail n lines of the youtubedownload log and quit
# if invoked with argument -F, Follow the tail of the youtubedownload log
# if invoked with argument -i, interactively receive URLs to add to the queue
# if invoked with argument -e, interactively edit the URLs in the queue
# if invoked with any other arguments, add those URLs to the youtubedownload queue
help=12 # this line number -1
case $# in
0) # if invoked without arguments, display the existing youtubedownload queue
echo "youtubedownload queue:" >& 2
sort -u /home/downloads/youtube.com/.youtube.txt
;;
*)
# if invoked with ususal version or help arguments, deliver that info and quit
case "${1}" in
-h) head -n ${help} $0
;;
--help) head -n ${help} $0
;;
-v) head -n 4 $0 | tail -n 1
;;
--version) head -n 4 $0 | tail -n 1
;;
-p) ps -ef --forest | grep "python /usr/local/bin/youtube-dl" | grep -v grep
;;
-l) shift # consume the -l and check for a line count for tail:
if [ $# -ne 0 ]
then
tail -n ${1} /home/downloads/youtube.com/.youlog.txt
else
tail /home/downloads/youtube.com/.youlog.txt
fi
;;
-F) tail -F /home/downloads/youtube.com/.youlog.txt
;;
-i) # if invoked with argument -i, interactively receive URLs to add to the queue
while read URL
do
echo "${URL}" >> /home/downloads/youtube.com/.youtube.txt # append new URL
done
;;
-e) # if invoked with argument -e, interactively edit the URLs in the queue
sort -u /home/downloads/youtube.com/.youtube.txt \
> /tmp/.$$.youtube.txt
vi /tmp/.$$.youtube.txt
sort -u /tmp/.$$.youtube.txt \
> /home/downloads/youtube.com/.youtube.txt
exit $?
;;
*) # if invoked with any other arguments, add those URLs to the youtubedownload queue
while [ $# -gt 0 ]
do
echo "${1}" >> /home/downloads/youtube.com/.youtube.txt # append new URL
shift # consume the argument
done
;;
esac
;;
esac
exit $?
syntax highlighted by Code2HTML, v. 0.9.1