-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.py
70 lines (56 loc) · 2.24 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
from tools import check_pypi, check_update
check_pypi()
import time
import argparse
from datetime import datetime
import os
import sys
import logging
import logging.handlers
import yaml
from glob import glob
from os.path import exists, splitext
os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.append('./tools')
VERSION = '2024.12.20'
from DMR import DanmakuRender
from DMR.Config import Config
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--config', default='configs')
parser.add_argument('--global_config',default='configs/global.yml')
parser.add_argument('--debug',action='store_true')
parser.add_argument('--version',action='store_true')
parser.add_argument('--skip_update',action='store_true')
args = parser.parse_args()
if args.version:
print(f'DanmakuRender-5 {VERSION}.')
print('https://github.com/SmallPeaches/DanmakuRender')
exit(0)
if not args.skip_update:
check_update(VERSION)
config = Config(args.global_config, args.config)
logger = logging.getLogger('DMR')
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(logging.Formatter("[%(asctime)s][%(levelname)s]: %(message)s"))
os.makedirs('logs', exist_ok=True)
log_file = f'logs/DMR-{datetime.now().strftime("%Y%m%d")}.log'
if exists(log_file):
_cnt = len(glob(splitext(log_file)[0] + '*'))
log_file = splitext(log_file)[0] + f'({_cnt})' + splitext(log_file)[1]
file_handler = logging.handlers.TimedRotatingFileHandler(log_file, when='D', interval=1, backupCount=3, encoding='utf-8')
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(logging.Formatter("[%(asctime)s][%(module)s][%(levelname)s]: %(message)s"))
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.debug(f'VERSION: {VERSION}')
dmr = DanmakuRender(config, logger=logger, debug=args.debug)
dmr.start()
try:
while 1:
time.sleep(60)
except KeyboardInterrupt:
dmr.stop()
exit(0)