Allow to set IP Addr as argument

This commit is contained in:
gardouille 2022-03-03 09:29:09 +01:00
parent 8f9ea40313
commit dbad50664f
Signed by: gardouille
GPG Key ID: E759BAA22501AF32

View File

@ -16,17 +16,12 @@ usage () {
[ -z "${1}" ] || echo "! ${1}" [ -z "${1}" ] || echo "! ${1}"
# display help # display help
echo "\ echo "\
$(basename "$0") -i url $(basename "$0") -u url
-i infile.(mp4|mov|mkv|m4v|aac|m4a|wav|mp3) or an http link" -u http link or a video file.(mp4|mov|mkv|m4v|aac|m4a|wav|mp3)
-i IP.AD.DR.ESS (default=127.0.0.1)"
exit 2 exit 2
} }
#===============================================================================
# ip address localhost - change to your ip
#===============================================================================
ip='127.0.0.1'
#=============================================================================== #===============================================================================
# error messages # error messages
#=============================================================================== #===============================================================================
@ -41,9 +36,9 @@ WRONG_ARGS_ERR='wrong number of arguments passed to script'
#=============================================================================== #===============================================================================
is_clipboard_youtube_url () { is_clipboard_youtube_url () {
infile=$(xclip -out -selection clipboard) url_arg=$(xclip -out -selection clipboard)
if printf "%s" "${infile}" | grep -q -E "http.*youtube.*"; then if printf "%s" "${url_arg}" | grep -q -E "http.*youtube.*"; then
printf "%b\n" "Clipboard content can be used: ${infile}" printf "%b\n" "Clipboard content can be used: ${url_arg}"
else else
usage "${WRONG_ARGS_ERR}" usage "${WRONG_ARGS_ERR}"
fi fi
@ -60,10 +55,11 @@ is_clipboard_youtube_url () {
# getopts check options passed to script # getopts check options passed to script
#=============================================================================== #===============================================================================
while getopts ':i:h' opt while getopts ':u:i:h' opt
do do
case ${opt} in case ${opt} in
i) infile="${OPTARG}";; u) url_arg="${OPTARG}";;
i) ip="${OPTARG}";;
h) usage;; h) usage;;
\?) usage "${INVALID_OPT_ERR} ${OPTARG}" 1>&2;; \?) usage "${INVALID_OPT_ERR} ${OPTARG}" 1>&2;;
:) usage "${INVALID_OPT_ERR} ${OPTARG} ${REQ_ARG_ERR}" 1>&2;; :) usage "${INVALID_OPT_ERR} ${OPTARG} ${REQ_ARG_ERR}" 1>&2;;
@ -71,13 +67,22 @@ do
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
#===============================================================================
# ip address localhost - change to your ip
#===============================================================================
## If ip wasn't defined
if [ -z "${ip}" ]; then
### Set it to localhost
ip='127.0.0.1'
fi
#=============================================================================== #===============================================================================
# url # url
#=============================================================================== #===============================================================================
# youtube-dl best format # youtube-dl best format
url=$(youtube-dl -f best -g --no-playlist "${infile}") url=$(youtube-dl -f best -g --no-playlist "${url_arg}")
# check url with ffprobe for errors and swap stderr and stdout to store error # check url with ffprobe for errors and swap stderr and stdout to store error
url_check=$(ffprobe -hide_banner -v warning -i "${url}" 3>&2 2>&1 1>&3 >/dev/null) url_check=$(ffprobe -hide_banner -v warning -i "${url}" 3>&2 2>&1 1>&3 >/dev/null)
@ -99,7 +104,7 @@ kodi-send --host="${ip}" --port=9777 --action="PlayMedia(${url},[noresume])" 1>/
#=============================================================================== #===============================================================================
two_streams () { two_streams () {
url=$(youtube-dl -g --no-playlist "${infile}") url=$(youtube-dl -g --no-playlist "${url_arg}")
video_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $1}') video_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $1}')
audio_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $2}') audio_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $2}')