#!/bin/bash
#                       /usr/local/bin/yourl
# https://crystalfaeries.net/posix/bin/yourl
# celeste:crystalfaery YOURL 2021-04-27 21:59:43+00:00
# yourl accepts as arguments youtube URL(s) and
# cannonicalizes those URL(s), in support of qyou

let help=7	# this line number -1
cd -P "${HOME}" # there's no place like Aum

case	$# in
0)	# if invoked without arguments, fall through
	;;

*)
	# if invoked with ususal version or help options, deliver that info	and quit
    case "${1}" in
	-h | --help)
			head -n ${help} $0
			exit
			;;
	-v | --version)
			head -n 4 $0 | tail -n 1
			exit
			;;
    esac
	;;
esac
while [ $# -gt 0 ]
do
    if [ 12 -eq $(echo "${1}" | /usr/local/bin/wc | sed 's/^.* //') ]
    then	# we have a naked youtube hashcode of 11 characters
	echo	"https://www.youtube.com/watch?v=${1}"	\
	|	tee -a	"${HOME}"/crystalfaeries.net/documents/youtube.com/.youlog.txt
	
    else	# hopefully we have a full URL
	echo	"${1}" | sed 's/^http:\/\/youtu.be\//https:\/\/www.youtube.com\/watch?v=/;s/^https:\/\/youtu.be\//https:\/\/www.youtube.com\/watch?v=/;s/^http:\/\/youtube.com\/watch?v=/https:\/\/www.youtube.com\/watch?v=/;s/^https:\/\/youtube.com\/watch?v=/https:\/\/www.youtube.com\/watch?v=/;s/^http:\/\/www.youtube.com\/watch?v=/https:\/\/www.youtube.com\/watch?v=/;s/^https:\/\/www.youtube.com\/watch?v=/https:\/\/www.youtube.com\/watch?v=/'	\
	|	tee -a	"${HOME}"/crystalfaeries.net/documents/youtube.com/.youlog.txt
    fi
    shift	# consume the argument
done		# loop for another
exit	$?	# pau for now

