-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
783 lines (675 loc) · 32.6 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
"""
Copyright (C) 2022 Fern Lane, Webinar-hacker
Licensed under the GNU Affero General Public License, Version 3.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/agpl-3.0.en.html
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""
import ctypes
import json
import logging
import os
import shutil
import signal
import sys
import webbrowser
import psutil
import requests
from PyQt5 import uic, QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QLineEdit, QPushButton, QWidget, \
QHBoxLayout, QFileDialog
import AudioHandler
import BrowserHandler
import LectureBuilder
import VideoAudioReader
WEBINAR_HACKER_VERSION = 'beta_4.0.4'
WEBINAR_HACKER_VERSION_CHECK_URL = 'https://api.github.com/repos/F33RNI/Webinar-Hacker/releases/latest'
WEBINAR_HACKER_URL = 'https://github.com/F33RNI/Webinar-hacker/releases/latest'
LOGGING_LEVEL = logging.INFO
SETTINGS_FILE = 'settings.json'
STYLESHEET_FILE = 'stylesheet/Toolery.qss'
ENABLE_DISABLE_GUI_FROM_LECTURE_BUILDER = 0
ENABLE_DISABLE_GUI_FROM_BROWSER = 1
ENABLE_DISABLE_GUI_FROM_VIDEOAUDIO = 2
def logging_setup():
"""
Sets up logging format and level
:return:
"""
logging.basicConfig(encoding='utf-8', format='%(asctime)s %(levelname)-8s %(message)s',
level=LOGGING_LEVEL,
datefmt='%Y-%m-%d %H:%M:%S')
logging.info('logging setup is complete')
def load_json(file_name: str):
"""
Loads json from file_name
:return: json if loaded or None if not
"""
try:
logging.info('Loading ' + file_name + '...')
file = open(file_name, encoding='utf-8')
json_content = json.load(file)
file.close()
if json_content is not None and len(str(json_content)) > 0:
logging.info('Loaded json: ' + str(json_content))
else:
json_content = None
logging.error('Error loading json data from file ' + file_name)
except Exception as e:
json_content = None
logging.error(e, exc_info=True)
return json_content
def save_json(file_name: str, content):
"""
Saves
:param file_name: filename to save
:param content: JSON dictionary
:return:
"""
logging.info('Saving to ' + file_name + '...')
file = open(file_name, 'w')
json.dump(content, file, indent=4)
file.close()
def exit_(signum, frame):
"""
Closes app
:param signum:
:param frame:
:return:
"""
logging.warning('Killing all threads...')
current_system_pid = os.getpid()
psutil.Process(current_system_pid).terminate()
exit(0)
class Window(QMainWindow):
stop_browser_and_recording = QtCore.pyqtSignal(bool) # QtCore.Signal()
elements_set_enabled_signal = QtCore.pyqtSignal(bool) # QtCore.Signal(bool)
progress_bar_audio_signal = QtCore.pyqtSignal(int) # QtCore.Signal(int)
progress_bar_set_value_signal = QtCore.pyqtSignal(int) # QtCore.Signal(int)
progress_bar_set_maximum_signal = QtCore.pyqtSignal(int) # QtCore.Signal(int)
lecture_copy_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
label_rec_set_stylesheet_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
label_device_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
label_current_link_time_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
label_time_left_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
label_current_video_audio_time_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
progress_bar_video_audio_signal = QtCore.pyqtSignal(int) # QtCore.Signal(int)
video_audio_decoding_ended_signal = QtCore.pyqtSignal(str) # QtCore.Signal(str)
def __init__(self, settings_):
super(Window, self).__init__()
self.settings = settings_
# Load GUI from file
uic.loadUi('gui.ui', self)
with open(STYLESHEET_FILE, 'r') as stylesheet_file:
self.setStyleSheet(stylesheet_file.read())
# Connect signals
self.stop_browser_and_recording.connect(lambda from_zoom: self.stop_browser(False, from_zoom=from_zoom))
self.elements_set_enabled_signal.connect(self.elements_set_enabled)
self.progress_bar_audio_signal.connect(self.progressBar_audio.setValue)
self.progress_bar_set_value_signal.connect(self.progressBar.setValue)
self.progress_bar_set_maximum_signal.connect(self.progressBar.setMaximum)
self.lecture_copy_signal.connect(self.lecture_copy)
self.label_rec_set_stylesheet_signal.connect(self.label_rec.setStyleSheet)
self.label_device_signal.connect(self.label_device.setText)
self.label_current_link_time_signal.connect(self.label_current_link_time.setText)
self.label_time_left_signal.connect(self.label_time_left.setText)
self.label_current_video_audio_time_signal.connect(self.label_current_video_time.setText)
self.progress_bar_video_audio_signal.connect(self.progressBar_videoaudio.setValue)
self.video_audio_decoding_ended_signal.connect(self.video_audio_decoding_ended)
# Initialize classes
self.audio_handler = AudioHandler.AudioHandler(self.settings, self.progress_bar_audio_signal,
self.label_rec_set_stylesheet_signal)
self.webinar_handler = BrowserHandler.BrowserHandler(self.audio_handler, self.settings,
self.stop_browser_and_recording, self.preview_label,
self.label_current_link_time_signal)
self.video_audio_reader = VideoAudioReader.VideoAudioReader(self.settings, self.audio_handler,
self.preview_label,
self.label_current_video_audio_time_signal,
self.progress_bar_video_audio_signal,
self.video_audio_decoding_ended_signal)
self.lecture_builder = LectureBuilder.LectureBuilder(self.settings, self.elements_set_enabled_signal,
self.progress_bar_set_value_signal,
self.progress_bar_set_maximum_signal,
self.lecture_copy_signal,
self.label_device_signal,
self.label_time_left_signal)
# Set window title
self.setWindowTitle('Lecture hacker ' + WEBINAR_HACKER_VERSION)
# Set icon
self.setWindowIcon(QtGui.QIcon('icon.png'))
# Show GUI
self.show()
# Additional links
self.additional_links = []
self.additional_links_widgets = []
# Link reconnects counter (for zoom)
self.reconnects_counters = []
# Multiple links indexes
self.current_link_index = 0
# Connect buttons
self.btn_link_add.clicked.connect(lambda: self.link_add(''))
self.btn_refresh.clicked.connect(self.lectures_refresh)
self.btn_build.clicked.connect(self.lecture_build)
self.btn_videoaudio_browse.clicked.connect(self.select_video_audio_file)
self.btn_start.clicked.connect(self.start_)
self.btn_stop.clicked.connect(self.stop_)
# Set gui elements from settings
gui_links = self.settings['gui_links']
if len(gui_links) > 0:
self.line_edit_link.setText(str(gui_links[0]))
if len(gui_links) > 1:
for gui_link_n in range(1, len(gui_links)):
self.link_add(gui_links[gui_link_n])
self.line_edit_name.setText(str(self.settings['gui_name']))
self.line_edit_hello_message.setText(str(self.settings['gui_hello_message']))
self.check_box_hello_message.setChecked(self.settings['gui_hello_message_enabled'])
self.check_box_recording.setChecked(self.settings['gui_recording_enabled'])
self.line_edit_proxy.setText(str(self.settings['gui_proxy']))
gui_max_event_time = int(self.settings['gui_max_event_time_milliseconds']) / 1000 / 60
self.check_box_max_link_time.setChecked(self.settings['gui_max_event_time_enabled'])
self.spin_box_time_hours.setValue(int(gui_max_event_time / 60))
self.spin_box_time_minutes.setValue(int(gui_max_event_time % 60))
self.check_box_zoom_reconnect.setChecked(self.settings['gui_zoom_reconnects_enabled'])
self.spin_box_zoom_max_reconnects.setValue(int(self.settings['gui_zoom_reconnects_max']))
self.slider_audio_threshold.setValue(int(self.settings['gui_audio_threshold_dbfs']))
self.label_audio_threshold.setText(str(int(self.settings['gui_audio_threshold_dbfs'])) + ' dBFS')
self.line_edit_videoaudio.setText(str(self.settings['gui_video_audio_file']))
self.tabWidget.setCurrentIndex(int(self.settings['gui_tabs_current_index']))
# Connect settings updater
self.line_edit_link.textChanged.connect(self.update_settings)
self.line_edit_name.textChanged.connect(self.update_settings)
self.line_edit_hello_message.textChanged.connect(self.update_settings)
self.check_box_hello_message.clicked.connect(self.update_settings)
self.check_box_recording.clicked.connect(self.update_settings)
self.line_edit_proxy.textChanged.connect(self.update_settings)
self.slider_audio_threshold.valueChanged.connect(self.update_settings)
self.check_box_max_link_time.clicked.connect(self.update_settings)
self.spin_box_time_hours.valueChanged.connect(self.update_settings)
self.spin_box_time_minutes.valueChanged.connect(self.update_settings)
self.check_box_zoom_reconnect.clicked.connect(self.update_settings)
self.spin_box_zoom_max_reconnects.valueChanged.connect(self.update_settings)
self.line_edit_videoaudio.textChanged.connect(self.update_settings)
self.tabWidget.currentChanged.connect(self.update_settings)
# Refresh list of lectures
self.lectures_refresh()
# Check app version
self.check_version()
def update_settings(self):
"""
Saves gui fields to settings file
:return:
"""
# Read data from elements
self.links_to_settings()
self.settings['gui_name'] = str(str(self.line_edit_name.text()))
self.settings['gui_hello_message'] = str(str(self.line_edit_hello_message.text()))
self.settings['gui_hello_message_enabled'] = self.check_box_hello_message.isChecked()
self.settings['gui_recording_enabled'] = self.check_box_recording.isChecked()
self.settings['gui_proxy'] = str(str(self.line_edit_proxy.text()))
self.settings['gui_max_event_time_enabled'] = self.check_box_max_link_time.isChecked()
self.settings['gui_max_event_time_milliseconds'] = (int(self.spin_box_time_hours.value()) * 60
+ int(self.spin_box_time_minutes.value())) * 60 * 1000
self.settings['gui_zoom_reconnects_enabled'] = self.check_box_zoom_reconnect.isChecked()
self.settings['gui_zoom_reconnects_max'] = int(self.spin_box_zoom_max_reconnects.value())
self.settings['gui_audio_threshold_dbfs'] = int(self.slider_audio_threshold.value())
self.label_audio_threshold.setText(str(int(self.slider_audio_threshold.value())) + ' dBFS')
self.settings['gui_video_audio_file'] = str(self.line_edit_videoaudio.text())
self.settings['gui_tabs_current_index'] = int(self.tabWidget.currentIndex())
# Save to file
save_json(SETTINGS_FILE, self.settings)
def check_version(self):
"""
Checks app version
:return:
"""
logging.info('Checking app version...')
request_result = requests.get(WEBINAR_HACKER_VERSION_CHECK_URL)
if request_result is not None:
try:
# Check version
tag_name = request_result.json()['tag_name']
if tag_name is not None and len(tag_name) > 1 and tag_name != WEBINAR_HACKER_VERSION:
# Get changelog
changelog = ''
try:
changelog_raw = str(request_result.json()['body'])
changelog += changelog_raw.split('\r\n')[0].replace('#', '').strip()
changelog += '\n\n' + '\n'.join(changelog_raw.split('\r\n')[3:-2]).strip()
except:
pass
# Show update message
QMessageBox.information(self, 'New version available', 'Please download new version: '
+ tag_name + '\n' + WEBINAR_HACKER_URL + '\n\nChangelog:\n' + changelog)
# Open download page
try:
webbrowser.open(WEBINAR_HACKER_URL)
except:
pass
except Exception as e:
logging.warning(e)
def start_(self):
"""
Start button callback
:return:
"""
# Webinar
if int(self.tabWidget.currentIndex()) == 0:
self.start_browser(from_button=True)
# Video / Audio file
elif int(self.tabWidget.currentIndex()) == 1:
self.start_video_audio_decoding()
def stop_(self):
"""
Stop button callback
:return:
"""
# Stop file and webinar handlers
self.stop_video_audio_decoding()
self.stop_browser(True)
# Clear preview image
self.preview_label.clear()
self.preview_label.setText('No image')
def links_to_settings(self):
"""
Updates gui_links
:return:
"""
gui_links = []
# Append main link
if len(str(self.line_edit_link.text()).strip()) > 0:
gui_links.append(str(self.line_edit_link.text()).strip())
# Append additional links
for additional_link in self.additional_links:
if additional_link is not None and len(str(additional_link).strip()) > 0:
gui_links.append(str(additional_link).strip())
# Write to settings
self.settings['gui_links'] = gui_links
def link_add(self, link=''):
"""
Adds new link field
:return:
"""
logging.info('Adding new link ' + link)
# Create elements
widget = QWidget()
layout = QHBoxLayout()
button = QPushButton('-')
line_edit = QLineEdit()
index_ = len(self.additional_links_widgets)
# Delete field on button click
button.clicked.connect(lambda: self.link_remove(index_))
# Set initial link
if len(link.strip()) > 0:
line_edit.setText(link)
# Connect edit event
line_edit.textChanged.connect(lambda: self.link_edit(index_, line_edit.text()))
# Add elements to new layout
layout.addWidget(line_edit)
layout.addWidget(button)
layout.setContentsMargins(0, 0, 0, 0)
widget.setLayout(layout)
# Add to lists
self.additional_links_widgets.append(widget)
self.additional_links.append(link)
# Add to layout
self.layout_links.addWidget(widget)
def link_edit(self, link_index: int, link: str):
"""
Edits additional link
:param link_index:
:param link:
:return:
"""
self.additional_links[link_index] = link
self.update_settings()
def link_remove(self, link_index: int):
"""
Removes link field
:param link_index:
:return:
"""
logging.info('Removing link with index: ' + str(link_index + 1))
if 0 <= link_index < len(self.additional_links_widgets):
widget = self.additional_links_widgets[link_index]
if widget is not None:
# Remove from layout
self.layout_links.removeWidget(widget)
widget.deleteLater()
# Remove from list
self.additional_links_widgets[link_index] = None
self.additional_links[link_index] = ''
# Write to settings
self.update_settings()
def lectures_refresh(self):
"""
Searches for lectures
:return:
"""
logging.info('Refreshing list of lectures...')
lectures = []
recordings_dir = str(self.settings['recordings_directory_name']) + '/'
if os.path.exists(recordings_dir):
# List all dirs in recordings directory
for recording_dir in os.listdir(recordings_dir):
recording_dir_ = recording_dir
recording_dir = os.path.join(recordings_dir, recording_dir)
if os.path.isdir(recording_dir):
# List all dirs inside DD_MM_YYYY__HH_MM_SS folder
for audio_or_screenshot_dir in os.listdir(recording_dir):
audio_or_screenshot_dir = os.path.join(recording_dir, audio_or_screenshot_dir)
if os.path.isdir(audio_or_screenshot_dir):
for file_ in os.listdir(audio_or_screenshot_dir):
if str(file_).lower().endswith(AudioHandler.WAVE_FILE_EXTENSION):
lectures.append(str(recording_dir_))
break
# Sort lectures
lectures.sort(reverse=True)
# Add to combobox and log list of lectures
logging.info('Available lectures: ' + str(lectures))
self.combo_box_recordings.clear()
self.combo_box_recordings.addItems(lectures)
def start_video_audio_decoding(self):
"""
Starts video/audio decoding
:return:
"""
# Check if file exists
video_audio_file = str(self.settings['gui_video_audio_file']).strip()
if not os.path.exists(video_audio_file):
if len(video_audio_file) > 0:
QMessageBox.warning(self, 'Not exists', 'File ' + video_audio_file + ' not exists!')
else:
QMessageBox.warning(self, 'No file', 'Please select video / audio file!')
else:
self.elements_set_enabled(False, ENABLE_DISABLE_GUI_FROM_VIDEOAUDIO)
self.audio_handler.recording_start(AudioHandler.RECORD_FROM_FRAMES,
os.path.splitext(os.path.basename(video_audio_file))[0])
self.video_audio_reader.start_processing_file(video_audio_file)
def stop_video_audio_decoding(self):
"""
Aborts video/audio decoding
:return:
"""
self.video_audio_reader.abort_processing_file()
self.elements_set_enabled(True, ENABLE_DISABLE_GUI_FROM_VIDEOAUDIO)
def video_audio_decoding_ended(self, name=None):
"""
Shows ending info after decoding finishes and enables gui elements
:param name:
:return:
"""
if name is None:
QMessageBox.warning(self, 'No frames!', 'No frames processed!')
else:
QMessageBox.information(self, 'Done!', 'File ' + name + ' decoded!\nNow you can build lecture from it')
self.elements_set_enabled(True, ENABLE_DISABLE_GUI_FROM_VIDEOAUDIO)
self.lectures_refresh()
def select_video_audio_file(self):
"""
Opens file dialog for video/audio file
:return:
"""
options = QFileDialog.Options()
options &= ~QFileDialog.DontUseNativeDialog
last_file = str(self.settings['gui_video_audio_file']).strip()
if not os.path.exists(last_file):
last_file = ''
open_filename, _ = QFileDialog.getOpenFileName(self, 'Open video/audio lecture',
last_file,
'Media files (*.mp4 *.mkv *.avi *.3gp *.mp3 *.m4a *.wav)'
';;All Files (*.*)',
options=options)
if open_filename is not None and open_filename:
# Set to field
self.line_edit_videoaudio.setText(str(open_filename).strip())
# Save to settings
self.settings['gui_video_audio_file'] = str(open_filename).strip()
self.update_settings()
def lecture_build(self):
"""
Starts building lecture
:return:
"""
selected_lecture = str(self.combo_box_recordings.currentText())
logging.info('Selected lecture: ' + selected_lecture)
if len(selected_lecture) > 0:
# Disable all gui elements
self.elements_set_enabled(False, ENABLE_DISABLE_GUI_FROM_LECTURE_BUILDER)
# Start building lecture
self.lecture_builder.start_building_lecture(str(self.settings['recordings_directory_name'])
+ '/' + selected_lecture, selected_lecture)
def lecture_copy(self, lecture_file):
"""
Copies lecture from lecture_file to whatever user selected
:param lecture_file: original lecture file (in lectures/ directory)
:return:
"""
# Ask for file
options = QFileDialog.Options()
options &= ~QFileDialog.DontUseNativeDialog
save_filename, _ = QFileDialog.getSaveFileName(self, 'Save lecture',
os.path.join(str(self.settings['save_lecture_to_directory']),
os.path.basename(lecture_file)),
'Word document (*.docx);;All Files (*.*)', options=options)
saved_to = ''
if save_filename is not None and save_filename and len(save_filename) > 1:
saved_to = save_filename
# Copy file
try:
shutil.copyfile(lecture_file, save_filename)
except Exception as e:
logging.warning('Error copying lecture file! ' + str(e))
# Save directory for future usages
self.settings['save_lecture_to_directory'] = os.path.dirname(save_filename)
self.update_settings()
# Show confirmation info message box
if len(saved_to) > 0:
info_text = 'Saved to: ' + saved_to + '\n\nAnd to: ' + lecture_file
else:
info_text = 'Saved to: ' + lecture_file
QMessageBox.information(self, 'Done!', info_text)
def start_browser(self, from_button: bool):
"""
Asks for confirmation and opens browser and starts recording
:param from_button: True if button clicked false if automation
:return:
"""
try:
# Reset current link index if action is from button
if from_button:
self.current_link_index = 0
logging.info('Starting from link with index: ' + str(self.current_link_index))
# Check link index
if self.current_link_index >= len(self.settings['gui_links']):
logging.info('No more links')
QMessageBox.information(self, 'No links!', 'No more available links provided')
self.elements_set_enabled(True, ENABLE_DISABLE_GUI_FROM_BROWSER)
return
# Get link
link = str(self.settings['gui_links'][self.current_link_index]).strip()
while len(link) <= 0 and self.current_link_index < len(self.settings['gui_links']):
self.current_link_index += 1
link = str(self.settings['gui_links'][self.current_link_index]).strip()
# Can not get new link
if len(link) <= 0:
QMessageBox.warning(self, 'No links!', 'No more available links provided')
self.elements_set_enabled(True, ENABLE_DISABLE_GUI_FROM_BROWSER)
return
# Get username
user_name = str(self.settings['gui_name']).strip()
# Check link and username
if len(user_name) > 0:
start_allowed = False
# No confirmation needed in auto mode
if not from_button:
start_allowed = True
# Ask for confirmation
else:
is_recording_enabled = self.settings['gui_recording_enabled']
recording_state_str = 'ENABLED' if is_recording_enabled else 'DISABLED'
warning_msg = 'Event recording ' + recording_state_str + '!\nDo you want to continue?'
reply = QMessageBox.warning(self, 'Recording ' + recording_state_str, warning_msg, QMessageBox.Yes,
QMessageBox.No)
if reply == QMessageBox.Yes:
start_allowed = True
if start_allowed:
# Add reconnect timer if not exists
counter_exists = False
for reconnect_counter in self.reconnects_counters:
if str(self.current_link_index) in reconnect_counter:
counter_exists = True
break
if not counter_exists:
self.reconnects_counters.append({str(self.current_link_index): 0})
# Open audio stream
if self.settings['gui_recording_enabled']:
self.audio_handler.open_stream()
# Disable form elements and start
self.elements_set_enabled(False, ENABLE_DISABLE_GUI_FROM_BROWSER)
self.webinar_handler.start_browser(link)
self.webinar_handler.start_handler(user_name)
else:
QMessageBox.warning(self, 'No user name', 'Please type user name to connect with!')
# Error
except Exception as e:
logging.error(e, exc_info=True)
QMessageBox.critical(self, 'Error', 'Error starting browser and other staff\n' + str(e)
+ '\nTry turning off recording.')
def stop_browser(self, from_button: bool, from_zoom=False):
"""
Stops recording and closes browser
:return:
:param from_button: True if button clicked false if automation
:param from_zoom: will reconnect to the same link if needed
"""
# Stop recording
self.audio_handler.recording_stop()
# Close audio stream
self.audio_handler.close_stream()
# Close browser
if self.webinar_handler.browser is not None:
self.webinar_handler.stop_handler()
self.webinar_handler.stop_browser()
# Refresh lectures
self.lectures_refresh()
# Reconnect for zoom
if from_zoom:
if self.settings['gui_zoom_reconnects_enabled']:
for i in range(len(self.reconnects_counters)):
if str(self.current_link_index) in self.reconnects_counters[i]:
reconnected_times = self.reconnects_counters[i][str(self.current_link_index)]
logging.info('Reconnected: ' + str(reconnected_times) + ' times')
if reconnected_times < int(self.settings['gui_zoom_reconnects_max']):
logging.info('Reconnecting...')
self.reconnects_counters[i][str(self.current_link_index)] = reconnected_times + 1
self.start_browser(False)
return
else:
logging.info('Reconnects disabled!')
# Next link
if not from_button and self.current_link_index <= len(self.settings['gui_links']):
self.current_link_index += 1
self.start_browser(False)
# No more links
else:
# Enable GUI elements
self.elements_set_enabled(True, ENABLE_DISABLE_GUI_FROM_BROWSER)
def elements_set_enabled(self, enabled: bool, enable_disable_from=ENABLE_DISABLE_GUI_FROM_LECTURE_BUILDER):
"""
Enables or disables gui elements
:param enabled:
:param enable_disable_from: ENABLE_DISABLE_GUI_FROM_LECTURE_BUILDER
:return:
"""
logging.info('Enable gui elements? ' + str(enabled))
# Independent elements
self.line_edit_link.setEnabled(enabled)
self.btn_link_add.setEnabled(enabled)
self.line_edit_name.setEnabled(enabled)
self.line_edit_hello_message.setEnabled(enabled)
self.check_box_hello_message.setEnabled(enabled)
self.check_box_recording.setEnabled(enabled)
self.line_edit_proxy.setEnabled(enabled)
self.combo_box_recordings.setEnabled(enabled)
self.btn_refresh.setEnabled(enabled)
self.btn_build.setEnabled(enabled)
self.line_edit_videoaudio.setEnabled(enabled)
self.btn_videoaudio_browse.setEnabled(enabled)
self.btn_start.setEnabled(enabled)
self.tabWidget.tabBar().setEnabled(enabled)
for additional_links_widget in self.additional_links_widgets:
if additional_links_widget is not None:
additional_links_widget.setEnabled(enabled)
# Function call from lecture builder
if enable_disable_from == ENABLE_DISABLE_GUI_FROM_LECTURE_BUILDER:
self.check_box_max_link_time.setEnabled(enabled)
self.spin_box_time_hours.setEnabled(enabled)
self.spin_box_time_minutes.setEnabled(enabled)
self.check_box_zoom_reconnect.setEnabled(enabled)
self.spin_box_zoom_max_reconnects.setEnabled(enabled)
self.slider_audio_threshold.setEnabled(enabled)
self.btn_stop.setEnabled(False)
# Function call from browser handlers
elif enable_disable_from == ENABLE_DISABLE_GUI_FROM_BROWSER:
self.check_box_max_link_time.setEnabled(True)
self.spin_box_time_hours.setEnabled(True)
self.spin_box_time_minutes.setEnabled(True)
self.check_box_zoom_reconnect.setEnabled(True)
self.spin_box_zoom_max_reconnects.setEnabled(True)
self.slider_audio_threshold.setEnabled(True)
self.btn_stop.setEnabled(not enabled)
# Function call from video handlers
elif enable_disable_from == ENABLE_DISABLE_GUI_FROM_VIDEOAUDIO:
self.check_box_max_link_time.setEnabled(enabled)
self.spin_box_time_hours.setEnabled(enabled)
self.spin_box_time_minutes.setEnabled(enabled)
self.check_box_zoom_reconnect.setEnabled(enabled)
self.spin_box_zoom_max_reconnects.setEnabled(enabled)
self.slider_audio_threshold.setEnabled(True)
self.btn_stop.setEnabled(not enabled)
def closeEvent(self, event):
"""
Kills all threads
:param event:
:return:
"""
# Stop recording
self.audio_handler.recording_stop()
# Close browser
if self.webinar_handler.browser is not None:
self.webinar_handler.stop_handler()
self.webinar_handler.stop_browser()
# Kill all threads
exit_(None, None)
# Accept event
event.accept()
if __name__ == '__main__':
# Initialize logging
logging_setup()
# Connect interrupt signal
signal.signal(signal.SIGINT, exit_)
# Load settings
settings = load_json(SETTINGS_FILE)
if settings is not None:
# Replace icon in taskbar
if os.name == 'nt':
webinar_hacker_app_ip = 'f3rni.webinarhacker.webinarhacker.' + WEBINAR_HACKER_VERSION
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(webinar_hacker_app_ip)
# Start app
app = QApplication.instance() or QApplication(sys.argv)
app.setStyle('fusion')
win = Window(settings)
app.exec_()
# Error loading settings file
else:
logging.error('Error loading ' + SETTINGS_FILE)
exit_(None, None)