#!/bin/bash

rest=""
crest=""
crcom=""
ytprefix=""
substring="PtR4cWb4HNg"

if [ -z "$1" ]; then

  echo "Radio Play via comma separate YouTube 11 character IDs or search ideas for an inhouse playlist (if any in a comma separated list is PtR4cWb4HNg temporary YouTube playlist audio and video play can be attempted) ... 7 such uses Shower Songs ... egs. Tragedy,Boogie Wonderland,Down Among the Dead Men flash ... random ... Tragedy ,Imagine*3,Breezin ... ordered 5 ... Tragedy  ,Pina Colada Song,Fast Car ... audio ... Tragedy   ,Galveston,Fix You    ... audio ordered,    and go."

  read ans
  
  if [[ "$ans" == *"$substring"* ]]; then
   open "https://www.youtube.com/watch_videos?video_ids=$ans"
   exit
  fi
  
else

  preans="$1"

  ans="$1 $2 $3 $4 $5 $6 $7 $8 $9"

  while [ ! -z "$9" ]; do

   shift

   rest="${rest} $9"
   crest="${crest}${crcom}$9"
   echo $rest
   if [[ "$rest" == *"$substring"* ]]; then
     ytprefix="https://www.youtube.com/watch_videos?video_ids="
   fi
   crcom=","

  done
  
  if [ "$ytprefix" == "" ]; then
   ytprefix=""
  else
   open "https://www.youtube.com/watch_videos?video_ids=$crest"
   exit
  fi

  ans="$ans${rest}"

fi

if [ ! -z "$ans" ]; then
 if [[ "$ans" == *"$substring"* ]]; then
   open "https://www.youtube.com/watch_videos?video_ids=$ans"
   exit
 fi
 
 commas_only="${ans//[^,]}"

 if [ "${#preans}" == "83" ]; then

  if [ "${#commas_only}" == "6" ]; then

   open "https://www.rjmprogramming.com.au/$1"

  else

   open "https://www.rjmprogramming.com.au/HTMLCSS/swipe_media.html $ans"

  fi

 else

  open "https://www.rjmprogramming.com.au/HTMLCSS/swipe_media.html $ans"

 fi

fi

exit