-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.py
125 lines (108 loc) · 4.91 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import datetime
import json
import logging
import os
import sys
import time
import threading
from multiprocessing import freeze_support
from lastversion import lastversion
import utils
from MainRunner import MainThreadRunner
CURRENT_VERSION = "1.3.3"
class versionThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
try:
latest_version = lastversion.has_update(
repo="AsaChiri/DDRecorder", current_version=CURRENT_VERSION)
if latest_version:
print('DDRecorder 有更新,版本号:{} 请尽快到 https://github.com/AsaChiri/DDRecorder/releases 下载最新版'.format(str(latest_version)))
else:
print('DDRecorder 已是最新版本!')
except:
print('无法获取 DDRecorder 的版本信息,当前版本号:{},请到 https://github.com/AsaChiri/DDRecorder/releases 检查最新版本'.format(CURRENT_VERSION))
if __name__ == "__main__":
freeze_support()
vt = versionThread()
vt.start()
if utils.is_windows():
utils.add_path("./ffmpeg/bin")
try:
if len(sys.argv) > 1:
all_config_filename = sys.argv[1]
with open(all_config_filename, "r", encoding="UTF-8") as f:
all_config = json.load(f)
else:
with open("config.json", "r", encoding="UTF-8") as f:
all_config = json.load(f)
except Exception as e:
print("解析配置文件时出现错误,请检查配置文件!")
print("错误详情:"+str(e))
os.system('pause')
utils.check_and_create_dir(all_config.get(
'root', {}).get('data_path', "./"))
utils.check_and_create_dir(all_config.get('root', {}).get(
'logger', {}).get('log_path', './log'))
logfile_name = "Main_"+datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')+'.log'
logging.basicConfig(level=utils.get_log_level(all_config),
format='%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
handlers=[logging.FileHandler(os.path.join(all_config.get('root', {}).get('logger', {}).get('log_path', "./log"), logfile_name), "a", encoding="utf-8")])
utils.init_data_dirs(all_config.get('root', {}).get('data_path', "./"))
if all_config.get('root', {}).get('enable_baiduyun', False):
from bypy import ByPy
bp = ByPy()
runner_dict = {}
for spec_config in all_config.get('spec', []):
config = {
'root': all_config.get('root', {}),
'spec': spec_config
}
tr = MainThreadRunner(config)
tr.setDaemon(True)
runner_dict[spec_config['room_id']] = tr
for tr in runner_dict.values():
tr.start()
time.sleep(10)
while True:
old_config = all_config
try:
if len(sys.argv) > 1:
all_config_filename = sys.argv[1]
with open(all_config_filename, "r", encoding="UTF-8") as f:
all_config = json.load(f)
else:
with open("config.json", "r", encoding="UTF-8") as f:
all_config = json.load(f)
except Exception as e:
print("解析配置文件时出现错误,请检查配置文件!已使用最后一次正确的配置")
print("错误详情:"+str(e))
all_config = old_config
utils.check_and_create_dir(all_config.get(
'root', {}).get('data_path', "./"))
utils.check_and_create_dir(all_config.get('root', {}).get(
'logger', {}).get('log_path', './log'))
logging.basicConfig(level=utils.get_log_level(all_config),
format='%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
handlers=[logging.FileHandler(os.path.join(all_config.get('root', {}).get('logger', {}).get('log_path', "./log"), logfile_name), "a", encoding="utf-8")])
utils.init_data_dirs(all_config.get('root', {}).get('data_path', "./"))
if all_config.get('root', {}).get('enable_baiduyun', False):
from bypy import ByPy
bp = ByPy()
for spec_config in all_config.get('spec', []):
config = {
'root': all_config.get('root', {}),
'spec': spec_config
}
if spec_config['room_id'] in runner_dict:
runner_dict[spec_config['room_id']].mr.config = config
else:
tr = MainThreadRunner(config)
tr.setDaemon(True)
runner_dict[spec_config['room_id']] = tr
tr.start()
utils.print_log(runner_dict)
time.sleep(all_config.get('root', {}).get('print_interval', 60))