-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop_cd_recording.py
executable file
·94 lines (80 loc) · 2.86 KB
/
stop_cd_recording.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
#!/usr/bin/env python3
# Copyright © 2024 Noah Vogt <[email protected]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from time import sleep
import colorama
from PyQt5.QtWidgets import ( # pylint: disable=no-name-in-module
QApplication,
QMessageBox,
)
from utils import (
get_yyyy_mm_dd_date,
make_sure_file_exists,
get_unix_milis,
warn,
expand_dir,
InfoMsgBox,
)
from input import get_cachefile_content, validate_cd_record_config
import config as const
from recording import is_valid_cd_record_checkfile, mark_end_of_recording
from os_agnostic import kill_process
def stop_cd_recording() -> None:
filename = expand_dir(const.CD_RECORD_CACHEFILE)
cachefile_content = get_cachefile_content(filename)
yyyy_mm_dd = get_yyyy_mm_dd_date()
if is_valid_cd_record_checkfile(cachefile_content, yyyy_mm_dd):
unix_milis = get_unix_milis()
last_track_milis = int(cachefile_content[4])
milis_diff = unix_milis - last_track_milis
if milis_diff < const.CD_RECORD_MIN_TRACK_MILIS:
warn(
f"Minimum track length of {const.CD_RECORD_MIN_TRACK_MILIS}"
+ "ms not satisfied, sleeping until reached..."
)
sleep(milis_diff / 1000 + 1)
try:
kill_process(int(cachefile_content[2]))
except ProcessLookupError:
app = QApplication
InfoMsgBox(
QMessageBox.Critical,
"Error",
"Recording not running, cannot be stopped.",
)
del app
sys.exit(1)
mark_end_of_recording(cachefile_content)
else:
if cachefile_content[1].strip() == "9001":
app = QApplication
InfoMsgBox(
QMessageBox.Warning,
"Warning",
"CD Recording stopped already.",
)
del app
sys.exit(0)
app = QApplication
InfoMsgBox(
QMessageBox.Critical,
"Error",
f"CD Record Checkfile {filename} is invalid.",
)
del app
sys.exit(1)
if __name__ == "__main__":
colorama.init()
validate_cd_record_config()
make_sure_file_exists(const.CD_RECORD_CACHEFILE, gui_error_out=True)
stop_cd_recording()