2021-06-14 08:52:58 +03:00
# utils
2021-06-14 08:50:35 +03:00
2021-06-20 15:56:25 +03:00
* [ffmpeger.py ](https://git.hmp.today/pavel.muhortov/utils#ffmpeger-py )
2021-06-21 00:05:04 +03:00
* [procutil.py ](https://git.hmp.today/pavel.muhortov/utils#procutil-py )
2021-06-15 15:36:16 +03:00
* [sendmail.py ](https://git.hmp.today/pavel.muhortov/utils#sendmail-py )
2021-06-15 15:34:01 +03:00
____
2021-06-20 15:56:25 +03:00
## ffmpeger.py
**Description:** FFmpeg management from Python
2021-06-21 00:05:04 +03:00
**Dependencies:** Python 3 (tested version 3.9.5), installed or downloaded ffmpeg, [procutil.py ](https://git.hmp.today/pavel.muhortov/utils#procutil-py ) in the same directory
2021-06-20 15:56:25 +03:00
| PARAMETERS | DESCRIPTION | DEFAULT|
|-------------|-------------|--------|
|**-s**, ** --src**|sources urls|**REQUIRED**|
|**[-h]**|print help and exit||
|**[--preset]**|240p, 360p, 480p, 720p, 1080p, 1440p, 2160p|`None`|
|**[--fps]**|frame per second encoding output|`None`|
|**[--dst]**|destination url|`None`|
|**[--ffpath]**|alternative path to bin|`None`|
|**[--watchdog]**|detect ffmpeg freeze and terminate||
|**[--sec]**|seconds to wait before the watchdog terminates|15|
|**[--mono]**|detect ffmpeg running copy and terminate||
Example usage in cron with Python:
```shell
* * * * * /usr/bin/python3 ~/ffmpeger.py -s rtsp://user:pass@host:554/Streaming/Channels/101 --dst rtmp://a.rtmp.youtube.com/live2/YOUKEY --mono --watchdog --sec 30 >> /dev/null 2>& 1
```
Example usage in terminal with make the script executable:
```shell
chmod u+x ./ffmpeger.py
ffmpeger.py -s rtsp://user:pass@host:554/Streaming/Channels/101 --dst rtp://239.0.0.1:5554
```
Example usage in Python:
```Python
from ffmpeger import FFmpeg
FFmpeg.run(src='null, anull', preset='240p', fps=10)
```
2021-06-20 19:23:02 +03:00
2021-06-20 15:56:25 +03:00
____
2021-06-21 00:05:04 +03:00
## procutil.py
**Description:** Find a running process from Python
**Dependencies:** Python 3 (tested version 3.9.5)
| PARAMETERS | DESCRIPTION | DEFAULT|
|-------------|-------------|--------|
|**[-h]**|print help and exit||
|**[--find]**|find process pid, name or arguments||
|**[--exclude]**|exclude process pid, name or arguments|`None`|
|**[--self]**|find a clones of self|`True`|
|**[--kill]**|kill the process with pid||
Example usage in terminal with Python for find all running processes:
```shell
python3 ./procutil.py
```
Example usage in terminal with make the script executable for find all specified processes:
```shell
chmod u+x ./procutil.py
./procutil.py --find ssh --exclude sftp
```
Example usage in Python for find a clones of self:
```Python
from os import getpid
from sys import argv
from procutil import Proc
processes = Proc.search(' '.join(argv), str(getpid()))
if processes:
for process in processes:
print(process)
```
2021-06-15 15:34:01 +03:00
## sendmail.py
2021-06-20 15:56:25 +03:00
**Description:** Sending email from Python
**Dependencies:** Python 3 (tested version 3.9.5)
2021-06-15 15:34:01 +03:00
| PARAMETERS | DESCRIPTION | DEFAULT|
|-------------|-------------|--------|
|**-u**, ** --user**|smtp valid user|**REQUIRED**|
|**-p**, ** --pass**|smtp valid password|**REQUIRED**|
|**-d**, ** --dest**|destination addresses|**REQUIRED**|
|**[-h]**|print help and exit||
|**[--smtp]**|smtp hostname or ip address|smtp.gmail.com|
|**[--port]**|smtp port number|587|
|**[--stls]**|smtp required TLS|`True`|
|**[--from]**|mail from alias|**--user** value|
|**[--subj]**|mail subject|'no subject'|
|**[--text]**|mail body text|'no text'|
|**[--type]**|mail body type: plain, html|plain|
|**[--file]**|mail attachment files|`None`|
2021-06-16 20:20:35 +03:00
Example usage in terminal with Python:
2021-06-15 15:34:01 +03:00
```shell
python3 ./sendmail.py -u user@gmail.com -p pass -d addr1@gmail.com,addr2@gmail.com
```
Example usage in terminal with make the script executable:
```shell
chmod u+x ./sendmail.py
./sendmail.py -u user@gmail.com -p pass -d addr1@gmail.com,addr2@gmail.com
```
Example usage in Python:
```Python
from sendmail import Mail
msg = Mail(smtp_user='user@gmail.com', smtp_pass='pass', mail_dest='addr1@gmail.com,addr2@gmail.com')
log = msg.send()
print(log)
2021-06-16 20:20:35 +03:00
```
2021-06-20 19:23:02 +03:00
2021-06-16 20:20:35 +03:00
____