publisher.sh absorbed cctv-scheduler.py

This commit is contained in:
Pavel Muhortov 2023-06-24 21:54:31 +03:00
parent d793e47e6c
commit 7a12aed45b
11 changed files with 4406 additions and 570 deletions

29
.vscode/launch.json vendored
View File

@ -39,7 +39,34 @@
"args": [
"-c",
"-w",
"-1"
"-3"
],
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Python: cctv-scheduler -p -w -3",
"type": "python",
"request": "launch",
"program": "${file}",
"args": [
"-p",
"-w",
"-3"
],
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Python: cctv-scheduler -w -3 -c -p",
"type": "python",
"request": "launch",
"program": "${file}",
"args": [
"-d",
"-1",
"-c",
"-p"
],
"console": "integratedTerminal",
"justMyCode": true

View File

@ -4,11 +4,10 @@ PTZ IP-Camera management
____
- [`cctv-scheduler.py`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#cctv-scheduler-py)
- [`publisher.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#publisher-sh)
____
![cctv-scheduler](info/images/cctv-scheduler-0.4.png)
![cctv-scheduler](info/images/cctv-scheduler-0.5.png)
## `Installation`
@ -30,9 +29,6 @@ Download scripts and configs.
```bash
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/cctv-scheduler.py -O /home/user/cctv-scheduler/cctv-scheduler.py
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/cctv-scheduler.conf -O /home/user/cctv-scheduler/cctv-scheduler.conf
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher.sh -O /home/user/cctv-scheduler/publisher.sh
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher.conf -O /home/user/cctv-scheduler/publisher.conf
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
```
### `Configuration`
@ -41,7 +37,6 @@ Edit configs.
```bash
nano /home/user/cctv-scheduler/cctv-scheduler.conf
nano /home/user/cctv-scheduler/publisher.conf
```
### `Scheduler`
@ -61,6 +56,7 @@ crontab -e
> - getting temperature from DS18B20 over SSH,
> - saving pictures to FTP.
> - converting picture collection to video.
> - publishing video to Telegram chat and Wordpress site.
>
> This is only a local "proof of concept" for testing and debugging.
@ -98,6 +94,7 @@ crontab -e
|**[-s, --sequences]**|run sequences from config file|`None`|
|**[--config]**|custom configuration file path|`./cctv-scheduler.conf`|
|**[-c, --converter]**|convert JPEG collection to MP4|`None`|
|**[-p, --publisher]**|publish content from templates|`None`|
|**[-d, --day]**|day in amount of days from today, for which the publication or conversion is made|`0`|
|**[-w, --week]**|week in amount of weeks from today, for which the publication or conversion is made|`0`|
|**[-m, --month]**|month in amount of months from today, for which the publication or conversion is made|`0`|
@ -116,54 +113,8 @@ Example usage with cron:
# crontab -e
* * * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -b
0 * * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -s
1 0 * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -d -1
7 0 * * 1 /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -w -1
30 0 1 * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -m -1
36 0 1 1 * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -y -1
```
____
## `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/))
> - [libxml2-utils](https://gitlab.gnome.org/GNOME/libxml2) (tested version 2.9.10 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
> - [jq](https://stedolan.github.io/jq/download/) (tested version 1.6 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| `./publisher.conf` |
| 3 | **[-d\|-w\|-m\|-y]** |periods: '' - 0 day \| '-d' - -X day \| '-w' - -X week \| '-m' - -X month \| '-y' - -X year|`''`|
| 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:
```bash
bash ./publisher.sh - ./publisher.conf - - - - --onlytg
```
Example usage with cron:
```bash
# crontab -e
1 1 * * * bash /home/user/cctv-scheduler/publisher.sh qn - -d
7 1 * * 1 bash /home/user/cctv-scheduler/publisher.sh qn - -w
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
1 0 * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -d -1 -c -p
7 0 * * 1 /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -w -1 -c -p
30 0 1 * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -m -1 -c -p
36 0 1 1 * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -y -1 -c -p
```

169
archive/0.4/README.md Normal file
View File

@ -0,0 +1,169 @@
# cctv-scheduler
PTZ IP-Camera management
____
- [`cctv-scheduler.py`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#cctv-scheduler-py)
- [`publisher.sh`](https://git.hmp.today/pavel.muhortov/cctv-scheduler#publisher-sh)
____
![cctv-scheduler](info/images/cctv-scheduler-0.4.png)
## `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/cctv-scheduler.py -O /home/user/cctv-scheduler/cctv-scheduler.py
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/cctv-scheduler.conf -O /home/user/cctv-scheduler/cctv-scheduler.conf
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher.sh -O /home/user/cctv-scheduler/publisher.sh
wget https://git.hmp.today/pavel.muhortov/cctv-scheduler/raw/branch/master/publisher.conf -O /home/user/cctv-scheduler/publisher.conf
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
```
### `Configuration`
Edit configs.
```bash
nano /home/user/cctv-scheduler/cctv-scheduler.conf
nano /home/user/cctv-scheduler/publisher.conf
```
### `Scheduler`
Look at examples and edit scheduler tasks:
```bash
crontab -e
```
## `cctv-scheduler`.py
**Description:**
> [Hikvision](https://git.hmp.today/pavel.muhortov/cctv-scheduler/src/branch/master/info/hikvision/manual/isapi.pdf) PTZ IP-Camera management. Media streaming. Images to video converting.
> Additionally:
>
> - getting temperature from DS18B20 over SSH,
> - saving pictures to FTP.
> - converting picture collection to video.
>
> This is only a local "proof of concept" for testing and debugging.
**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/))
> - [paramiko](https://www.paramiko.org/) Python 3 module (tested version 3.1.0)
> - [ffmpeg](https://ffmpeg.org) (tested version 4.3.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
> - specified record pictures filesystem organization
>
>```bash
> # record pictures filesystem organization example
>/root/
> /2022/
> /12/
> /52/
> /31/
> /image-01_2022.12.31_time.jpeg
> /image-02_2022.12.31_time.jpeg
> /2023/
> /01/
> /01/
> /02/
> /image-01_2023.01.02_time.jpeg
> /image-02_2023.01.02_time.jpeg
> /03/
> /image-01_2023.01.03_time.jpeg
> /image-02_2023.01.03_time.jpeg
>```
| PARAMETERS | DESCRIPTION | DEFAULT|
|-------------|-------------|--------|
|**[-h]**|print help and exit||
|**[-b, --broadcast]**|streaming media to destination|`None`|
|**[-s, --sequences]**|run sequences from config file|`None`|
|**[--config]**|custom configuration file path|`./cctv-scheduler.conf`|
|**[-c, --converter]**|convert JPEG collection to MP4|`None`|
|**[-d, --day]**|day in amount of days from today, for which the publication or conversion is made|`0`|
|**[-w, --week]**|week in amount of weeks from today, for which the publication or conversion is made|`0`|
|**[-m, --month]**|month in amount of months from today, for which the publication or conversion is made|`0`|
|**[-y, --year]**|year in amount of years from today, for which the publication or conversion is made|`0`|
Example usage in terminal with make the script executable:
```bash
chmod u+x ./cctv-scheduler.py
./cctv-scheduler.py -s --config /home/user/cctv-scheduler/cctv-scheduler.conf
```
Example usage with cron:
```bash
# crontab -e
* * * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -b
0 * * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -s
1 0 * * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -d -1
7 0 * * 1 /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -w -1
30 0 1 * * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -m -1
36 0 1 1 * /usr/bin/python3 /home/user/cctv-scheduler/cctv-scheduler.py -c -y -1
```
____
## `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/))
> - [libxml2-utils](https://gitlab.gnome.org/GNOME/libxml2) (tested version 2.9.10 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
> - [jq](https://stedolan.github.io/jq/download/) (tested version 1.6 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| `./publisher.conf` |
| 3 | **[-d\|-w\|-m\|-y]** |periods: '' - 0 day \| '-d' - -X day \| '-w' - -X week \| '-m' - -X month \| '-y' - -X year|`''`|
| 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:
```bash
bash ./publisher.sh - ./publisher.conf - - - - --onlytg
```
Example usage with cron:
```bash
# crontab -e
1 1 * * * bash /home/user/cctv-scheduler/publisher.sh qn - -d
7 1 * * 1 bash /home/user/cctv-scheduler/publisher.sh qn - -w
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
```

View File

@ -0,0 +1,136 @@
[common]
# By default, a temporary files directory is created in the same path where the script is located.
# If you need change it, uncomment the parameter and set the path you want.
#temp_path = /tmp/cctv-scheduler
#
# By default, logs use the same directory where the script is located.
# If you need change it, uncomment the parameter and set the path you want.
#log_root = /var/log/cctv-scheduler
#
# The default log level is "INFO".
# If you get errors or want to change the logging level, uncomment the parameter and set the level you want:
# DEBUG, INFO, WARNING, ERROR, CRITICAL.
#log_level = DEBUG
[enable-broadcast]
# List the broadcast block names. Only blocks with the TRUE value will be used.
camera.test.local = true
[enable-sequences]
# List the sequence/camera block names. Only blocks with the TRUE value will be used.
camera.test.local = true
[enable-sensors]
# List the sensor block names. Only blocks with the TRUE value will be used.
sensor.test.local = true
[enable-convert]
# List the convert block names. Only blocks with the TRUE value will be used.
camera.test.local = true
[broadcast-config:camera.test.local]
# Broadcast parameter description block always starts with "broadcast-config:".
src = rtsp://user:pass@192.168.254.253:554/Streaming/Channels/101,http://radio.fm:8000/stream.mp3
dst = rtp://239.0.0.1:5554
# Optionality you can change video stream framerate.
#fps = 25
#
# Optionality you can set YouTube recommended preset:
# 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p.
#preset = 1080p
#
# By default ffmpeg expected in /usr/bin/ffmpeg or C:\Program Files\ffmpeg\bin\ffmpeg.exe.
# If you need change it, uncomment the parameter and set the path you want.
#ffpath = /usr/bin/ffmpeg
#
# If you get program freezes because your network unstable, uncomment the parameter.
#watchdog = true
#
# By default, watchdog waits 5 seconds before terminating the program.
# If you need change it, uncomment the parameter and set the path you want.
#watchsec = 15
#
# If you use crontab or other scheduler to run, uncomment the parameter to prevent process overlap.
#onlyonce = true
[sensor-config:sensor.test.local]
# Remote host's sensor parameter description block always starts with "sensor-config:".
hostname = 192.168.254.252
username = user
userpass = pass
# To recognize options for polling a sensor, you must specify the type of sensor.
# Supported types:
# ds18b20
nodetype = ds18b20
nodename = 28-1a2b3c4d5e6f
[camera-config:camera.test.local]
# Camera parameter description block always starts with "camera-config:".
hostname = 192.168.254.253
username = user
userpass = pass
# If a record directory on a remote host is used, a username and password must be specified.
# Supported protocols:
# FTP, SFTP.
records_root_path = ftp://192.168.254.254/Records/camera.test.local
records_root_user = user
records_root_pass = pass
[camera-sequences:camera.test.local]
# Camera sequence description block always starts with "camera-sequences:".
# Place only the sequence of PTZ-actions in this block!
# Variable name can be anything. Only 'downloadjpeg' is using this for filename prefix.
# Available actions:
# setcamerapos, setcameramov, settextonosd, downloadjpeg, capabilities, getcamerapos,
# setptzmovyyu, setptzmovyyd, setptzmovxxl, setptzmovxxr, setptzmovzzi, setptzmovzzo,
# setptzpreset, setptztostop, setmovtohome, setposashome, rebootcamera.
#
# Format (spaces are used for readability only):
# name = action, x, y, zoom, preset, speed, d(ms), w(s), text, notes or anything
step001 = capabilities, -, -, -, -, -, -, 3, ,
step002 = getcamerapos, -, -, -, -, -, -, 3, ,
step011 = setmovtohome, -, -, -, -, -, -, 15, ,
step021 = setptzmovyyd, -, -, -, -, 2, -, 5, , 'speed: 1..7'
step022 = setptzmovyyu, -, -, -, -, 4, -, 3, , 'speed: 1..7'
step023 = setptzmovxxl, -, -, -, -, 4, -, 3, , 'speed: 1..7'
step024 = setptzmovxxr, -, -, -, -, 2, -, 5, , 'speed: 1..7'
step025 = setptzmovzzi, -, -, -, -, 7, -, 3, , 'speed: 1..7'
step026 = setptzmovzzo, -, -, -, -, 7, -, 3, , 'speed: 1..7'
step027 = setptztostop, -, -, -, -, -, -, 3, ,
step031 = setptzpreset, -, -, -, 2, 1, -, 15, , 'speed: 1..7'
step041 = setcameramov, 33, 33, 66, -, -, -, 5, , 'x: -100..100, y: -100..100, z: -100..100, duration: 0..180000'
step042 = setcameramov, -66, -66, -99, -, -, 5000, 0, , 'x: -100..100, y: -100..100, z: -100..100, duration: 0..180000'
step043 = setcamerapos, 0, 0, 0, -, -, -, 15, , 'x: 0..3600, y: -900..2700, z: 0..1000'
step051 = setposashome, -, -, -, -, -, -, 3.5, ,
step061 = settextonosd, 0, 0, -, -, -, -, 3, hello, 'x|y: osd text position, text: text for osd without quotes or commas'
step062 = settextonosd, 0, 0, -, -, -, -, 3, sensor-config:sensor.test.local, 'if a sensor configuration is specified, the sensor value is used instead of text'
step063 = settextonosd, 0, 0, -, -, -, -, 3, , 'an empty text value is used to clear the osd'
step071 = downloadjpeg, 1920, 1080, -, -, -, -, 5, , 'name: filename prefix, x|y: camera width|height resolution'
step999 = rebootcamera, -, -, -, -, -, -, 120, ,
[convert-config:camera.test.local]
# Converter parameter description block always starts with "convert-config:".
image_find_names = step071, image-01, image-02
# If a image root or destination video directories on a remote host is used, a username and password must be specified.
# Supported protocols:
# FTP.
image_root_path = ftp://192.168.254.254/Records/camera.test.local
image_root_user = user
image_root_pass = pass
video_dest_path = ftp://192.168.254.254/Downloads
video_dest_user = user
video_dest_pass = pass
video_scale_x = 1920
video_scale_y = 1080
video_framerate = 25

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ camera.test.local = true
[enable-sequences]
# List the sequence/camera block names. Only blocks with the TRUE value will be used.
# List the sequence camera block names. Only blocks with the TRUE value will be used.
camera.test.local = true
@ -33,6 +33,11 @@ sensor.test.local = true
camera.test.local = true
[enable-publish]
# List the publish block names. Only blocks with the TRUE value will be used.
camera.test.local = true
[broadcast-config:camera.test.local]
# Broadcast parameter description block always starts with "broadcast-config:".
src = rtsp://user:pass@192.168.254.253:554/Streaming/Channels/101,http://radio.fm:8000/stream.mp3
@ -78,7 +83,7 @@ username = user
userpass = pass
# If a record directory on a remote host is used, a username and password must be specified.
# Supported protocols:
# FTP, SFTP.
# FTP.
records_root_path = ftp://192.168.254.254/Records/camera.test.local
records_root_user = user
records_root_pass = pass
@ -119,8 +124,9 @@ step999 = rebootcamera, -, -, -, -, -, -,
[convert-config:camera.test.local]
# Converter parameter description block always starts with "convert-config:".
#
image_find_names = step071, image-01, image-02
# If a image root or destination video directories on a remote host is used, a username and password must be specified.
# If image root or destination video directories on a remote host is used, username and password must be specified.
# Supported protocols:
# FTP.
image_root_path = ftp://192.168.254.254/Records/camera.test.local
@ -133,4 +139,25 @@ video_dest_pass = pass
video_scale_x = 1920
video_scale_y = 1080
video_framerate = 25
video_framerate = 25
[publish-config:camera.test.local]
# Publisher parameter description block always starts with "publish-config:".
video_find_names = step071, image-01, image-02
# If a video directory on a remote host is used, a username and password must be specified.
# Supported protocols:
# FTP.
video_root_path = ftp://192.168.254.254/Downloads
video_root_user = user
video_root_pass = pass
wp_enabled = true
wp_site_name = www.site.name
wp_user_name = user
wp_user_pass = pass
wp_update_page_id = 4848
tg_enabled = true
tg_api_key = TELEGRAM_API_KEY
tg_chat_id = @blackhole

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 KiB