-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathprogram.py
More file actions
119 lines (108 loc) · 3.7 KB
/
program.py
File metadata and controls
119 lines (108 loc) · 3.7 KB
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
import logging
from module.conf import VERSION, settings
from module.models import ResponseModel
from module.update import (
data_migration,
first_run,
from_30_to_31,
start_up,
cache_image,
)
from .sub_thread import RenameThread, RSSThread
logger = logging.getLogger(__name__)
figlet = r"""
_ ____ _
/\ | | | _ \ (_)
/ \ _ _| |_ ___ | |_) | __ _ _ __ __ _ _ _ _ __ ___ _
/ /\ \| | | | __/ _ \| _ < / _` | '_ \ / _` | | | | '_ ` _ \| |
/ ____ \ |_| | || (_) | |_) | (_| | | | | (_| | |_| | | | | | | |
/_/ \_\__,_|\__\___/|____/ \__,_|_| |_|\__, |\__,_|_| |_| |_|_|
__/ |
|___/
"""
class Program(RenameThread, RSSThread):
@staticmethod
def __start_info():
for line in figlet.splitlines():
logger.info(line.strip("\n"))
logger.info(
f"Version {VERSION} Author: EstrellaXD Twitter: https://twitter.com/Estrella_Pan"
)
logger.info("GitHub: https://github.com/EstrellaXD/Auto_Bangumi/")
logger.info("Starting AutoBangumi...")
def startup(self):
self.__start_info()
if not self.database:
first_run()
logger.info("[Core] No db file exists, create database file.")
return {"status": "First run detected."}
if self.legacy_data:
logger.info(
"[Core] Legacy data detected, starting data migration, please wait patiently."
)
data_migration()
elif self.version_update:
# Update database
from_30_to_31()
logger.info("[Core] Database updated.")
if not self.img_cache:
logger.info("[Core] No image cache exists, create image cache.")
cache_image()
self.start()
def start(self):
self.stop_event.clear()
settings.load()
if self.downloader_status:
if self.enable_renamer:
self.rename_start()
if self.enable_rss:
self.rss_start()
logger.info("Program running.")
return ResponseModel(
status=True,
status_code=200,
msg_en="Program started.",
msg_zh="程序启动成功。",
)
else:
self.stop_event.set()
logger.warning("Program failed to start.")
return ResponseModel(
status=False,
status_code=406,
msg_en="Program failed to start.",
msg_zh="程序启动失败。",
)
def stop(self):
if self.is_running:
self.stop_event.set()
self.rename_stop()
self.rss_stop()
return ResponseModel(
status=True,
status_code=200,
msg_en="Program stopped.",
msg_zh="程序停止成功。",
)
else:
return ResponseModel(
status=False,
status_code=406,
msg_en="Program is not running.",
msg_zh="程序未运行。",
)
def restart(self):
self.stop()
self.start()
return ResponseModel(
status=True,
status_code=200,
msg_en="Program restarted.",
msg_zh="程序重启成功。",
)
def update_database(self):
if not self.version_update:
return {"status": "No update found."}
else:
start_up()
return {"status": "Database updated."}