46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
|
|
import requests
|
|
|
|
mp4_path = '/home/pi/mp4'
|
|
|
|
|
|
def push_stream():
|
|
subprocess.Popen(['/bin/bash start_push.sh'], shell=True)
|
|
|
|
|
|
def close_stream():
|
|
subprocess.Popen(['/bin/bash stop_push.sh'], shell=True)
|
|
|
|
|
|
def exec_sh(msg):
|
|
cmd = json.loads(msg.payload.decode('utf-8'))["data"]
|
|
if cmd == "supervisorctl stop __mqtt__":
|
|
return
|
|
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
out, err = p.communicate()
|
|
output = out.decode('utf-8')
|
|
print(output)
|
|
|
|
|
|
def update():
|
|
subprocess.Popen(['/bin/bash update.sh'], shell=True)
|
|
|
|
|
|
def get_list_record():
|
|
data = {
|
|
"data": os.listdir(mp4_path)
|
|
}
|
|
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)
|
|
|
|
|
|
def get_record(msg, client):
|
|
filename = json.loads(msg.payload.decode('utf-8'))["data"]
|
|
if filename is None or filename == '':
|
|
client.publish('error', payload='没有该文件', qos=1)
|
|
return
|
|
files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"}
|
|
requests.post("https://shop.lihaink.cn/api/index/upload", files=files)
|