-
Notifications
You must be signed in to change notification settings - Fork 8
/
rtsp_capture.py
executable file
·44 lines (29 loc) · 1.19 KB
/
rtsp_capture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import os
from fire import Fire
from lib.rtsp import capture_image
from lib.utils import geoip_str_online
from lib.utils import geoip_str_online, str_to_filename
from lib.files import LOCAL_DIR
CAPTURES_DIR = LOCAL_DIR / 'rtsp_captures'
def capture(stream_url, prefer_ffmpeg=False, capture_callback=None):
from urllib.parse import urlparse
up = urlparse(stream_url)
p = str_to_filename(f'{up.path}{up.params}')
img_name = f'{up.hostname}_{up.port}_{up.username}_{up.password}_{p}'
img_path = CAPTURES_DIR / ('%s.jpg' % img_name)
captured = capture_image(stream_url, img_path, prefer_ffmpeg)
print('[+]' if captured else '[-]', stream_url)
if captured and capture_callback:
import subprocess
subprocess.Popen([capture_callback, stream_url,
str(img_path), geoip_str_online(up.hostname).encode().decode('ascii', errors='ignore')]).communicate(timeout=25)
def main(urls_file, ff=False, cb=''):
if not CAPTURES_DIR.exists():
CAPTURES_DIR.mkdir()
with open(urls_file) as f:
for ln in f:
url = ln.rstrip()
capture(url, ff, cb)
if __name__ == "__main__":
Fire(main)