-
Notifications
You must be signed in to change notification settings - Fork 0
/
construct.py
178 lines (129 loc) · 5.03 KB
/
construct.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import cv2
from tkinter import *
from tkinter import messagebox
import PIL.Image, PIL.ImageTk
from time import time, sleep
from ffpyplayer.player import MediaPlayer
import smtplib, os, pickle
from email import encoders
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
import json
with open("info.json", encoding='UTF8') as json_file:
json_info = json.load(json_file)
video_path=json_info["video_path"]
email = json_info["myInfo"]["mail"] # google mail
pw = json_info["myInfo"]["pw"] # google app password required
# check student info
def exist_student(class_id, std_id, name):
if (class_id not in json_info.keys()) or \
(std_id not in json_info[class_id].keys()) or \
(name != json_info[class_id][std_id]):
return False
else:
return True
# SMTP type
def mailing(std_class, std_id, name, play_time):
smtp = smtplib.SMTP('smtp.gmail.com', 587)
smtp.ehlo()
smtp.starttls()
smtp.login(email, pw)
msg = MIMEMultipart()
msg['Subject'] = std_class + '_' + std_id + '_' + name + '_' + str(play_time)
part = MIMEText(std_class + '_' + std_id + '_' + name + '_' + str(play_time))
msg.attach(part)
msg["To"] = email
smtp.sendmail(email, email, msg.as_string())
smtp.quit()
class VideoPlayer(Tk):
def __init__(self, video_source=None):
Tk.__init__(self)
self._frame = None
self.switch_frame(EntranceScene)
self.video_source = video_source
def switch_frame(self, frame_class):
new_frame = frame_class(self)
if self._frame is not None:
self._frame.destroy()
self._frame = new_frame
self._frame.pack()
def end_app(self):
self.destroy()
class EntranceScene(Frame):
def __init__(self, master):
Frame.__init__(self, master)
description_lbl1 = Label(self, text="created by ParkHeeChan")
description_lbl1.pack()
description_lbl2 = Label(self, text="hchan11@naver.com")
description_lbl2.pack()
class_lbl = Label(self, text="분반 (월/화/목오전/목오후)") # class
class_lbl.pack()
class_txt = Entry(self)
class_txt.pack()
std_id_lbl = Label(self, text="학번(std_id)") # student ID
std_id_lbl.pack()
std_id_txt = Entry(self)
std_id_txt.pack()
name_lbl = Label(self, text="이름(name)") # student name
name_lbl.pack()
name_txt = Entry(self)
name_txt.pack()
def entrance_btn():
class_id = class_txt.get()
std_id = std_id_txt.get()
name = name_txt.get()
self.master.class_id = class_id
self.master.std_id = std_id
self.master.name = name
if exist_student(class_id, std_id, name) is True:
messagebox.showinfo("info", f"{std_id}_ {name}")
master.switch_frame(PlayerScene)
else:
messagebox.showinfo("Error", "분반, 학번, 이름을 확인하세요.")
entrance_btn = Button(self, text="확인", command=entrance_btn)
entrance_btn.pack()
class PlayerScene(Frame):
def __init__(self, master):
Frame.__init__(self, master)
description_lbl1 = Label(self, text="동영상이 끝나고 확인 메세지가 나와야 출석 체크 됩니다.")
description_lbl1.pack()
def destroy_btn():
messagebox.showinfo("info", "종료합니다.")
master.destroy()
def play_btn():
try:
cap = cv2.VideoCapture(self.master.video_source)
sound_player = MediaPlayer(self.master.video_source)
except:
ValueError
return 0
start_time = time()
fps = cap.get(cv2.CAP_PROP_FPS)
delay = round(1000 / fps)
cap.set(cv2.CAP_PROP_FPS, round(fps))
ret = False
while(cap.isOpened()):
ret, frame = cap.read()
audio_frame, val = sound_player.get_frame()
if ret:
cv2.imshow('FPGA Player', frame)
if cv2.waitKey(delay-4) & 0xFF == ord('q'): # fps - 4 frame will be sync with audio
break
if val != 'eof' and audio_frame is not None:
img, t = audio_frame
else:
break
cap.release()
messagebox.showinfo("info", "학습이 끝났습니다.")
cv2.destroyAllWindows()
end_time = time()
play_time = start_time - end_time # play time check
mailing(self.master.class_id, self.master.std_id, self.master.name, play_time)
exit_lbl = Button(self, text="종료", command=destroy_btn)
exit_lbl.pack()
play_btn = Button(self, text="재생", command=play_btn)
play_btn.pack()
if __name__ == "__main__":
app = VideoPlayer(video_source=video_path)
app.mainloop()