generated from pavel.muhortov/template-bash
	simple code refactoring
This commit is contained in:
		
							parent
							
								
									a241aa5977
								
							
						
					
					
						commit
						d470736839
					
				
							
								
								
									
										64
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								README.md
									
									
									
									
									
								
							|  | @ -1,18 +1,26 @@ | |||
| # cctv-scheduler | ||||
| 
 | ||||
| PTZ IP-Camera management | ||||
| 
 | ||||
|  | ||||
| 
 | ||||
| ## `Installation` | ||||
| 
 | ||||
| ### `Requirements` | ||||
| 
 | ||||
| Cameras settings: | ||||
| > | ||||
| > - Configuration -> System -> Security -> Authentication -> RTSP Authentication: digest/basic | ||||
| > - Configuration -> System -> Security -> Authentication -> WEB Authentication: digest/basic | ||||
| > - Configuration -> Network -> Advanced Settings -> Integration Protocol -> Enable Hikvision-CGI: Enabled | ||||
| > - Configuration -> Network -> Advanced Settings -> Integration Protocol -> Hikvision-CGI Authentication: digest/basic | ||||
| 
 | ||||
| Look at the description of dependencies and install the necessary. | ||||
| 
 | ||||
| ### `Downloading` | ||||
| 
 | ||||
| Download scripts and configs. | ||||
| 
 | ||||
| ```bash | ||||
| wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/sequences.sh -O /home/user/cctv-scheduler/sequences.sh | ||||
| wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/sequences.conf -O /home/user/cctv-scheduler/sequences.conf | ||||
|  | @ -23,66 +31,84 @@ wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publi | |||
| wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher-template-page-1007.xml -O /home/user/cctv-scheduler/publisher-template-page-1007.xml | ||||
| wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/streaming.py -O /home/user/cctv-scheduler/streaming.py | ||||
| ``` | ||||
| 
 | ||||
| ### `Configuration` | ||||
| 
 | ||||
| Edit configs. | ||||
| 
 | ||||
| ```bash | ||||
| nano /home/user/cctv-scheduler/sequences.conf | ||||
| nano /home/user/cctv-scheduler/converter.conf | ||||
| nano /home/user/cctv-scheduler/publisher.conf | ||||
| ``` | ||||
| 
 | ||||
| ### `Scheduler` | ||||
| 
 | ||||
| Look at examples and edit scheduler tasks: | ||||
| 
 | ||||
| ```bash | ||||
| crontab -e | ||||
| ``` | ||||
| ____ | ||||
| * [`sequences.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#sequences-sh) | ||||
| * [`converter.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#converter-sh) | ||||
| * [`publisher.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#publisher-sh) | ||||
| * [`streaming.py`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#streaming-py) | ||||
| 
 | ||||
| ____ | ||||
| 
 | ||||
| - [`sequences.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#sequences-sh) | ||||
| - [`converter.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#converter-sh) | ||||
| - [`publisher.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#publisher-sh) | ||||
| - [`streaming.py`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#streaming-py) | ||||
| 
 | ||||
| ____ | ||||
| 
 | ||||
| ## `sequences`.sh | ||||
| 
 | ||||
| **Description:**   | ||||
| > [Hikvision](https://git.hmp.today/pavel.muhortov/cctv-scheduler/src/branch/master/info/hikvision/manual/isapi.pdf) PTZ-camera sequences.   | ||||
| > Additionally: | ||||
| > | ||||
| > - getting temperature from DS18B20 over SSH, | ||||
| > - saving pictures to FTP. | ||||
| > | ||||
| > This is only a local "proof of conept" for testing and debugging. | ||||
| 
 | ||||
| **Dependencies:**   | ||||
| > | ||||
| > - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - [curl](https://curl.se/download.html) (tested version 7.74 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - [sshpass](https://www.cyberciti.biz/faq/noninteractive-shell-script-ssh-password-provider/) (tested version 1.09 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| 
 | ||||
| 
 | ||||
| |  POSITION | PARAMETERS   |       DESCRIPTION      |    DEFAULT    | | ||||
| |-----------|--------------|------------------------|---------------| | ||||
| |     1     |    **[qn]**    |execution without pauses|| | ||||
| |     2     |    **[/path/to/conf]**    |path to config|     ./sequences.conf    | | ||||
| 
 | ||||
| 
 | ||||
| Example usage in terminal with bash: | ||||
| 
 | ||||
| ```bash | ||||
| bash ./sequences.sh - ./sequences.conf | ||||
| ``` | ||||
| 
 | ||||
| Example usage with cron: | ||||
| 
 | ||||
| ```bash | ||||
| # crontab -e | ||||
| 0  *  *  *  * bash /home/user/cctv-scheduler/sequences.sh qn | ||||
| ``` | ||||
| 
 | ||||
| ____ | ||||
| 
 | ||||
| ## `converter`.sh | ||||
| 
 | ||||
| **Description:**   | ||||
| > JPEG to MP4 converter. | ||||
| > | ||||
| > This is only a local "proof of conept" for testing and debugging. | ||||
| 
 | ||||
| **Dependencies:**   | ||||
| > | ||||
| > - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - filesystem organization: | ||||
| > | ||||
| >```bash | ||||
| > # filesystem organisation example | ||||
| >/root/ | ||||
|  | @ -109,12 +135,14 @@ ____ | |||
| |     2     |    **[/path/to/conf]**    |path to config|     ./converter.conf    | | ||||
| |     3     |    **[-d\|-w\|-m\|-y]**    |periods: '' - today \| '-d' - yesterday \| '-w' - last week \| '-m' - last month \| '-y' - last year|| | ||||
| 
 | ||||
| 
 | ||||
| Example usage in terminal with bash for today's MP4 making: | ||||
| 
 | ||||
| ```bash | ||||
| bash ./converter.sh - ./converter.conf | ||||
| ``` | ||||
| 
 | ||||
| Example usage with cron: | ||||
| 
 | ||||
| ```bash | ||||
| # crontab -e | ||||
| 1  0  *  *  * bash /home/user/cctv-scheduler/converter.sh qn - -d | ||||
|  | @ -122,17 +150,22 @@ Example usage with cron: | |||
| 30 0  1  *  * bash /home/user/cctv-scheduler/converter.sh qn - -m | ||||
| 36 0  1  1  * bash /home/user/cctv-scheduler/converter.sh qn - -y | ||||
| ``` | ||||
| 
 | ||||
| ____ | ||||
| 
 | ||||
| ## `publisher`.sh | ||||
| 
 | ||||
| **Description:** | ||||
| > Uploading MP4 to [Wordpress](https://wordpress.com/) and [Telegram](https://web.telegram.org/).   | ||||
| > Additionally: | ||||
| > | ||||
| > - editing [Wordpress](https://codex.wordpress.org/XML-RPC_WordPress_API) page from template | ||||
| > - recompressing video if size [over 50MB](https://core.telegram.org/bots/api#sendvideo) | ||||
| > | ||||
| > This is only a local "proof of conept" for testing and debugging. | ||||
| 
 | ||||
| **Dependencies:**   | ||||
| > | ||||
| > - [bash](https://www.gnu.org/software/bash/) (tested version 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - [curl](https://curl.se/download.html) (tested version 7.74 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
|  | @ -148,12 +181,14 @@ ____ | |||
| |     4     |    **[1\|2\|3..XXX]**    |multiplier for period: '' - 1 day\|week\|month\|year|1| | ||||
| |     5     |    **[--onlytg\|--onlywp]**    |'--onlytg' - only publish to Telegram \|'--onlywp' - only publish to Wordpress|| | ||||
| 
 | ||||
| Example usage in terminal with bash for publish to Telegram today's MP4: | ||||
| 
 | ||||
| Example usage in terminal with bash for publish today's MP4 maked: | ||||
| ```bash | ||||
| bash ./publisher.sh - ./publisher.conf - --onlytg | ||||
| bash ./publisher.sh - ./publisher.conf - - - - --onlytg | ||||
| ``` | ||||
| 
 | ||||
| Example usage with cron: | ||||
| 
 | ||||
| ```bash | ||||
| # crontab -e | ||||
| 1  1  *  *  * bash /home/user/cctv-scheduler/publisher.sh qn - -d | ||||
|  | @ -161,12 +196,16 @@ Example usage with cron: | |||
| 30 1  1  *  * bash /home/user/cctv-scheduler/publisher.sh qn - -m | ||||
| 36 1  1  1  * bash /home/user/cctv-scheduler/publisher.sh qn - -y | ||||
| ``` | ||||
| 
 | ||||
| ____ | ||||
| 
 | ||||
| ## `streaming`.py | ||||
| 
 | ||||
| **Description:** | ||||
| > FFmpeg management from Python   | ||||
| 
 | ||||
| **Dependencies:** | ||||
| > | ||||
| > - [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| > - [ffmpeg](https://ffmpeg.org/download.html) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/)) | ||||
| 
 | ||||
|  | @ -183,17 +222,22 @@ ____ | |||
| |**[--mono]**|detect ffmpeg running copy and terminate|| | ||||
| 
 | ||||
| Example usage in terminal with make the script executable:   | ||||
| 
 | ||||
| ```bash | ||||
| chmod u+x ./streaming.py | ||||
| ./streaming.py -s rtsp://user:pass@host:554/Streaming/Channels/101 --dst rtp://239.0.0.1:5554 | ||||
| ``` | ||||
| 
 | ||||
| Example usage with cron: | ||||
| 
 | ||||
| ```bash | ||||
| # crontab -e | ||||
| * * * * * /usr/bin/python3 /home/user/cctv-scheduler/streaming.py -s rtsp://user:pass@host:554/Streaming/Channels/video,http://Streaming/Channels/audio --dst rtmp://a.rtmp.youtube.com/live2/YOUKEY --mono --watchdog --sec 30 >> /dev/null 2>&1 | ||||
| * * * * * /usr/bin/python3 /home/user/cctv-scheduler/streaming.py -s ~/media.mp4 --dst rtmp://b.rtmp.youtube.com/live2?backup=1/YOUKEY --mono >> /dev/null 2>&1 | ||||
| ``` | ||||
| 
 | ||||
| Example usage in Python: | ||||
| 
 | ||||
| ```Python | ||||
| from streaming import FFmpeg | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										177
									
								
								converter.sh
									
									
									
									
									
								
							
							
						
						
									
										177
									
								
								converter.sh
									
									
									
									
									
								
							|  | @ -1,69 +1,113 @@ | |||
| #! /bin/bash | ||||
| 
 | ||||
| # | ||||
| ## DESCRIPTION: | ||||
| #    JPEG to MP4 converter. | ||||
| # DESCRIPTION: | ||||
| #   Converting JPEG collection to MP4. | ||||
| #   This is only a local "proof of conept" for testing and debugging. | ||||
| # | ||||
| 
 | ||||
| # DEPENDENCIES: | ||||
| #   - ffmpeg | ||||
| # | ||||
| ## DEPENDENCIES: sudo apt|yum install -y ffmpeg | ||||
| # | ||||
| 
 | ||||
| # | ||||
| ## FUNCTIONS | ||||
| # PARAMETERS: | ||||
| #   1: "qn" - execution without pauses | ||||
| #   2: custom configuration file path | ||||
| #   3: periods: '' - today | '-d' - yesterday | '-w' - last week | '-m' - last month | '-y' - last year | ||||
| # | ||||
| # FUNCTIONS: | ||||
| # | ||||
| 
 | ||||
| ####################################### | ||||
| # Print message and add to log. | ||||
| # Globals: | ||||
| #   logs | ||||
| # Arguments: | ||||
| #   1: message to print and logging | ||||
| ####################################### | ||||
| addtologs() { | ||||
| 	echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs | ||||
|   echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a "${logs}" | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Waiting for press [ENTER]. | ||||
| # Globals: | ||||
| #   None | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| execpause() { | ||||
| 	read -p "Press [ENTER] to continue... " | ||||
|   read -r -p "Press [ENTER] to continue... " | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Exit procedure. | ||||
| # Globals: | ||||
| #   show | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| execquite() { | ||||
| 	addtologs "execution time is $(($(date +%s)-$time)) seconds, exit" | ||||
|   addtologs "execution time is $(($(date +%s)-time)) seconds, exit" | ||||
|   if [ "${show}" != "qn" ]; then | ||||
|   execpause | ||||
|   fi | ||||
|   exit | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Error exit procedure with Telegram notification. | ||||
| # Globals: | ||||
| #   telegramapiurl | ||||
| #   telegramchatid | ||||
| # Arguments: | ||||
| #   1: message to print and logging | ||||
| ####################################### | ||||
| execerror() { | ||||
|   addtologs "error: $1" | ||||
| 	curl -s -X POST $telegramapiurl/sendMessage -d chat_id=$telegramchatid -d text="$(basename -s .sh $0) error: $1" >> /dev/null 2>&1 | ||||
|   curl -s -X POST "${telegramapiurl}/sendMessage" \ | ||||
|   -d "chat_id=${telegramchatid}" \ | ||||
|   -d "text=$(basename -s .sh "$0") error: $1" \ | ||||
|   >> /dev/null 2>&1 | ||||
|   execquite | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Parsing config file and creating global vars. | ||||
| # Globals: | ||||
| #   None | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| getconfig() { | ||||
| 	logs=$(cat $conf | grep "logs=" | cut -d= -f2) | ||||
| 	list=$(cat $conf | grep "list=" | cut -d= -f2) | ||||
| 	imgroot=$(cat $conf | grep "imgroot=" | cut -d= -f2) | ||||
| 	imgnames=($(cat $conf | grep "imgnames=" | cut -d= -f2)) | ||||
| 	xscale=$(cat $conf | grep "xscale=" | cut -d= -f2) | ||||
| 	yscale=$(cat $conf | grep "yscale=" | cut -d= -f2) | ||||
| 	mp4fps=$(cat $conf | grep "mp4fps=" | cut -d= -f2) | ||||
| 	telegramapiurl=$(cat $conf | grep "telegramapiurl=" | cut -d= -f2) | ||||
| 	telegramchatid=$(cat $conf | grep "telegramchatid=" | cut -d= -f2) | ||||
|   logs=$(grep "logs=" "${conf}" | cut -d= -f2) | ||||
|   list=$(grep "list=" "${conf}" | cut -d= -f2) | ||||
|   imgroot=$(grep "imgroot=" "${conf}" | cut -d= -f2) | ||||
|   IFS=" " read -r -a imgnames <<< "$(grep "imgnames=" "${conf}" | cut -d= -f2)" | ||||
|   xscale=$(grep "xscale=" "${conf}" | cut -d= -f2) | ||||
|   yscale=$(grep "yscale=" "${conf}" | cut -d= -f2) | ||||
|   mp4fps=$(grep "mp4fps=" "${conf}" | cut -d= -f2) | ||||
|   telegramapiurl=$(grep "telegramapiurl=" "${conf}" | cut -d= -f2) | ||||
|   telegramchatid=$(grep "telegramchatid=" "${conf}" | cut -d= -f2) | ||||
| } | ||||
| 
 | ||||
| # | ||||
| ## PARAMETERS | ||||
| ## VARIABLES: | ||||
| # | ||||
| 
 | ||||
| show=${1} | ||||
| conf=${2} | ||||
| show=$1 | ||||
| conf=$2 | ||||
| if [ -z "${conf}" ] || [ "${conf}" == "-" ]; then | ||||
| 	conf="$(dirname $(realpath "$0"))/$(basename -s .sh $0).conf" | ||||
|   conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").conf" | ||||
| fi | ||||
| when=${3} | ||||
| if [ -z "$when" ]; then | ||||
| when=$3 | ||||
| if [ -z "${when}" ]; then | ||||
|   d=$(date +"%d") | ||||
|   w=$(date +"%V") | ||||
|   m=$(date +"%m") | ||||
|   y=$(date +"%Y") | ||||
|   duration=1 | ||||
| 	imgpath=$y/$m/$w/$d | ||||
| 	imgname=$y.$m.$d | ||||
|   imgpath="${y}/${m}/${w}/${d}" | ||||
|   imgname="${y}.${m}.${d}" | ||||
| fi | ||||
| if [ "$when" == "-d" ]; then | ||||
| if [ "${when}" == "-d" ]; then | ||||
|   d=$(date -d "-1 day" +"%d") | ||||
|   m=$(date +"%m") | ||||
|   if [ "$(date -d '-1 day' +'%m')" != "$(date +'%m')" ]; then | ||||
|  | @ -78,10 +122,10 @@ if [ "$when" == "-d" ]; then | |||
|     w=$(date -d "-1 week" +"%V") | ||||
|   fi | ||||
|   duration=1 | ||||
| 	imgpath=$y/$m/$w/$d | ||||
| 	imgname=$y.$m.$d | ||||
|   imgpath="${y}/${m}/${w}/${d}" | ||||
|   imgname="${y}.${m}.${d}" | ||||
| fi | ||||
| if [ "$when" == "-w" ]; then | ||||
| if [ "${when}" == "-w" ]; then | ||||
|   w=$(date -d "-1 week" +"%V") | ||||
|   m=$(date +"%m") | ||||
|   if [ "$(date -d '-1 week' +'%m')" != "$(date +'%m')" ]; then | ||||
|  | @ -92,74 +136,73 @@ if [ "$when" == "-w" ]; then | |||
|     y=$(date -d '-1 week' +'%Y') | ||||
|   fi | ||||
|   duration=7 | ||||
| 	imgpath=$y/*/$w | ||||
| 	imgname=$y-w$w | ||||
|   imgpath="${y}/*/${w}" | ||||
|   imgname="${y}-w${w}" | ||||
| fi | ||||
| if [ "$when" == "-m" ]; then | ||||
| if [ "${when}" == "-m" ]; then | ||||
|   m=$(date -d "-1 month" +"%m") | ||||
|   y=$(date +"%Y") | ||||
|   if [ "$(date -d '-1 month' +'%Y')" != "$(date +'%Y')" ]; then | ||||
|     y=$(date -d '-1 month' +'%Y') | ||||
|   fi | ||||
|   duration=30 | ||||
| 	imgpath=$y/$m | ||||
| 	imgname=$y.$m | ||||
|   imgpath="${y}/${m}" | ||||
|   imgname="${y}.${m}" | ||||
| fi | ||||
| if [ "$when" == "-y" ]; then | ||||
| if [ "${when}" == "-y" ]; then | ||||
|   y=$(date -d "-1 year" +"%Y") | ||||
|   duration=360 | ||||
| 	imgpath=$y | ||||
| 	imgname=$y | ||||
|   imgpath="${y}" | ||||
|   imgname="${y}" | ||||
| fi | ||||
| 
 | ||||
| # | ||||
| ## VARIABLES | ||||
| # | ||||
| 
 | ||||
| time=$(date +%s) | ||||
| cd "$(dirname "$(realpath "$0")")" | ||||
| if [ ! -e ${conf} ];then | ||||
| cd "$(dirname "$(realpath "$0")")" || execerror | ||||
| if [ ! -e "${conf}" ]; then | ||||
|   execerror "Not found config file: ${conf}" | ||||
| else | ||||
|   getconfig | ||||
| fi | ||||
| if [ -z "${logs}" ];then | ||||
|   logs=/dev/null | ||||
| elif [ ! -e ${logs} ];then | ||||
| 	touch ${logs} | ||||
| elif [ ! -e "${logs}" ];then | ||||
|   touch "${logs}" | ||||
| fi | ||||
| if [ -z "${list}" ];then | ||||
| 	list="$(dirname $(realpath "$0"))/$(basename -s .sh $0).list" | ||||
|   list="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").list" | ||||
| fi | ||||
| if [ ! -e ${list} ];then | ||||
| 	touch ${list} | ||||
| if [ ! -e "${list}" ];then | ||||
|   touch "${list}" | ||||
| fi | ||||
| if ! command -v ffmpeg &> /dev/null; then | ||||
|   execerror "Not found dependencies" | ||||
| fi | ||||
| 
 | ||||
| # | ||||
| ## RUN | ||||
| # MAIN: | ||||
| # | ||||
| 
 | ||||
| for name in ${imgnames[*]}; do | ||||
| 	imgmatch="*$name*.jpeg" | ||||
| for name in "${imgnames[@]}"; do | ||||
|   imgmatch="*${name}*.jpeg" | ||||
|   imgarray=() | ||||
| 	while read FILE; do | ||||
|   while read -r FILE; do | ||||
|     imgarray+=("${FILE}") | ||||
| 	done < <(find $imgroot/$imgpath -name "$imgmatch" | sort) | ||||
|   done < <(find "${imgroot}/${imgpath}" -name "${imgmatch}" | sort) | ||||
|   imgcount=${#imgarray[*]} | ||||
| 
 | ||||
| 	echo '' > $list | ||||
| 	for item in ${imgarray[*]}; do | ||||
| 		echo file \'$item\' >> $list | ||||
|   echo '' > "${list}" | ||||
|   for item in "${imgarray[@]}"; do | ||||
|     echo file \'"${item}"\' >> "${list}" | ||||
|   done | ||||
| 
 | ||||
| 	imgdest=$imgroot/$name\_$imgname.mp4 | ||||
| 	echo $imgdest | ||||
| 	#ffmpeg -r $imgcount/$duration -f concat -safe 0 -i $list -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t $duration -c:v libx264 -vf "scale=$xscale:$yscale,fps=$mp4fps,format=yuv420p" -c:a aac $imgdest -y | ||||
| 	ffmpeg -r $imgcount/$duration -f concat -safe 0 -i $list -c:v libx264 -vf "scale=$xscale:$yscale,fps=$mp4fps,format=yuv420p" $imgdest -y \ | ||||
| 	&& addtologs "converted $imgcount images to $imgdest with duration $duration" \ | ||||
| 	|| execerror "converted $imgcount images to $imgdest with duration $duration" | ||||
|   imgdest="${imgroot}/${name}_${imgname}.mp4" | ||||
|   echo "${imgdest}" | ||||
|   if ffmpeg -r "${imgcount}/${duration}" -f concat -safe 0 -i "${list}" \ | ||||
|     -c:v libx264 -vf "scale=${xscale}:${yscale},fps=${mp4fps},format=yuv420p" \ | ||||
| 	"${imgdest}" -y; then | ||||
|     addtologs "converted ${imgcount} images to ${imgdest} with duration ${duration}" | ||||
|   else | ||||
|     execerror "converted ${imgcount} images to ${imgdest} with duration ${duration}" | ||||
|   fi | ||||
| done | ||||
| execquite | ||||
|  |  | |||
							
								
								
									
										620
									
								
								publisher.sh
									
									
									
									
									
								
							
							
						
						
									
										620
									
								
								publisher.sh
									
									
									
									
									
								
							|  | @ -1,298 +1,357 @@ | |||
| #! /bin/bash | ||||
| 
 | ||||
| # | ||||
| ## DESCRIPTION: | ||||
| # DESCRIPTION: | ||||
| #   Uploading MP4 to Wordpress and Telegram. | ||||
| #   Additionally: | ||||
| #   - editing Wordpress page from template | ||||
| #   - recompressing video if size over 50MB | ||||
| #   This is only a local "proof of conept" for testing and debugging. | ||||
| # | ||||
| 
 | ||||
| # DEPENDENCIES: | ||||
| #   - curl | ||||
| #   - ffmpeg | ||||
| #   - libxml2-utils | ||||
| #   - jq | ||||
| # | ||||
| ## DEPENDENCIES: sudo apt|yum install -y curl ffmpeg libxml2-utils jq | ||||
| # | ||||
| 
 | ||||
| # | ||||
| ## FUNCTIONS | ||||
| # PARAMETERS: | ||||
| #   1: "qn" - execution without pauses | ||||
| #   2: custom configuration file path | ||||
| #   3: periods: '' - today | '-d' - yesterday | '-w' - last week | '-m' - last month | '-y' - last year | ||||
| #   4: period multiplier: '' - 1 day|week|month|year | ||||
| #   5: publishing '--onlytg' - only to Telegram | '--onlywp' - only to Wordpress | ||||
| # | ||||
| # FUNCTIONS: | ||||
| # | ||||
| 
 | ||||
| ####################################### | ||||
| # Print message and add to log. | ||||
| # Globals: | ||||
| #   logs | ||||
| # Arguments: | ||||
| #   1: message to print and logging | ||||
| ####################################### | ||||
| addtologs() { | ||||
| 	echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs | ||||
|   echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a "${logs}" | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Waiting for press [ENTER]. | ||||
| # Globals: | ||||
| #   None | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| execpause() { | ||||
| 	read -p "Press [ENTER] to continue... " | ||||
|   read -r -p "Press [ENTER] to continue... " | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Exit procedure. | ||||
| # Globals: | ||||
| #   show | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| execquite() { | ||||
| 	addtologs "execution time is $(($(date +%s)-$time)) seconds, exit" | ||||
|   addtologs "execution time is $(($(date +%s)-time)) seconds, exit" | ||||
|   if [ "${show}" != "qn" ]; then | ||||
|   execpause | ||||
|   fi | ||||
|   exit | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Error exit procedure with Telegram notification. | ||||
| # Globals: | ||||
| #   telegramapiurl | ||||
| #   telegramchatid | ||||
| # Arguments: | ||||
| #   1: message to print and logging | ||||
| ####################################### | ||||
| execerror() { | ||||
|   addtologs "error: $1" | ||||
| 	curl -s -X POST $telegramapiurl/sendMessage -d chat_id=$telegramchatid -d text="$(basename -s .sh $0) error: $1" >> /dev/null 2>&1 | ||||
|   curl -s -X POST "${telegramapiurl}/sendMessage" \ | ||||
|   -d "chat_id=${telegramchatid}" \ | ||||
|   -d "text=$(basename -s .sh "$0") error: $1" \ | ||||
|   >> /dev/null 2>&1 | ||||
|   execquite | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Parsing config file and creating global vars. | ||||
| # Globals: | ||||
| #   None | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| getconfig() { | ||||
| 	logs=$(cat $conf | grep "logs=" | cut -d= -f2) | ||||
| 	pathroot=$(cat $conf | grep "pathroot=" | cut -d= -f2) | ||||
| 	vidnamesarray=($(cat $conf | grep "vidnamesarray=" | cut -d= -f2)) | ||||
| 	telegramapiurl=$(cat $conf | grep "telegramapiurl=" | cut -d= -f2) | ||||
| 	telegramchatid=$(cat $conf | grep "telegramchatid=" | cut -d= -f2) | ||||
| 	tgpreviewlink=$(cat $conf | grep "tgpreviewlink=" | cut -d= -f2) | ||||
| 	tgpreviewtext=$(cat $conf | grep "tgpreviewtext=" | cut -d= -f2) | ||||
| 	wpxmlrpclink=$(cat $conf | grep "wpxmlrpclink=" | cut -d= -f2) | ||||
| 	wpxmlrpcuser=$(cat $conf | grep "wpxmlrpcuser=" | cut -d= -f2) | ||||
| 	wpxmlrpcpass=$(cat $conf | grep "wpxmlrpcpass=" | cut -d= -f2) | ||||
| 	wppageauthor=$(cat $conf | grep "wppageauthor=" | cut -d= -f2) | ||||
| 	wppagelinkis=$(cat $conf | grep "wppagelinkis=" | cut -d= -f2) | ||||
| 	wpeditpageid=$(cat $conf | grep "wpeditpageid=" | cut -d= -f2) | ||||
| 	wpedituserid=$(cat $conf | grep "wpedituserid=" | cut -d= -f2) | ||||
| 	wpeditdateis=$(cat $conf | grep "wpeditdateis=" | cut -d= -f2) | ||||
| 	wptemplateis=$(cat $conf | grep "wptemplateis=" | cut -d= -f2) | ||||
| 	youtubelink=$(cat $conf | grep "youtubelink=" | cut -d= -f2) | ||||
|   logs=$(grep "logs=" "${conf}" | cut -d= -f2) | ||||
|   pathroot=$(grep "pathroot=" "${conf}" | cut -d= -f2) | ||||
|   IFS=" " read -r -a vidnamesarray <<< "$(grep "vidnamesarray=" "${conf}" | cut -d= -f2)" | ||||
|   telegramapiurl=$(grep "telegramapiurl=" "${conf}" | cut -d= -f2) | ||||
|   telegramchatid=$(grep "telegramchatid=" "${conf}" | cut -d= -f2) | ||||
|   tgpreviewlink=$(grep "tgpreviewlink=" "${conf}" | cut -d= -f2) | ||||
|   tgpreviewtext=$(grep "tgpreviewtext=" "${conf}" | cut -d= -f2) | ||||
|   wpxmlrpclink=$(grep "wpxmlrpclink=" "${conf}" | cut -d= -f2) | ||||
|   wpxmlrpcuser=$(grep "wpxmlrpcuser=" "${conf}" | cut -d= -f2) | ||||
|   wpxmlrpcpass=$(grep "wpxmlrpcpass=" "${conf}" | cut -d= -f2) | ||||
|   wppageauthor=$(grep "wppageauthor=" "${conf}" | cut -d= -f2) | ||||
|   wppagelinkis=$(grep "wppagelinkis=" "${conf}" | cut -d= -f2) | ||||
|   wpeditpageid=$(grep "wpeditpageid=" "${conf}" | cut -d= -f2) | ||||
|   wpedituserid=$(grep "wpedituserid=" "${conf}" | cut -d= -f2) | ||||
|   wpeditdateis=$(grep "wpeditdateis=" "${conf}" | cut -d= -f2) | ||||
|   wptemplateis=$(grep "wptemplateis=" "${conf}" | cut -d= -f2) | ||||
|   youtubelink=$(grep "youtubelink=" "${conf}" | cut -d= -f2) | ||||
| 
 | ||||
| 	defaultdp01=($(cat $conf | grep "defaultdp01=" | cut -d= -f2)) | ||||
| 	defaultwp01=($(cat $conf | grep "defaultwp01=" | cut -d= -f2)) | ||||
| 	defaultmp01=($(cat $conf | grep "defaultmp01=" | cut -d= -f2)) | ||||
| 	defaultyp01=($(cat $conf | grep "defaultyp01=" | cut -d= -f2)) | ||||
|   IFS=" " read -r -a defaultdp01 <<< "$(grep "defaultdp01=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultwp01 <<< "$(grep "defaultwp01=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultmp01 <<< "$(grep "defaultmp01=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultyp01 <<< "$(grep "defaultyp01=" "${conf}" | cut -d= -f2)" | ||||
| 
 | ||||
| 	defaultdp02=($(cat $conf | grep "defaultdp02=" | cut -d= -f2)) | ||||
| 	defaultwp02=($(cat $conf | grep "defaultwp02=" | cut -d= -f2)) | ||||
| 	defaultmp02=($(cat $conf | grep "defaultmp02=" | cut -d= -f2)) | ||||
| 	defaultyp02=($(cat $conf | grep "defaultyp02=" | cut -d= -f2)) | ||||
|   IFS=" " read -r -a defaultdp02 <<< "$(grep "defaultdp02=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultwp02 <<< "$(grep "defaultwp02=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultmp02 <<< "$(grep "defaultmp02=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultyp02 <<< "$(grep "defaultyp02=" "${conf}" | cut -d= -f2)" | ||||
| 
 | ||||
| 	defaultdp04=($(cat $conf | grep "defaultdp04=" | cut -d= -f2)) | ||||
| 	defaultwp04=($(cat $conf | grep "defaultwp04=" | cut -d= -f2)) | ||||
| 	defaultmp04=($(cat $conf | grep "defaultmp04=" | cut -d= -f2)) | ||||
| 	defaultyp04=($(cat $conf | grep "defaultyp04=" | cut -d= -f2)) | ||||
|   IFS=" " read -r -a defaultdp04 <<< "$(grep "defaultdp04=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultwp04 <<< "$(grep "defaultwp04=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultmp04 <<< "$(grep "defaultmp04=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultyp04 <<< "$(grep "defaultyp04=" "${conf}" | cut -d= -f2)" | ||||
| 
 | ||||
| 	defaultdp05=($(cat $conf | grep "defaultdp05=" | cut -d= -f2)) | ||||
| 	defaultwp05=($(cat $conf | grep "defaultwp05=" | cut -d= -f2)) | ||||
| 	defaultmp05=($(cat $conf | grep "defaultmp05=" | cut -d= -f2)) | ||||
| 	defaultyp05=($(cat $conf | grep "defaultyp05=" | cut -d= -f2)) | ||||
|   IFS=" " read -r -a defaultdp05 <<< "$(grep "defaultdp05=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultwp05 <<< "$(grep "defaultwp05=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultmp05 <<< "$(grep "defaultmp05=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultyp05 <<< "$(grep "defaultyp05=" "${conf}" | cut -d= -f2)" | ||||
| 
 | ||||
| 	defaultdp11=($(cat $conf | grep "defaultdp11=" | cut -d= -f2)) | ||||
| 	defaultwp11=($(cat $conf | grep "defaultwp11=" | cut -d= -f2)) | ||||
| 	defaultmp11=($(cat $conf | grep "defaultmp11=" | cut -d= -f2)) | ||||
| 	defaultyp11=($(cat $conf | grep "defaultyp11=" | cut -d= -f2)) | ||||
|   IFS=" " read -r -a defaultdp11 <<< "$(grep "defaultdp11=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultwp11 <<< "$(grep "defaultwp11=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultmp11 <<< "$(grep "defaultmp11=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultyp11 <<< "$(grep "defaultyp11=" "${conf}" | cut -d= -f2)" | ||||
| 
 | ||||
| 	defaultdp12=($(cat $conf | grep "defaultdp12=" | cut -d= -f2)) | ||||
| 	defaultwp12=($(cat $conf | grep "defaultwp12=" | cut -d= -f2)) | ||||
| 	defaultmp12=($(cat $conf | grep "defaultmp12=" | cut -d= -f2)) | ||||
| 	defaultyp12=($(cat $conf | grep "defaultyp12=" | cut -d= -f2)) | ||||
|   IFS=" " read -r -a defaultdp12 <<< "$(grep "defaultdp12=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultwp12 <<< "$(grep "defaultwp12=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultmp12 <<< "$(grep "defaultmp12=" "${conf}" | cut -d= -f2)" | ||||
|   IFS=" " read -r -a defaultyp12 <<< "$(grep "defaultyp12=" "${conf}" | cut -d= -f2)" | ||||
| 
 | ||||
| 
 | ||||
| 	currentdp01=($(cat $conf | grep "currentdp01=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentdp01" ];then | ||||
| 		currentdp01=(${defaultdp01[*]}) | ||||
|   IFS=" " read -r -a currentdp01 <<< "$(grep "currentdp01=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentdp01[1]}" ]; then | ||||
|     currentdp01=${defaultdp01[*]} | ||||
|   fi | ||||
| 	currentwp01=($(cat $conf | grep "currentwp01=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentwp01" ];then | ||||
| 		currentwp01=(${defaultwp01[*]}) | ||||
|   IFS=" " read -r -a currentwp01 <<< "$(grep "currentwp01=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentwp01[1]}" ]; then | ||||
|     currentwp01=${defaultwp01[*]} | ||||
|   fi | ||||
| 	currentmp01=($(cat $conf | grep "currentmp01=" | cut -d= -f2)) | ||||
| 		if [ -z "$currentmp01" ];then | ||||
| 		currentmp01=(${defaultmp01[*]}) | ||||
|   IFS=" " read -r -a currentmp01 <<< "$(grep "currentmp01=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentmp01[1]}" ]; then | ||||
|     currentmp01=${defaultmp01[*]} | ||||
|   fi | ||||
| 	currentyp01=($(cat $conf | grep "currentyp01=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentyp01" ];then | ||||
| 		currentyp01=(${defaultyp01[*]}) | ||||
|   IFS=" " read -r -a currentyp01 <<< "$(grep "currentyp01=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentyp01[1]}" ]; then | ||||
|     currentyp01=${defaultyp01[*]} | ||||
|   fi | ||||
| 
 | ||||
| 	currentdp02=($(cat $conf | grep "currentdp02=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentdp02" ];then | ||||
| 		currentdp02=(${defaultdp02[*]}) | ||||
|   IFS=" " read -r -a currentdp02 <<< "$(grep "currentdp02=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentdp02[1]}" ]; then | ||||
|     currentdp02=${defaultdp02[*]} | ||||
|   fi | ||||
| 	currentwp02=($(cat $conf | grep "currentwp02=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentwp02" ];then | ||||
| 		currentwp02=(${defaultwp02[*]}) | ||||
|   IFS=" " read -r -a currentwp02 <<< "$(grep "currentwp02=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentwp02[1]}" ]; then | ||||
|     currentwp02=${defaultwp02[*]} | ||||
|   fi | ||||
| 	currentmp02=($(cat $conf | grep "currentmp02=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentmp02" ];then | ||||
| 		currentmp02=(${defaultmp02[*]}) | ||||
|   IFS=" " read -r -a currentmp02 <<< "$(grep "currentmp02=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentmp02[1]}" ]; then | ||||
|     currentmp02=${defaultmp02[*]} | ||||
|   fi | ||||
| 	currentyp02=($(cat $conf | grep "currentyp02=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentyp02" ];then | ||||
| 		currentyp02=(${defaultyp02[*]}) | ||||
|   IFS=" " read -r -a currentyp02 <<< "$(grep "currentyp02=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentyp02[1]}" ]; then | ||||
|     currentyp02=${defaultyp02[*]} | ||||
|   fi | ||||
| 
 | ||||
| 	currentdp04=($(cat $conf | grep "currentdp04=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentdp04" ];then | ||||
| 		currentdp04=(${defaultdp04[*]}) | ||||
|   IFS=" " read -r -a currentdp04 <<< "$(grep "currentdp04=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentdp04[1]}" ]; then | ||||
|     currentdp04=${defaultdp04[*]} | ||||
|   fi | ||||
| 	currentwp04=($(cat $conf | grep "currentwp04=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentwp04" ];then | ||||
| 		currentwp04=(${defaultwp04[*]}) | ||||
|   IFS=" " read -r -a currentwp04 <<< "$(grep "currentwp04=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentwp04[1]}" ]; then | ||||
|     currentwp04=${defaultwp04[*]} | ||||
|   fi | ||||
| 	currentmp04=($(cat $conf | grep "currentmp04=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentmp04" ];then | ||||
| 		currentmp04=(${defaultmp04[*]}) | ||||
|   IFS=" " read -r -a currentmp04 <<< "$(grep "currentmp04=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentmp04[1]}" ]; then | ||||
|     currentmp04=${defaultmp04[*]} | ||||
|   fi | ||||
| 	currentyp04=($(cat $conf | grep "currentyp04=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentyp04" ];then | ||||
| 		currentyp04=(${defaultyp04[*]}) | ||||
|   IFS=" " read -r -a currentyp04 <<< "$(grep "currentyp04=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentyp04[1]}" ]; then | ||||
|     currentyp04=${defaultyp04[*]} | ||||
|   fi | ||||
| 
 | ||||
| 	currentdp05=($(cat $conf | grep "currentdp05=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentdp05" ];then | ||||
| 		currentdp05=(${defaultdp05[*]}) | ||||
|   IFS=" " read -r -a currentdp05 <<< "$(grep "currentdp05=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentdp05[1]}" ]; then | ||||
|     currentdp05=${defaultdp05[*]} | ||||
|   fi | ||||
| 	currentwp05=($(cat $conf | grep "currentwp05=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentwp05" ];then | ||||
| 		currentwp05=(${defaultwp05[*]}) | ||||
|   IFS=" " read -r -a currentwp05 <<< "$(grep "currentwp05=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentwp05[1]}" ]; then | ||||
|     currentwp05=${defaultwp05[*]} | ||||
|   fi | ||||
| 	currentmp05=($(cat $conf | grep "currentmp05=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentmp05" ];then | ||||
| 		currentmp05=(${defaultmp05[*]}) | ||||
|   IFS=" " read -r -a currentmp05 <<< "$(grep "currentmp05=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentmp05[1]}" ]; then | ||||
|     currentmp05=${defaultmp05[*]} | ||||
|   fi | ||||
| 	currentyp05=($(cat $conf | grep "currentyp05=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentyp05" ];then | ||||
| 		currentyp05=(${defaultyp05[*]}) | ||||
|   IFS=" " read -r -a currentyp05 <<< "$(grep "currentyp05=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentyp05[1]}" ]; then | ||||
|     currentyp05=${defaultyp05[*]} | ||||
|   fi | ||||
| 
 | ||||
| 	currentdp11=($(cat $conf | grep "currentdp11=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentdp11" ];then | ||||
| 		currentdp11=(${defaultdp11[*]}) | ||||
|   IFS=" " read -r -a currentdp11 <<< "$(grep "currentdp11=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentdp11[1]}" ]; then | ||||
|     currentdp11=${defaultdp11[*]} | ||||
|   fi | ||||
| 	currentwp11=($(cat $conf | grep "currentwp11=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentwp11" ];then | ||||
| 		currentwp11=(${defaultwp11[*]}) | ||||
|   IFS=" " read -r -a currentwp11 <<< "$(grep "currentwp11=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentwp11[1]}" ]; then | ||||
|     currentwp11=${defaultwp11[*]} | ||||
|   fi | ||||
| 	currentmp11=($(cat $conf | grep "currentmp11=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentmp11" ];then | ||||
| 		currentmp11=(${defaultmp11[*]}) | ||||
|   IFS=" " read -r -a currentmp11 <<< "$(grep "currentmp11=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentmp11[1]}" ]; then | ||||
|     currentmp11=${defaultmp11[*]} | ||||
|   fi | ||||
| 	currentyp11=($(cat $conf | grep "currentyp11=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentyp11" ];then | ||||
| 		currentyp11=(${defaultyp11[*]}) | ||||
|   IFS=" " read -r -a currentyp11 <<< "$(grep "currentyp11=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentyp11[1]}" ]; then | ||||
|     currentyp11=${defaultyp11[*]} | ||||
|   fi | ||||
| 
 | ||||
| 	currentdp12=($(cat $conf | grep "currentdp12=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentdp12" ];then | ||||
| 		currentdp12=(${defaultdp12[*]}) | ||||
|   IFS=" " read -r -a currentdp12 <<< "$(grep "currentdp12=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentdp12[1]}" ]; then | ||||
|     currentdp12=${defaultdp12[*]} | ||||
|   fi | ||||
| 	currentwp12=($(cat $conf | grep "currentwp12=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentwp12" ];then | ||||
| 		currentwp12=(${defaultwp12[*]}) | ||||
|   IFS=" " read -r -a currentwp12 <<< "$(grep "currentwp12=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentwp12[1]}" ]; then | ||||
|     currentwp12=${defaultwp12[*]} | ||||
|   fi | ||||
| 	currentmp12=($(cat $conf | grep "currentmp12=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentmp12" ];then | ||||
| 		currentmp12=(${defaultmp12[*]}) | ||||
|   IFS=" " read -r -a currentmp12 <<< "$(grep "currentmp12=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentmp12[1]}" ]; then | ||||
|     currentmp12=${defaultmp12[*]} | ||||
|   fi | ||||
| 	currentyp12=($(cat $conf | grep "currentyp12=" | cut -d= -f2)) | ||||
| 	if [ -z "$currentyp12" ];then | ||||
| 		currentyp12=(${defaultyp12[*]}) | ||||
|   IFS=" " read -r -a currentyp12 <<< "$(grep "currentyp12=" "${conf}" | cut -d= -f2)" | ||||
|   if [ -z "${currentyp12[1]}" ]; then | ||||
|     currentyp12=${defaultyp12[*]} | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Writing changes to configuration file. | ||||
| # Globals: | ||||
| #   conf | ||||
| #   when | ||||
| #   vidnamesarray | ||||
| #   vidlinksarray | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| setconfig() { | ||||
| 	if [ -z "$target" ] || [ "$target" == "-d" ];then | ||||
| 		if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentdp01=')#currentdp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf | ||||
|   if [ -z "${when}" ] || [ "${when}" == "-d" ]; then | ||||
|     if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then | ||||
|       sed -i "s#$(grep 'currentdp01=' "${conf}")#currentdp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentdp02=')#currentdp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf | ||||
|     if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then | ||||
|       sed -i "s#$(grep 'currentdp02=' "${conf}")#currentdp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentdp04=')#currentdp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf | ||||
|     if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then | ||||
|       sed -i "s#$(grep 'currentdp04=' "${conf}")#currentdp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentdp05=')#currentdp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf | ||||
|     if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then | ||||
|       sed -i "s#$(grep 'currentdp05=' "${conf}")#currentdp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentdp11=')#currentdp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf | ||||
|     if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then | ||||
|       sed -i "s#$(grep 'currentdp11=' "${conf}")#currentdp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentdp12=')#currentdp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf | ||||
|     if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then | ||||
|       sed -i "s#$(grep 'currentdp12=' "${conf}")#currentdp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}" | ||||
|     fi | ||||
|   fi | ||||
| 	if [ "$target" == "-w" ];then | ||||
| 		if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentwp01=')#currentwp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf | ||||
|   if [ "${when}" == "-w" ]; then | ||||
|     if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then | ||||
|       sed -i "s#$(grep 'currentwp01=' "${conf}")#currentwp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentwp02=')#currentwp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf | ||||
|     if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then | ||||
|       sed -i "s#$(grep 'currentwp02=' "${conf}")#currentwp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentwp04=')#currentwp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf | ||||
|     if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then | ||||
|       sed -i "s#$(grep 'currentwp04=' "${conf}")#currentwp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentwp05=')#currentwp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf | ||||
|     if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then | ||||
|       sed -i "s#$(grep 'currentwp05=' "${conf}")#currentwp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentwp11=')#currentwp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf | ||||
|     if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then | ||||
|       sed -i "s#$(grep 'currentwp11=' "${conf}")#currentwp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentwp12=')#currentwp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf | ||||
|     if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then | ||||
|       sed -i "s#$(grep 'currentwp12=' "${conf}")#currentwp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}" | ||||
|     fi | ||||
|   fi | ||||
| 	if [ "$target" == "-m" ];then | ||||
| 		if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentmp01=')#currentmp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf | ||||
|   if [ "${when}" == "-m" ]; then | ||||
|     if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then | ||||
|       sed -i "s#$(grep 'currentmp01=' "${conf}")#currentmp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentmp02=')#currentmp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf | ||||
|     if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then | ||||
|       sed -i "s#$(grep 'currentmp02=' "${conf}")#currentmp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentmp04=')#currentmp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf | ||||
|     if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then | ||||
|       sed -i "s#$(grep 'currentmp04=' "${conf}")#currentmp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentmp05=')#currentmp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf | ||||
|     if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then | ||||
|       sed -i "s#$(grep 'currentmp05=' "${conf}")#currentmp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentmp11=')#currentmp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf | ||||
|     if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then | ||||
|       sed -i "s#$(grep 'currentmp11=' "${conf}")#currentmp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentmp12=')#currentmp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf | ||||
|     if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then | ||||
|       sed -i "s#$(grep 'currentmp12=' "${conf}")#currentmp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}" | ||||
|     fi | ||||
|   fi | ||||
| 	if [ "$target" == "-y" ];then | ||||
| 		if [ ! -z "${vidnamesarray[0]}" ] && [ ! -z "${vidlinksarray[0]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentyp01=')#currentyp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" $conf | ||||
|   if [ "${when}" == "-y" ]; then | ||||
|     if [ -n "${vidnamesarray[0]}" ] && [ -n "${vidlinksarray[0]}" ]; then | ||||
|       sed -i "s#$(grep 'currentyp01=' "${conf}")#currentyp01=${vidnamesarray[0]} ${vidlinksarray[0]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[1]}" ] && [ ! -z "${vidlinksarray[1]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentyp02=')#currentyp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" $conf | ||||
|     if [ -n "${vidnamesarray[1]}" ] && [ -n "${vidlinksarray[1]}" ]; then | ||||
|       sed -i "s#$(grep 'currentyp02=' "${conf}")#currentyp02=${vidnamesarray[1]} ${vidlinksarray[1]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[2]}" ] && [ ! -z "${vidlinksarray[2]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentyp04=')#currentyp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" $conf | ||||
|     if [ -n "${vidnamesarray[2]}" ] && [ -n "${vidlinksarray[2]}" ]; then | ||||
|       sed -i "s#$(grep 'currentyp04=' "${conf}")#currentyp04=${vidnamesarray[2]} ${vidlinksarray[2]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[3]}" ] && [ ! -z "${vidlinksarray[3]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentyp05=')#currentyp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" $conf | ||||
|     if [ -n "${vidnamesarray[3]}" ] && [ -n "${vidlinksarray[3]}" ]; then | ||||
|       sed -i "s#$(grep 'currentyp05=' "${conf}")#currentyp05=${vidnamesarray[3]} ${vidlinksarray[3]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[4]}" ] && [ ! -z "${vidlinksarray[4]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentyp11=')#currentyp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" $conf | ||||
|     if [ -n "${vidnamesarray[4]}" ] && [ -n "${vidlinksarray[4]}" ]; then | ||||
|       sed -i "s#$(grep 'currentyp11=' "${conf}")#currentyp11=${vidnamesarray[4]} ${vidlinksarray[4]}#" "${conf}" | ||||
|     fi | ||||
| 		if [ ! -z "${vidnamesarray[5]}" ] && [ ! -z "${vidlinksarray[5]}" ];then | ||||
| 			sed -i "s#$(cat $conf | grep 'currentyp12=')#currentyp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" $conf | ||||
|     if [ -n "${vidnamesarray[5]}" ] && [ -n "${vidlinksarray[5]}" ]; then | ||||
|       sed -i "s#$(grep 'currentyp12=' "${conf}")#currentyp12=${vidnamesarray[5]} ${vidlinksarray[5]}#" "${conf}" | ||||
|     fi | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| # | ||||
| ## PARAMETERS | ||||
| ## VARIABLES: | ||||
| # | ||||
| 
 | ||||
| show=${1} | ||||
| conf=${2} | ||||
| show=$1 | ||||
| conf=$2 | ||||
| if [ -z "${conf}" ] || [ "${conf}" == "-" ]; then | ||||
| 	conf="$(dirname $(realpath "$0"))/$(basename -s .sh $0).conf" | ||||
|   conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").conf" | ||||
| fi | ||||
| ever=${4} | ||||
| if [ -z "$ever" ] || [ "$ever" == "-" ];then | ||||
| ever=$4 | ||||
| if [ -z "${ever}" ] || [ "${ever}" == "-" ]; then | ||||
|   ever=1 | ||||
| fi | ||||
| if [ ! -z $(echo "$ever" | grep -o "^[0-9][0-9]*$") ];then | ||||
| if grep -q -o "^[0-9][0-9]*$" <<< "${ever}"; then | ||||
|   : | ||||
| else | ||||
| 	execerror "$ever - wrong argument" | ||||
|   execerror "${ever} - wrong argument" | ||||
| fi | ||||
| when=${3} | ||||
| if [ -z "$when" ];then | ||||
| when=$3 | ||||
| if [ -z "${when}" ]; then | ||||
|   viddate=$(date +"%Y").$(date +"%m").$(date +"%d") | ||||
| fi | ||||
| if [ "$when" == "-d" ];then | ||||
| if [ "${when}" == "-d" ]; then | ||||
|   d=$(date -d "-${ever} day" +"%d") | ||||
|   m=$(date +"%m") | ||||
|   if [ "$(date -d "-${ever} day" +'%m')" != "$(date +'%m')" ]; then | ||||
|  | @ -302,74 +361,71 @@ if [ "$when" == "-d" ];then | |||
|   if [ "$(date -d "-${ever} day" +'%Y')" != "$(date +'%Y')" ]; then | ||||
|     y=$(date -d "-${ever} day" +'%Y') | ||||
|   fi | ||||
| 	viddate=${y}.${m}.${d} | ||||
|   viddate="${y}.${m}.${d}" | ||||
| fi | ||||
| if [ "$when" == "-w" ];then | ||||
| if [ "${when}" == "-w" ]; then | ||||
|   w=$(date -d "-${ever} week" +"%V") | ||||
|   y=$(date +"%Y") | ||||
|   if [ "$(date -d "-${ever} week" +'%Y')" != "$(date +'%Y')" ]; then | ||||
|     y=$(date -d "-${ever} week" +'%Y') | ||||
|   fi | ||||
| 	viddate=${y}-w${w} | ||||
|   viddate="${y}-w${w}" | ||||
| fi | ||||
| if [ "$when" == "-m" ];then | ||||
| if [ "${when}" == "-m" ]; then | ||||
|   m=$(date -d "-${ever} month" +"%m") | ||||
|   y=$(date +"%Y") | ||||
|   if [ "$(date -d "-${ever} month" +'%Y')" != "$(date +'%Y')" ]; then | ||||
|     y=$(date -d "-${ever} month" +'%Y') | ||||
|   fi | ||||
| 	viddate=${y}.${m} | ||||
|   viddate="${y}.${m}" | ||||
| fi | ||||
| if [ "$when" == "-y" ];then | ||||
| if [ "${when}" == "-y" ]; then | ||||
|   y=$(date -d "-${ever} year" +"%Y") | ||||
| 	viddate=${y} | ||||
|   viddate="${y}" | ||||
| fi | ||||
| vidname=${viddate}.mp4 | ||||
| only=${5} | ||||
| 
 | ||||
| # | ||||
| ## VARIABLES | ||||
| # | ||||
| vidname="${viddate}.mp4" | ||||
| only=$5 | ||||
| 
 | ||||
| time=$(date +%s) | ||||
| cd "$(dirname "$(realpath "$0")")" | ||||
| if [ ! -e ${conf} ];then | ||||
| cd "$(dirname "$(realpath "$0")")" || execerror | ||||
| if [ ! -e "${conf}" ]; then | ||||
|   execerror "Not found config file: ${conf}" | ||||
| else | ||||
|   getconfig | ||||
| fi | ||||
| if [ -z "${logs}" ]; then | ||||
|   logs=/dev/null | ||||
| elif [ ! -e ${logs} ];then | ||||
| 	touch ${logs} | ||||
| elif [ ! -e "${logs}" ]; then | ||||
|   touch "${logs}" | ||||
| fi | ||||
| if ! command -v curl &> /dev/null || ! command -v ffmpeg &> /dev/null || ! command -v xmllint &> /dev/null || ! command -v jq &> /dev/null; then | ||||
| if ! command -v curl &> /dev/null || \ | ||||
|   ! command -v ffmpeg &> /dev/null || \ | ||||
|   ! command -v xmllint &> /dev/null || \ | ||||
|   ! command -v jq &> /dev/null; then | ||||
|   execerror "Not found dependencies" | ||||
| fi | ||||
| 
 | ||||
| # | ||||
| ## RUN | ||||
| # MAIN: | ||||
| # | ||||
| 
 | ||||
| vidpathsarray=() | ||||
| vidlinksarray=() | ||||
| vidtgidsarray=() | ||||
| vidtgcpsarray=() | ||||
| for name in ${vidnamesarray[*]} | ||||
| do | ||||
| 	vidmatch=$name\_$vidname | ||||
| 	while read FILE; do | ||||
| for name in "${vidnamesarray[@]}"; do | ||||
|   vidmatch="${name}_${vidname}" | ||||
|   while read -r FILE; do | ||||
|     vidpathsarray+=("${FILE}") | ||||
| 	done < <(find $pathroot -name "*$vidmatch" | sort) | ||||
|   done < <(find "${pathroot}" -name "*${vidmatch}" | sort) | ||||
| done | ||||
| for item in "${!vidpathsarray[@]}" | ||||
| do | ||||
| 	### WORDPRESS UPLOAD VIDEO | ||||
| for item in "${!vidpathsarray[@]}"; do | ||||
|   # WORDPRESS UPLOAD VIDEO | ||||
|   if [ ! "$only" == "--onlytg" ]; then | ||||
|     # This realisation isn't optimal, but it fixes a few issues with large files: | ||||
|     #    variable=$(base64 $file)                      -> "xrealloc: cannot allocate" | ||||
|     #    response=$(curl -X POST -d @${file}.xml $url) -> "curl: option -d: out of memory" | ||||
| 		filetype=video/mp4 | ||||
|     filetype="video/mp4" | ||||
|     echo '<?xml version="1.0"?> | ||||
|     <methodCall><methodName>wp.uploadFile</methodName> | ||||
|     <params> | ||||
|  | @ -377,79 +433,97 @@ do | |||
|     <param><value>'"${wpxmlrpcuser}"'</value></param> | ||||
|     <param><value>'"${wpxmlrpcpass}"'</value></param> | ||||
|     <param><value><struct> | ||||
| 		<member><name>name</name><value><string>'"$(basename ${vidpathsarray[$item]})"'</string></value></member> | ||||
|     <member><name>name</name><value><string>'"$(basename "${vidpathsarray[$item]}")"'</string></value></member> | ||||
|     <member><name>type</name><value><string>'"${filetype}"'</string></value></member> | ||||
| 		<member><name>bits</name><value><base64>' > ${vidpathsarray[$item]}.xml | ||||
| 		base64 --wrap=0 ${vidpathsarray[$item]} >> ${vidpathsarray[$item]}.xml | ||||
|     <member><name>bits</name><value><base64>' > "${vidpathsarray[$item]}.xml" | ||||
|     base64 --wrap=0 "${vidpathsarray[$item]}" >> "${vidpathsarray[$item]}.xml" | ||||
|     echo '</base64></value></member> | ||||
|     </struct></value></param> | ||||
|     </params> | ||||
| 		</methodCall>' >> ${vidpathsarray[$item]}.xml | ||||
| 		curl -X POST -T ${vidpathsarray[$item]}.xml $wpxmlrpclink > ${vidpathsarray[$item]}-response.xml \ | ||||
| 		&& vidlinksarray+=("$(xmllint --xpath '//member[contains(name,"link")]/value/string/text()' ${vidpathsarray[$item]}-response.xml)") \ | ||||
| 		&& vidlinkcodeis=$(curl --output /dev/null --silent --write-out "%{http_code}" ${vidlinksarray[$item]}) \ | ||||
| 		|| execerror "${vidpathsarray[$item]}-response.xml" | ||||
|     </methodCall>' >> "${vidpathsarray[$item]}.xml" | ||||
|     response="${vidpathsarray[$item]}-response.xml" | ||||
|     if curl -X POST -T "${vidpathsarray[$item]}.xml" "${wpxmlrpclink}" > "${response}"; then | ||||
|       vidlinksarray+=("$(xmllint --xpath '//member[contains(name,"link")]/value/string/text()' "${response}")") | ||||
|       vidlinkcodeis=$(curl --output /dev/null --silent --write-out "%{http_code}" "${vidlinksarray[$item]}") | ||||
|     else | ||||
|       execerror "${response}" | ||||
|     fi | ||||
|     if [[ ${vidlinkcodeis} -eq 200 ]]; then | ||||
| 			rm ${vidpathsarray[$item]}.xml | ||||
| 			rm ${vidpathsarray[$item]}-response.xml | ||||
| 			echo "$(date +'%Y.%m.%d-%H:%M:%S') sent ${vidpathsarray[$item]} to ${vidlinksarray[$item]}" | tee -a $logs | ||||
|       rm "${vidpathsarray[$item]}.xml" | ||||
|       rm "${response}" | ||||
|       echo "$(date +'%Y.%m.%d-%H:%M:%S') sent ${vidpathsarray[$item]} to ${vidlinksarray[$item]}" | tee -a "${logs}" | ||||
|       echo -e "WORDPRESS UPLOAD VIDEO RESULT:" | ||||
| 			echo -e "item: $item" | ||||
| 			echo -e "type: $filetype" | ||||
|       echo -e "item: ${item}" | ||||
|       echo -e "type: ${filetype}" | ||||
|       echo -e "name: ${vidnamesarray[$item]}" | ||||
| 			echo -e "base: $(basename ${vidpathsarray[$item]})" | ||||
|       echo -e "base: $(basename "${vidpathsarray[$item]}")" | ||||
|       echo -e "path: ${vidpathsarray[$item]}" | ||||
|       echo -e "link: ${vidlinksarray[$item]}" | ||||
| 			echo -e "code: $vidlinkcodeis" | ||||
|       echo -e "code: ${vidlinkcodeis}" | ||||
|     else | ||||
| 			vidlinksarray[$item]='' | ||||
|       vidlinksarray[item]='' | ||||
|     fi | ||||
|   fi | ||||
| 	### TELEGRAM SEND/UPLOAD VIDEO | ||||
| 	if [ ! "$only" == "--onlywp" ];then | ||||
| 
 | ||||
|   # TELEGRAM SEND/UPLOAD VIDEO | ||||
|   if [ ! "${only}" == "--onlywp" ]; then | ||||
|     videofullpath=${vidpathsarray[$item]} | ||||
| 		vidcompressed=$(echo ${vidpathsarray[$item]} | sed -e 's/.mp4/-compressed.mp4/g') | ||||
| 		if [ -n "$(find "$videofullpath" -prune -size +51380224c)" ];then | ||||
| 			duration=$(ffprobe -i "$videofullpath" -show_entries format=duration -v quiet -of csv="p=0" | cut -d'.' -f 1) \ | ||||
| 			&& ffmpeg -i "$videofullpath" -c:v libx264 -b:v $((49*8*1000/$duration))k -vf "scale=960:540,fps=25,format=yuv420p" -preset veryslow "$vidcompressed" -y -loglevel quiet -stats \ | ||||
| 			&& videofullpath=$vidcompressed \ | ||||
| 			|| execerror "ffmpeg convert ${videofullpath} to ${vidcompressed}" | ||||
|     vidcompressed=${videofullpath//".mp4"/"-compressed.mp4"} | ||||
|     if [ -n "$(find "${videofullpath}" -prune -size +51380224c)" ]; then | ||||
|       duration=$(ffprobe -i "${videofullpath}" \ | ||||
|         -show_entries format=duration -v quiet -of csv="p=0" | cut -d'.' -f 1) | ||||
|       if ffmpeg -i "${videofullpath}" \ | ||||
|         -c:v libx264 -b:v "$((49*8*1000/duration))k" \ | ||||
|         -vf "scale=960:540,fps=25,format=yuv420p" \ | ||||
|         -preset veryslow "${vidcompressed}" -y -loglevel quiet -stats; then | ||||
|         videofullpath=${vidcompressed} | ||||
|       else | ||||
|         execerror "ffmpeg convert ${videofullpath} to ${vidcompressed}" | ||||
|       fi | ||||
| 		response=$(curl -s -F chat_id=$telegramchatid \ | ||||
| 				   -F video=@${videofullpath} \ | ||||
| 				   -F caption="$(echo $(basename ${videofullpath}) | sed -e 's/.mp4//g')" \ | ||||
| 				   $telegramapiurl/sendVideo) \ | ||||
| 		&& curl -s -F chat_id=$telegramchatid \ | ||||
| 			   -F message_id=$(echo $response | jq -r '.result.message_id') \ | ||||
| 			   $telegramapiurl/deleteMessage \ | ||||
| 		&& vidtgidsarray+=("$(echo $response | jq -r '.result.video.file_id')") \ | ||||
| 		&& vidtgcpsarray+=("$(echo $response | jq -r '.result.caption')") \ | ||||
| 		&& echo "$(date +'%Y.%m.%d-%H:%M:%S') sent ${videofullpath} to ${vidtgidsarray[$item]} Telegram file ID" | tee -a $logs \ | ||||
| 		|| execerror "sent ${videofullpath} to $telegramchatid Telegram Chat ID" | ||||
| 		if [ -e $vidcompressed ];then | ||||
| 			rm $vidcompressed | ||||
|     fi | ||||
|     videobasename=$(basename "${videofullpath}") | ||||
|     videobasename=${videobasename//".mp4"/""} | ||||
|     response=$(curl -s \ | ||||
|       -F "chat_id=${telegramchatid}" \ | ||||
|       -F "video=@${videofullpath}" \ | ||||
|       -F "caption=${videobasename}" \ | ||||
|       "${telegramapiurl}/sendVideo") | ||||
|     if curl -s -F "chat_id=${telegramchatid}" \ | ||||
|       -F "message_id=$(echo "${response}" | jq -r '.result.message_id')" \ | ||||
|       "${telegramapiurl}/deleteMessage"; then | ||||
|       vidtgidsarray+=("$(echo "${response}" | jq -r '.result.video.file_id')") | ||||
|       vidtgcpsarray+=("$(echo "${response}" | jq -r '.result.caption')") | ||||
|       addtologs "sent ${videofullpath} to ${vidtgidsarray[$item]} Telegram file ID" | ||||
|     else | ||||
|       execerror "sent ${videofullpath} to ${telegramchatid} Telegram Chat ID" | ||||
|     fi | ||||
|     if [ -e "${vidcompressed}" ]; then | ||||
|       rm "${vidcompressed}" | ||||
|     fi | ||||
|   fi | ||||
| done | ||||
| ### TELEGRAM SEND MEDIAGROUP | ||||
| if [ ! "$only" == "--onlywp" ];then | ||||
| 	response=$(curl -s -F chat_id=$telegramchatid \ | ||||
| 
 | ||||
| # TELEGRAM SEND MEDIAGROUP | ||||
| if [ ! "${only}" == "--onlywp" ]; then | ||||
|   response=$(curl -s -F "chat_id=${telegramchatid}" \ | ||||
|     -F media='[ | ||||
| 			   {"type":"photo","media":"'${tgpreviewlink}'","caption":"period: '${viddate}'\nsource: '${tgpreviewtext}'\nstream: '${youtubelink}'"}, | ||||
| 			   {"type":"video","media":"'${vidtgidsarray[0]}'"}, | ||||
| 			   {"type":"video","media":"'${vidtgidsarray[1]}'"}, | ||||
| 			   {"type":"video","media":"'${vidtgidsarray[2]}'"}, | ||||
| 			   {"type":"video","media":"'${vidtgidsarray[3]}'"}, | ||||
| 			   {"type":"video","media":"'${vidtgidsarray[4]}'"}, | ||||
| 			   {"type":"video","media":"'${vidtgidsarray[5]}'"}]' \ | ||||
|       {"type":"photo","media":"'"${tgpreviewlink}"'", | ||||
|        "caption":"period: '"${viddate}"'\nsource: '"${tgpreviewtext}"'\nstream: '"${youtubelink}"'"}, | ||||
|       {"type":"video","media":"'"${vidtgidsarray[0]}"'"}, | ||||
|       {"type":"video","media":"'"${vidtgidsarray[1]}"'"}, | ||||
|       {"type":"video","media":"'"${vidtgidsarray[2]}"'"}, | ||||
|       {"type":"video","media":"'"${vidtgidsarray[3]}"'"}, | ||||
|       {"type":"video","media":"'"${vidtgidsarray[4]}"'"}, | ||||
|       {"type":"video","media":"'"${vidtgidsarray[5]}"'"}]' \ | ||||
|     -H "Content-Type:multipart/form-data" \ | ||||
| 			   $telegramapiurl/sendMediaGroup) | ||||
|     "${telegramapiurl}/sendMediaGroup") | ||||
| fi | ||||
| ### WORDPRESS UPDATE PAGE | ||||
| if [ ! "$only" == "--onlytg" ];then | ||||
| 
 | ||||
| # WORDPRESS UPDATE PAGE | ||||
| if [ ! "${only}" == "--onlytg" ]; then | ||||
|   setconfig | ||||
|   getconfig | ||||
| 	xml=$(cat ./${wptemplateis}) | ||||
|   xml=$(cat "./${wptemplateis}") | ||||
| 
 | ||||
|   xml=${xml//wpeditpageid/${wpeditpageid}} | ||||
|   xml=${xml//wpxmlrpcuser/${wpxmlrpcuser}} | ||||
|  | @ -514,12 +588,12 @@ if [ ! "$only" == "--onlytg" ];then | |||
|   xml=${xml//wppagelinkis/${wppagelinkis}} | ||||
|   xml=${xml//wpeditdateis/${wpeditdateis}} | ||||
| 
 | ||||
| 	response=$(curl -d "$xml" $wpxmlrpclink) | ||||
| 	if echo "$response" | grep -q '<boolean>1</boolean>';then | ||||
| 		addtologs "update $(echo "$xml" | grep 'Link' | cut -d'>' -f 6 | cut -d'<' -f 1))" | ||||
|   response=$(curl -d "${xml}" "${wpxmlrpclink}") | ||||
|   if echo "${response}" | grep -q '<boolean>1</boolean>'; then | ||||
|     addtologs "update $(grep 'Link' "${xml}" | cut -d'>' -f 6 | cut -d'<' -f 1))" | ||||
|   else | ||||
| 		echo $response | xmllint --format - > $pathroot/wp-page${wpeditpageid}-response.xml 2>/dev/null | ||||
| 		execerror "$pathroot/wp-page${wpeditpageid}-response.xml" | ||||
|     echo "${response}" | xmllint --format - > "${pathroot}/wp-page${wpeditpageid}-response.xml" 2>/dev/null | ||||
|     execerror "${pathroot}/wp-page${wpeditpageid}-response.xml" | ||||
|   fi | ||||
| fi | ||||
| execquite | ||||
|  | @ -9,6 +9,7 @@ ftpuser=user | |||
| ftppass=pass | ||||
| ftpaddr=192.168.254.254 | ||||
| ftpport=21 | ||||
| ftppath=Records/cam.test.local | ||||
| 
 | ||||
| tmpuser=user | ||||
| tmppass=pass | ||||
|  |  | |||
							
								
								
									
										291
									
								
								sequences.sh
									
									
									
									
									
								
							
							
						
						
									
										291
									
								
								sequences.sh
									
									
									
									
									
								
							|  | @ -1,137 +1,291 @@ | |||
| #! /bin/bash | ||||
| 
 | ||||
| # | ||||
| ## DESCRIPTION: | ||||
| #    Hikvision PTZ-camera sequences. | ||||
| # DESCRIPTION: | ||||
| #   Handling Hikvision PTZ-cameras sequences. | ||||
| #   Additionally: | ||||
| #    - getting temperature from ds-18b20 over SSH, | ||||
| #   - get ds18b20 sensor value over SSH, | ||||
| #   - saving pictures to FTP. | ||||
| #   This is only a local "proof of conept" for testing and debugging. | ||||
| # | ||||
| 
 | ||||
| # DEPENDENCIES: | ||||
| #   - curl | ||||
| #   - sshpass | ||||
| # | ||||
| ## DEPENDENCIES: sudo apt|yum install -y curl sshpass | ||||
| # | ||||
| 
 | ||||
| # | ||||
| ## FUNCTIONS | ||||
| # PARAMETERS: | ||||
| #   1: "qn" - execution without pauses | ||||
| #   2: custom configuration file path | ||||
| # | ||||
| # FUNCTIONS: | ||||
| # | ||||
| 
 | ||||
| ####################################### | ||||
| # Print message and add to log. | ||||
| # Globals: | ||||
| #   logs | ||||
| # Arguments: | ||||
| #   1: message to print and logging | ||||
| ####################################### | ||||
| addtologs() { | ||||
| 	echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs | ||||
|   echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a "${logs}" | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Waiting for press [ENTER]. | ||||
| # Globals: | ||||
| #   None | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| execpause() { | ||||
| 	read -p "Press [ENTER] to continue... " | ||||
|   read -r -p "Press [ENTER] to continue... " | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Exit procedure. | ||||
| # Globals: | ||||
| #   show | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| execquite() { | ||||
| 	addtologs "execution time is $(($(date +%s)-$time)) seconds, exit" | ||||
|   addtologs "execution time is $(($(date +%s)-time)) seconds, exit" | ||||
|   if [ "${show}" != "qn" ]; then | ||||
|     execpause | ||||
|   fi | ||||
|   exit | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Error exit procedure with Telegram notification. | ||||
| # Globals: | ||||
| #   telegramapiurl | ||||
| #   telegramchatid | ||||
| # Arguments: | ||||
| #   1: message to print and logging | ||||
| ####################################### | ||||
| execerror() { | ||||
|   addtologs "error: $1" | ||||
| 	curl -s -X POST $telegramapiurl/sendMessage -d chat_id=$telegramchatid -d text="$(basename -s .sh $0) error: $1" >> /dev/null 2>&1 | ||||
|   curl -s -X POST "${telegramapiurl}/sendMessage" \ | ||||
|     -d "chat_id=${telegramchatid}" \ | ||||
|     -d "text=$(basename -s .sh "$0") error: $1" \ | ||||
|     >> /dev/null 2>&1 | ||||
|   execquite | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Parsing config file and creating global vars. | ||||
| # Globals: | ||||
| #   None | ||||
| # Arguments: | ||||
| #   None | ||||
| ####################################### | ||||
| getconfig() { | ||||
| 	logs=$(cat $conf | grep "logs=" | cut -d= -f2) | ||||
| 	camuser=$(cat $conf | grep "camuser=" | cut -d= -f2) | ||||
| 	campass=$(cat $conf | grep "campass=" | cut -d= -f2) | ||||
| 	camaddr=$(cat $conf | grep "camaddr=" | cut -d= -f2) | ||||
| 	camport=$(cat $conf | grep "camport=" | cut -d= -f2) | ||||
| 	ftpuser=$(cat $conf | grep "ftpuser=" | cut -d= -f2) | ||||
| 	ftppass=$(cat $conf | grep "ftppass=" | cut -d= -f2) | ||||
| 	ftpaddr=$(cat $conf | grep "ftpaddr=" | cut -d= -f2) | ||||
| 	ftpport=$(cat $conf | grep "ftpport=" | cut -d= -f2) | ||||
| 	tmpuser=$(cat $conf | grep "tmpuser=" | cut -d= -f2) | ||||
| 	tmppass=$(cat $conf | grep "tmppass=" | cut -d= -f2) | ||||
| 	tmpaddr=$(cat $conf | grep "tmpaddr=" | cut -d= -f2) | ||||
| 	tmpport=$(cat $conf | grep "tmpport=" | cut -d= -f2) | ||||
| 	tmpnode=$(cat $conf | grep "tmpnode=" | cut -d= -f2) | ||||
| 	telegramapiurl=$(cat $conf | grep "telegramapiurl=" | cut -d= -f2) | ||||
| 	telegramchatid=$(cat $conf | grep "telegramchatid=" | cut -d= -f2) | ||||
|   logs=$(grep "logs=" "${conf}" | cut -d= -f2) | ||||
|   camuser=$(grep "camuser=" "${conf}" | cut -d= -f2) | ||||
|   campass=$(grep "campass=" "${conf}" | cut -d= -f2) | ||||
|   camaddr=$(grep "camaddr=" "${conf}" | cut -d= -f2) | ||||
|   camport=$(grep "camport=" "${conf}" | cut -d= -f2) | ||||
|   ftpuser=$(grep "ftpuser=" "${conf}" | cut -d= -f2) | ||||
|   ftppass=$(grep "ftppass=" "${conf}" | cut -d= -f2) | ||||
|   ftpaddr=$(grep "ftpaddr=" "${conf}" | cut -d= -f2) | ||||
|   ftpport=$(grep "ftpport=" "${conf}" | cut -d= -f2) | ||||
|   ftppath=$(grep "ftppath=" "${conf}" | cut -d= -f2) | ||||
|   tmpuser=$(grep "tmpuser=" "${conf}" | cut -d= -f2) | ||||
|   tmppass=$(grep "tmppass=" "${conf}" | cut -d= -f2) | ||||
|   tmpaddr=$(grep "tmpaddr=" "${conf}" | cut -d= -f2) | ||||
|   tmpport=$(grep "tmpport=" "${conf}" | cut -d= -f2) | ||||
|   tmpnode=$(grep "tmpnode=" "${conf}" | cut -d= -f2) | ||||
|   telegramapiurl=$(grep "telegramapiurl=" "${conf}" | cut -d= -f2) | ||||
|   telegramchatid=$(grep "telegramchatid=" "${conf}" | cut -d= -f2) | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Get ds18b20 sensor value over SSH. | ||||
| # Globals: | ||||
| #   tmpaddr | ||||
| #   tmpport | ||||
| #   tmpuser | ||||
| #   tmppass | ||||
| #   tmpnode | ||||
| # Arguments: | ||||
| #   None | ||||
| # return: | ||||
| #   temperature in Celsius | ||||
| ####################################### | ||||
| getairtmp() { | ||||
| 	local temp=$( \ | ||||
|     sshpass -p $tmppass ssh $tmpuser@$tmpaddr -p $tmpport -o StrictHostKeyChecking=no -o ConnectTimeout=10 \ | ||||
|     "cat /sys/bus/w1/devices/$tmpnode/temperature" \ | ||||
|     ) && temp=$(($temp / 1000)) | ||||
|     if [ ! -z "${temp}" ]; then | ||||
| 		addtologs "air temperature now is $temp'C" > /dev/null | ||||
|         echo $temp | ||||
|   temp=$(sshpass -p "${tmppass}" \ | ||||
|     ssh "${tmpuser}@${tmpaddr}" -p "${tmpport}" \ | ||||
|     -o StrictHostKeyChecking=no -o ConnectTimeout=10 \ | ||||
|     "cat /sys/bus/w1/devices/${tmpnode}/temperature" \ | ||||
|   ) && temp=$((temp / 1000)) | ||||
|   if [ -n "${temp}" ]; then | ||||
|     addtologs "getairtmp: air temperature now is ${temp}'C" > /dev/null | ||||
|     echo "${temp}" | ||||
|   else | ||||
| 		execerror "air temperature now is $temp'C" | ||||
|     execerror "getairtmp: air temperature now is ${temp}'C" | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Get static picture from camera and upload to FTP. | ||||
| # Globals: | ||||
| #   camaddr | ||||
| #   camport | ||||
| #   camuser | ||||
| #   campass | ||||
| #   ftpaddr | ||||
| #   ftpport | ||||
| #   ftppath | ||||
| #   ftpuser | ||||
| #   ftppass | ||||
| # Arguments: | ||||
| #   1: filename prefix | ||||
| ####################################### | ||||
| getcamimg() { | ||||
|     local name=$1 | ||||
| 	local file="$ftpaddr:$ftpport/Records/cam-street.home.local/$(date +"%Y")/$(date +"%m")/$(date +"%V")/$(date +"%d")/${name}_$(date +"%Y.%m.%d_%H-%M-%S").jpeg" | ||||
|     url='/Streaming/channels/101/picture?snapShotImageType=JPEG&videoResolutionWidth=1920&videoResolutionHeight=1080' | ||||
|     curl -vs "http://$camuser:$campass@$camaddr:$camport/$url" -o tmp \ | ||||
|     && curl -T tmp "ftp://$ftpuser:$ftppass@$file" --ftp-create-dirs \ | ||||
|     && rm tmp && addtologs "save photo to ftp://$file" || execerror "save photo to ftp://$file" | ||||
|   local name | ||||
|   name=$1 | ||||
|   path="${ftppath}/$(date +"%Y")/$(date +"%m")/$(date +"%V")/$(date +"%d")" | ||||
|   file="${ftpaddr}:${ftpport}/${path}/${name}_$(date +"%Y.%m.%d_%H-%M-%S").jpeg" | ||||
|   url='Streaming/channels/101/picture?snapShotImageType=JPEG&videoResolutionWidth=1920&videoResolutionHeight=1080' | ||||
|   if curl -vs "http://$camuser:$campass@$camaddr:$camport/$url" -o tmp \ | ||||
|     && curl -T tmp "ftp://$ftpuser:$ftppass@$file" --ftp-create-dirs; then | ||||
|     addtologs "getcamimg: save photo to ftp://${file}" | ||||
|     rm tmp | ||||
|   else | ||||
|     execerror "getcamimg: save photo to ftp://${file}" | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Set message as video overlay text. | ||||
| # Globals: | ||||
| #   camaddr | ||||
| #   camport | ||||
| #   camuser | ||||
| #   campass | ||||
| # Arguments: | ||||
| #   1: overlay text content | ||||
| ####################################### | ||||
| setcamtxt() { | ||||
|   local message=$1 | ||||
|     url='/Video/inputs/channels/101/overlays/text' | ||||
|     xml='<TextOverlayList><TextOverlay><id>1</id><enabled>true</enabled><posX>0</posX><posY>0</posY><message>'"${message}"'</message></TextOverlay></TextOverlayList>' | ||||
|     curl -d "$xml" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" && addtologs "text on video is $message" && sleep 5 || execerror "text on video is $message" | ||||
|   url='ISAPI/System/Video/inputs/channels/101/overlays/text' | ||||
|   xml='<TextOverlayList> | ||||
|        <TextOverlay> | ||||
|        <id>1</id> | ||||
|        <enabled>true</enabled> | ||||
|        <posX>0</posX><posY>0</posY> | ||||
|        <displayText>'"${message}"'</displayText> | ||||
|        </TextOverlay> | ||||
|      </TextOverlayList>' | ||||
|   if curl -d "${xml}" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" \ | ||||
|     | grep -q '<statusString>OK</statusString>'; then | ||||
|     addtologs "setcamtxt: ${message}" | ||||
|     sleep 5 | ||||
|   else | ||||
|     execerror "setcamtxt: ${message}" | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Set camera moving to absolute position. | ||||
| # Globals: | ||||
| #   camaddr | ||||
| #   camport | ||||
| #   camuser | ||||
| #   campass | ||||
| # Arguments: | ||||
| #   1: horisontal camera position from 0 to 3600 | ||||
| #   2: vertical camera position from -900 to 2700 | ||||
| #   3: zoom camera position from 0 to 1000 | ||||
| #   4: time to wait | ||||
| #   5: message to print and logging | ||||
| ####################################### | ||||
| setcampos() { | ||||
|   local x=$1 | ||||
|   local y=$2 | ||||
|   local z=$3 | ||||
|   local t=$4 | ||||
|   local message=$5 | ||||
|     url='/ISAPI/PTZCtrl/channels/101/absolute' | ||||
|     xml='<PTZData><AbsoluteHigh><elevation>'"${y}"'</elevation><azimuth>'"${x}"'</azimuth><absoluteZoom>'"${z}"'</absoluteZoom></AbsoluteHigh></PTZData>' | ||||
|     curl -d "$xml" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" && addtologs "$message" && sleep $t || execerror "$message" | ||||
|   url='ISAPI/PTZCtrl/channels/101/absolute' | ||||
|   xml='<PTZData> | ||||
|        <AbsoluteHigh> | ||||
|        <elevation>'"${y}"'</elevation> | ||||
|        <azimuth>'"${x}"'</azimuth> | ||||
|        <absoluteZoom>'"${z}"'</absoluteZoom> | ||||
|        </AbsoluteHigh> | ||||
|      </PTZData>' | ||||
|   if curl -d "${xml}" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" \ | ||||
|     | grep -q '<statusString>OK</statusString>'; then | ||||
|     addtologs "setcampos: ${message}" | ||||
|     sleep "${t}" | ||||
|   else | ||||
|     execerror "setcampos: ${message}" | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| ####################################### | ||||
| # Set camera moving to direction. | ||||
| # Globals: | ||||
| #   camaddr | ||||
| #   camport | ||||
| #   camuser | ||||
| #   campass | ||||
| # Arguments: | ||||
| #   1: acceleration of horizontal camera movement from -100 to 100 | ||||
| #   2: acceleration of vertical camera movement from -100 to 100 | ||||
| #   3: acceleration of zoom camera movement from -100 to 100 | ||||
| #   4: time to wait | ||||
| #   5: message to print and logging | ||||
| ####################################### | ||||
| setcammov() { | ||||
|   local x=$1 | ||||
|   local y=$2 | ||||
|   local z=$3 | ||||
|   local t=$4 | ||||
|   local message=$5 | ||||
|     url='/ISAPI/PTZCtrl/channels/101/continuous' | ||||
|     xml='<PTZData><pan>'"${x}"'</pan><tilt>'"${y}"'</tilt><zoom>'"${z}"'</zoom></PTZData>' | ||||
|     curl -d "$xml" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" && addtologs "$message" && sleep $t || execerror "$message" | ||||
|   url='ISAPI/PTZCtrl/channels/101/continuous' | ||||
|   xml='<PTZData> | ||||
|        <pan>'"${x}"'</pan> | ||||
|        <tilt>'"${y}"'</tilt> | ||||
|        <zoom>'"${z}"'</zoom> | ||||
|      </PTZData>' | ||||
|   if curl -d "${xml}" -X PUT "http://$camuser:$campass@$camaddr:$camport/$url" \ | ||||
|     | grep -q '<statusString>OK</statusString>'; then | ||||
|     addtologs "setcammov: ${message}" | ||||
|     sleep "${t}" | ||||
|   else | ||||
|     execerror "setcammov: ${message}" | ||||
|   fi | ||||
| } | ||||
| 
 | ||||
| # | ||||
| ## PARAMETERS | ||||
| ## VARIABLES: | ||||
| # | ||||
| 
 | ||||
| show=${1} | ||||
| conf=${2} | ||||
| show=$1 | ||||
| conf=$2 | ||||
| if [ -z "${conf}" ] || [ "${conf}" == "-" ]; then | ||||
| 	conf="$(dirname $(realpath "$0"))/$(basename -s .sh $0).conf" | ||||
|   conf="$(dirname "$(realpath "$0")")/$(basename -s .sh "$0").conf" | ||||
| fi | ||||
| 
 | ||||
| # | ||||
| ## VARIABLES | ||||
| # | ||||
| 
 | ||||
| time=$(date +%s) | ||||
| cd "$(dirname "$(realpath "$0")")" | ||||
| if [ ! -e ${conf} ];then | ||||
| cd "$(dirname "$(realpath "$0")")" || execerror | ||||
| if [ ! -e "${conf}" ]; then | ||||
|   execerror "Not found config file: ${conf}" | ||||
| else | ||||
|   getconfig | ||||
| fi | ||||
| if [ -z "${logs}" ];then | ||||
|   logs=/dev/null | ||||
| elif [ ! -e ${logs} ];then | ||||
| 	touch ${logs} | ||||
| elif [ ! -e "${logs}" ];then | ||||
|   touch "${logs}" | ||||
| fi | ||||
| if ! command -v curl &> /dev/null || ! command -v sshpass &> /dev/null; then | ||||
|   execerror "Not found dependencies" | ||||
| fi | ||||
| 
 | ||||
| # | ||||
| ## RUN | ||||
| # MAIN: | ||||
| # | ||||
| 
 | ||||
| setcamtxt "$(getairtmp)'C" | ||||
|  | @ -162,12 +316,13 @@ sleep                                   4m | |||
| setcammov       0       -44     33      1.50s     '08 >> 09 Точка - Стадион 8x' | ||||
| setcampos       2860    -170    80      5.00s     '08 >| 09 Точка - Стадион 8x' | ||||
| sleep                                   1m | ||||
| setcammov       0       -99     0       7.50s     '09 >> 10 Точка - Въезд во двор 8x' | ||||
| setcampos       2805    200     80      5.00s     '09 >| 10 Точка - Въезд во двор 8x' | ||||
| sleep                                   5m | ||||
| setcammov       -88     99      0       5.00s     '10 >> 11 Точка - Бассейн 8x' | ||||
| setcammov       -99     88      0       2.00s     '10 >> 11 Точка - Бассейн 8x' | ||||
| setcammov       -44     99      0       4.25s     '10 >> 11 Точка - Бассейн 8x' | ||||
| setcampos       2510    -100    80      5.00s     '10 >| 11 Точка - Бассейн 8x' | ||||
| setcampos       2510    -20     80      5.00s     '10 >| 11 Точка - Бассейн 8x' | ||||
| sleep                                   1m | ||||
| setcammov       -88     99      33      2.50s     '11 >> 12 Точка - Общежитие дальнее 16x' | ||||
| setcampos       2415    -200    160     5.00s     '11 >| 12 Точка - Общежитие дальнее 16x' | ||||
|  | @ -176,7 +331,7 @@ setcammov       66      0       0       22.5s     '12 >> 13 Точка - Общ | |||
| setcampos       2640    -200    160     5.00s     '12 >| 13 Точка - Общежите ближнее 16x' | ||||
| sleep                                   1m | ||||
| setcammov       66      0       0       90.5s     '13 >> 14 Точка - Крыша магазина 4x' | ||||
| setcammov       99      0       -33     3.25s     '13 >> 14 Точка - Крыша магазина 4x' | ||||
| setcammov       99      0       -44     3.25s     '13 >> 14 Точка - Крыша магазина 4x' | ||||
| setcampos       335     -200    40      5.00s     '13 >| 14 Точка - Крыша магазина 4x' | ||||
| sleep                                   1m | ||||
| setcamtxt '' && getcamimg 'point-11' && setcamtxt "$(getairtmp)'C" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user