forked from sxyazi/free-hls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
42 lines (32 loc) · 951 Bytes
/
utils.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
import os
import re
import shutil
import importlib
import subprocess
from os import getenv as _
def exec(cmd, timeout=None, **kwargs):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
communicate_kwargs = {}
if timeout is not None:
communicate_kwargs['timeout'] = timeout
out, err = p.communicate(**communicate_kwargs)
if p.returncode != 0:
raise Exception(cmd, out, err.decode('utf-8'))
return out.decode('utf-8').strip()
def tsfiles(m3u8):
return re.findall(r'^out\d+\.ts$', m3u8, re.M)
def safename(file):
return '"' + file.replace('"', '\\"') + '"'
def sameparams(dir, command):
if not os.path.isdir(dir):
return False
try:
if open('%s/command.sh' % dir, 'r').read() != command:
shutil.rmtree(dir)
return False
except:
shutil.rmtree(dir)
return False
return True
def uploader():
return importlib.import_module('uploader.' + _('UPLOAD_DRIVE')).handle