#!/bin/bash
	
	############################################################
	############################################################
	############################################################
	# Project : OrangeTvCmd
	# Version : 
	# Dependency / Dependencies : /
	# Language : Français
	# License : GNU GPL - http://www.gnu.org/licenses/gpl.html
	# Author : Hilger Sébastien
	# Contact : hilger.sebastien@gmail.com
	############################################################
	############################################################
	############################################################
	#Programme develloper avec : décodeur TV Orange "Samsung TV UHD 87"


#  ___                            _____        ____               _ 
# / _ \ _ __ __ _ _ __   __ _  __|_   _|_   __/ ___|_ __ ___   __| |
#| | | | '__/ _` | '_ \ / _` |/ _ \| | \ \ / / |   | '_ ` _ \ / _` |
#| |_| | | | (_| | | | | (_| |  __/| |  \ V /| |___| | | | | | (_| |
# \___/|_|  \__,_|_| |_|\__, |\___||_|   \_/  \____|_| |_| |_|\__,_|
#                       |___/                                       


	
	# PROGRAM VARIABLES ########################################

	green='\e[1;32m'
	yellow='\e[1;33m'
	red='\e[1;31m'
	nocolor='\e[0;m'
	
	ProgramLocation="$(readlink -f "$0" )"
	ProgramDirectory=${ProgramLocation%/*}
	ConfigDirectory="$ProgramDirectory/../.config"
	TempDirectory="$ProgramDirectory/../.config/tmp"
	DependenciesDirectory="$ProgramDirectory/../dependencies"
	
	# FUNCTION / FUNCTIONS #####################################
	
Help(){
echo "
OrangeTvCmd : Script de controle du boitier TV Orange en LAN.

1 2 3 ... 30 : Chaînes de 1 à 30

--on-off : Allumer / Éteindre le boitier.

--play-pause : Lecture / Pause.

--menu : Accéder au menu.

--ok : Valider / Ok.

--back : Retour.

--info : Informations.

--ch- : Chaînes précédente.

--ch+ : Chaînes suivante.

--mute : Couper le son.

--vol- : Baisser le son.

--vol+ : Augmenter le volume.

--vod : Vidéo à la demande.

Exemples :

OrangeTvCmd 6
OrangeTvCmd 15
OrangeTvCmd --on-off
OrangeTvCmd --play-pause
OrangeTvCmd --menu
OrangeTvCmd --ok
OrangeTvCmd --back
OrangeTvCmd --info
OrangeTvCmd --ch-
OrangeTvCmd --ch+
OrangeTvCmd --mute
OrangeTvCmd --vol-
OrangeTvCmd --vol+
"
}
	
	# BODY #####################################################
		
		#Configuration
		PORT="8080"
		TvBox="http://dcodeurtvdorange.home"
		
		if [ -z "$1" ] || [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "--Help" ] || [ "$1" = "--HELP" ] || [ "$1" = "-h" ] || [ "$1" = "-H" ]; then
			Help
		else
			if [ "$1" = "0" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=512&mode=0" && clear && echo -e "${green}Chaînes 0${nocolor}"
			fi

			if [ "$1" = "1" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0" && clear && echo -e "${green}Chaînes 1${nocolor}"
			fi

			if [ "$1" = "2" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0" && clear && echo -e "${green}Chaînes 2${nocolor}"
			fi

			if [ "$1" = "3" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=515&mode=0" && clear && echo -e "${green}Chaînes 3${nocolor}"
			fi

			if [ "$1" = "4" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=516&mode=0" && clear && echo -e "${green}Chaînes 4${nocolor}"
			fi

			if [ "$1" = "5" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=517&mode=0" && clear && echo -e "${green}Chaînes 5${nocolor}"
			fi

			if [ "$1" = "6" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=518&mode=0" && clear && echo -e "${green}Chaînes 6${nocolor}"
			fi

			if [ "$1" = "7" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=519&mode=0" && clear && echo -e "${green}Chaînes 7${nocolor}"
			fi

			if [ "$1" = "8" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=520&mode=0" && clear && echo -e "${green}Chaînes 8${nocolor}"
			fi

			if [ "$1" = "9" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=521&mode=0" && clear && echo -e "${green}Chaînes 9${nocolor}"
			fi

			if [ "$1" = "10" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=512&mode=0"	&& clear && echo -e "${green}Chaînes 10${nocolor}"
			fi

			if [ "$1" = "11" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0" && clear && echo -e "${green}Chaînes 11${nocolor}"
			fi

			if [ "$1" = "12" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0" && clear && echo -e "${green}Chaînes 12${nocolor}"
			fi

			if [ "$1" = "13" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=515&mode=0" && clear && echo -e "${green}Chaînes 13${nocolor}"
			fi

			if [ "$1" = "14" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=516&mode=0" && clear && echo -e "${green}Chaînes 14${nocolor}"
			fi

			if [ "$1" = "15" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=517&mode=0" && clear && echo -e "${green}Chaînes 15${nocolor}"
			fi

			if [ "$1" = "16" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=518&mode=0" && clear && echo -e "${green}Chaînes 16${nocolor}"
			fi

			if [ "$1" = "17" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=519&mode=0" && clear && echo -e "${green}Chaînes 17${nocolor}"

			fi

			if [ "$1" = "18" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=520&mode=0" && clear && echo -e "${green}Chaînes 18${nocolor}"
			fi

			if [ "$1" = "19" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=521&mode=0" && clear && echo -e "${green}Chaînes 19${nocolor}"
			fi

			if [ "$1" = "20" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=512&mode=0" && clear && echo -e "${green}Chaînes 20${nocolor}"
			fi

			if [ "$1" = "21" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=513&mode=0" && clear && echo -e "${green}Chaînes 21${nocolor}"
			fi

			if [ "$1" = "22" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0" && clear && echo -e "${green}Chaînes 22${nocolor}"
			fi

			if [ "$1" = "23" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=515&mode=0" && clear && echo -e "${green}Chaînes 23${nocolor}"
			fi

			if [ "$1" = "24" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=516&mode=0" && clear && echo -e "${green}Chaînes 24${nocolor}"
			fi

			if [ "$1" = "25" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=517&mode=0" && clear && echo -e "${green}Chaînes 25${nocolor}"
			fi

			if [ "$1" = "26" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=518&mode=0" && clear && echo -e "${green}Chaînes 26${nocolor}"
			fi

			if [ "$1" = "27" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=519&mode=0" && clear && echo -e "${green}Chaînes 27${nocolor}"
			fi

			if [ "$1" = "28" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=520&mode=0" && clear && echo -e "${green}Chaînes 28${nocolor}"
			fi

			if [ "$1" = "29" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=514&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=521&mode=0" && clear && echo -e "${green}Chaînes 29${nocolor}"
			fi

			if [ "$1" = "30" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=515&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=512&mode=0" && clear && echo -e "${green}Chaînes 30${nocolor}"
			fi

			if [ "$1" = "--on-off" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=116&mode=0" && clear && echo -e "${green}On/Off${nocolor}"
			fi

			if [ "$1" = "--play-pause" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=164&mode=0" && clear && echo -e "${green}Play / Pause${nocolor}"
			fi

			if [ "$1" = "--menu" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=139&mode=0" && clear && echo -e "${green}Menu${nocolor}"
			fi

			if [ "$1" = "--ok" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=352&mode=0" && clear && echo -e "${green}Ok${nocolor}"
			fi

			if [ "$1" = "--back" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=352&mode=0" && clear && echo -e "${green}Back${nocolor}"
			fi

			if [ "$1" = "--info" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=108&mode=0" && clear && echo -e "${green}Info${nocolor}"
			fi

			if [ "$1" = "--ch-" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=403&mode=0" && clear && echo -e "${green}Ch-${nocolor}"
			fi

			if [ "$1" = "--ch+" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=402&mode=0" && clear && echo -e "${green}Ch+${nocolor}"
			fi

			if [ "$1" = "--mute" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=113&mode=0" && clear && echo -e "${green}Mute${nocolor}"
			fi

			if [ "$1" = "--vol-" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=114&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=114&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=114&mode=0" && clear && echo -e "${green}Vol-${nocolor}"
			fi

			if [ "$1" = "--vol+" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=115&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=115&mode=0"
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=115&mode=0" && clear && echo -e "${green}Vol+${nocolor}"
			fi

			if [ "$1" = "--vod" ]; then
				curl "$TvBox:$PORT/remoteControl/cmd?operation=01&key=393&mode=0" && clear && echo -e "${green}Vod${nocolor}"
			fi
		fi	
