-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnmv.py
1316 lines (1122 loc) · 62.5 KB
/
nmv.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
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright xbyteW 2024
import config # Configures python environment before anything else is done
from PySide6.QtWidgets import (QApplication, QLabel, QVBoxLayout, QWidget, QMainWindow, QCheckBox, QHBoxLayout,
QScroller, QSpinBox, QPushButton, QGraphicsOpacityEffect, QScrollerProperties, QFrame,
QComboBox, QFormLayout, QLineEdit, QMessageBox, QScrollBar, QSizePolicy)
from PySide6.QtGui import QDesktopServices, QPixmap, QIcon, QDoubleValidator, QFont, QImage
from PySide6.QtCore import Qt, QTimer, QPropertyAnimation, QRect, QUrl
# from PySide6.QtMultimediaWidgets import QVideoWidget
# from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtGui import QColor
from modules.AutoProviderPlugin import AutoProviderPlugin, AutoProviderBaseLike, AutoProviderBaseLike2
from modules.Classes import (CustomProgressDialog, ImageLabel, SearchWidget, AdvancedQMessageBox,
CustomComboBox, Settings, QAdvancedSmoothScrollingArea, AutoProviderManager,
AdvancedSettingsDialog)
from modules.themes import Themes
# Apt stuff ( update to newer version )
from aplustools.io.loggers import monitor_stdout
from aplustools.data.updaters import VersionNumber
from aplustools.io.environment import System
from aplustools import set_dir_to_ex
from urllib.parse import urlparse
import requests
import sqlite3
import random
import shutil
import json
import math
import time
import sys
import os
import multiprocessing
import stdlib_list
multiprocessing.freeze_support()
hiddenimports = list(stdlib_list.stdlib_list())
set_dir_to_ex()
os.chdir(os.path.join(os.getcwd(), './_internal'))
class MainWindow(QMainWindow):
def __init__(self, app):
super().__init__()
self.app = app
self.data_folder = os.path.abspath('./data').strip("/")
self.cache_folder = os.path.abspath('./cache').strip("/")
self.modules_folder = os.path.abspath('./modules').strip("/")
self.extensions_folder = os.path.abspath('./extensions').strip("/")
self.logger = monitor_stdout(f"{self.data_folder}/logs.txt")
self.system = System()
self.setWindowTitle("Manhwa Viewer 166")
self.setWindowIcon(QIcon(f"{self.data_folder}/Untitled-1-noBackground.png"))
db_path = f"{self.data_folder}/data.db"
if int(self.system.get_major_os_version()) <= 10:
self.settings = Settings(db_path, {"geometry": "100, 100, 800, 630", "advanced_settings": '{"recent_titles": [], "themes": {"light": "light", "dark": "dark", "font": "Segoe UI"}, "settings_file_path": "", "settings_file_mode": "overwrite", "misc": {"auto_export": false, "num_workers": 10}}',}, self.export_settings)
else:
self.settings = Settings(db_path, {"geometry": "100, 100, 800, 630"}, self.export_settings)
# self.settings.set_geometry([100, 100, 800, 630])
self.os_theme = self.system.get_windows_theme() or os.environ.get('MV_THEME') or "light"
self.theme = None
self.update_theme(self.os_theme.lower())
x, y, height, width = self.settings.get_geometry()
self.setGeometry(x, y + 31, height, width) # Somehow saves it as 31 pixels less
self.setup_gui()
# Advanced setup
self.provider_dict = self.provider = None
self.provider_combobox.currentIndexChanged.disconnect()
self.reload_providers()
self.switch_provider(self.settings.get_provider())
self.provider_combobox.currentIndexChanged.connect(self.change_provider)
self.reload_window_title()
# Scaling stuff
self.previous_scrollarea_width = self.scrollarea.width()
self.content_paths = self.get_content_paths()
self.task_successful = False
self.threading = False
self.reload_gui()
self.downscaling = self.downscale_checkbox.isChecked()
self.upscaling = self.upscale_checkbox.isChecked()
if not self.hover_effect_all_checkbox.isChecked():
self.reload_hover_effect_all_setting()
self.reload_acrylic_menus_setting(callback=True)
else:
self.reload_hover_effect_all_setting()
self.reload_acrylic_menus_setting()
self.reload_borderless_setting()
self.reload_acrylic_background_setting()
self.reload_hide_titlebar_setting()
self.reload_hide_scrollbar_setting()
self.reload_stay_on_top_setting()
self.update_sensitivity(int(self.settings.get_scrolling_sensitivity() * 10))
self.show()
self.check_for_update()
self.force_rescale = False
self.content_widgets = []
self.reload_content()
self.force_rescale = True
QTimer.singleShot(50, lambda: (
self.scrollarea.verticalScrollBar().setValue(self.settings.get_last_scroll_positions()[0]),
self.scrollarea.horizontalScrollBar().setValue(self.settings.get_last_scroll_positions()[1])
))
self.last_reload_ts = time.time()
def check_for_update(self):
try:
response = requests.get("https://raw.githubusercontent.com/adalfarus/update_check/main/mv/update.json",
timeout=1)
except Exception as e:
title = "Info"
text = "There was an error when checking for updates."
description = f"{e}"
msg_box = AdvancedQMessageBox(self, QMessageBox.Icon.Information, title, text, description,
standard_buttons=QMessageBox.StandardButton.Ok,
default_button=QMessageBox.StandardButton.Ok)
msg_box.exec()
return
try:
update_json = response.json()
except (requests.exceptions.RequestException, requests.exceptions.JSONDecodeError, ValueError) as e:
print(f"An error occurred: {e}")
return
# Initializing all variables
newest_version = VersionNumber(update_json["metadata"]["newestVersion"])
newest_version_data = update_json["versions"][-1]
for release in update_json["versions"]:
if release["versionNumber"] == newest_version:
newest_version_data = release
push = newest_version_data["push"].title() == "True"
current_version = "166"
found_version = None
# Find a version bigger than the current version and prioritize versions with push
for version_data in reversed(update_json["versions"]):
this_version = VersionNumber(version_data['versionNumber'])
push = version_data["push"].title() == "True"
if this_version > current_version:
found_version = version_data
if push:
break
if not found_version:
found_version = newest_version_data
push = found_version["push"].title() == "True"
if found_version['versionNumber'] > current_version and self.settings.get_update_info() and push:
title = "There is an update available"
text = (f"There is a newer version ({found_version.get('versionNumber')}) "
f"available.\nDo you want to open the link to the update?")
description = found_version.get("Description")
checkbox = QCheckBox("Do not show again")
msg_box = AdvancedQMessageBox(self, QMessageBox.Icon.Question, title, text, description, checkbox,
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.Yes)
msg_box.raise_()
retval = msg_box.exec()
if checkbox.isChecked():
print("Do not show again selected")
self.settings.set_update_info(False)
if retval == QMessageBox.StandardButton.Yes:
if found_version.get("updateUrl", "None").title() == "None":
link = update_json["metadata"].get("sorryUrl", "https://example.com")
else:
link = found_version.get("updateUrl")
QDesktopServices.openUrl(QUrl(link))
elif self.settings.get_no_update_info() and (push or found_version['versionNumber'] == current_version):
title = "Info"
text = (f"No new updates available.\nChecklist last updated "
f"{update_json['metadata']['lastUpdated'].replace('-', '.')}.")
description = f"v{found_version['versionNumber']}\n{found_version.get('description')}"
checkbox = QCheckBox("Do not show again")
msg_box = AdvancedQMessageBox(self, QMessageBox.Icon.Information, title, text, description, checkbox,
QMessageBox.StandardButton.Ok, QMessageBox.StandardButton.Ok)
msg_box.raise_()
msg_box.exec()
if checkbox.isChecked():
print("Do not show again selected")
self.settings.set_no_update_info(False)
elif self.settings.get_no_update_info() and not push:
title = "Info"
text = (f"New version available, but not recommended {found_version['versionNumber']}.\n"
f"Checklist last updated {update_json['metadata']['lastUpdated'].replace('-', '.')}.")
description = found_version.get("description")
checkbox = QCheckBox("Do not show again")
msg_box = AdvancedQMessageBox(self, QMessageBox.Icon.Information, title, text, description,
checkbox, QMessageBox.StandardButton.Ok, QMessageBox.StandardButton.Ok)
msg_box.raise_()
msg_box.exec()
if checkbox.isChecked():
print("Do not show again selected")
self.settings.set_no_update_info(False)
else:
print("Bug, please fix me.")
def setup_gui(self):
# Central Widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
self.window_layout = QVBoxLayout(central_widget)
# Scroll Area
self.scrollarea = QAdvancedSmoothScrollingArea(self, self.settings.get_scrolling_sensitivity())
self.scrollarea.setWidgetResizable(True)
self.scrollarea.verticalScrollBar().setSingleStep(24)
self.window_layout.addWidget(self.scrollarea)
# Content widgets
# content_widget = QWidget()
# self.scrollarea.setWidget(content_widget)
self.content_layout = self.scrollarea.content_layout # QVBoxLayout(content_widget)
# Enable kinetic scrolling
scroller = QScroller.scroller(self.scrollarea.viewport())
scroller.grabGesture(self.scrollarea.viewport(), QScroller.ScrollerGestureType.TouchGesture)
scroller_properties = QScrollerProperties(scroller.scrollerProperties())
scroller_properties.setScrollMetric(QScrollerProperties.ScrollMetric.MaximumVelocity, 0.3)
scroller.setScrollerProperties(scroller_properties)
# Add buttons at the end of the content, side by side
self.buttons_widget = QWidget()
buttons_layout = QHBoxLayout(self.buttons_widget)
previous_chapter_button = QPushButton("Previous")
buttons_layout.addWidget(previous_chapter_button)
next_chapter_button = QPushButton("Next")
buttons_layout.addWidget(next_chapter_button)
# Add a transparent image on the top left
self.transparent_image = QLabel(self)
self.transparent_image.setObjectName("transparentImage")
self.transparent_image.setPixmap(QPixmap(os.path.abspath(f"{self.data_folder}/empty.png")))
self.transparent_image.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft)
opacity = QGraphicsOpacityEffect(self.transparent_image)
opacity.setOpacity(0.5) # Adjust the opacity level
self.transparent_image.setGraphicsEffect(opacity)
self.transparent_image.setAttribute(Qt.WA_TransparentForMouseEvents, True)
# Search Toggle Button
self.search_bar_toggle_button = QPushButton("^", self)
self.search_bar_toggle_button.setFixedHeight(20) # Set fixed height, width will be set in resizeEvent
self.search_bar_toggle_button.move(0, 0)
# Search Bar
self.search_widget = SearchWidget(lambda: None)
self.search_widget.adjustSize()
self.search_widget.search_bar.setMinimumHeight(30)
self.search_widget.setMinimumHeight(30)
self.search_widget.move(0, -self.search_widget.height()) # Initially hide the search bar
self.search_widget.setParent(self)
# Search Bar Animation
self.search_bar_animation = QPropertyAnimation(self.search_widget, b"geometry")
self.search_bar_animation.setDuration(300)
# Side Menu
self.side_menu = QFrame(self)
self.side_menu.setObjectName("sideMenu")
self.side_menu.setFrameShape(QFrame.Shape.StyledPanel)
self.side_menu.setAutoFillBackground(True)
self.side_menu.move(int(self.width() * 2 / 3), 0)
self.side_menu.resize(int(self.width() / 3), self.height())
# Animation for Side Menu
self.side_menu_animation = QPropertyAnimation(self.side_menu, b"geometry")
self.side_menu_animation.setDuration(500)
# Side Menu Layout & Widgets
side_menu_layout = QFormLayout(self.side_menu)
self.side_menu.setLayout(side_menu_layout)
self.provider_combobox = CustomComboBox()
provider_layout = QHBoxLayout()
provider_layout.addWidget(QLabel("Provider:"))
provider_layout.addWidget(self.provider_combobox)
side_menu_layout.addRow(provider_layout)
title_layout = QHBoxLayout()
title_layout.addWidget(QLabel("Title:"))
self.title_selector = QLineEdit()
self.title_selector.setMinimumWidth(120)
title_layout.addWidget(self.title_selector)
side_menu_layout.addRow(title_layout)
self.chapter_selector = QLineEdit()
side_menu_layout.addRow(QLabel("Chapter:"), self.chapter_selector)
self.chapter_selector.setValidator(QDoubleValidator(0.5, 999.5, 1))
self.chapter_rate_selector = QLineEdit()
side_menu_layout.addRow(QLabel("Chapter Rate:"), self.chapter_rate_selector)
self.chapter_selector.setValidator(QDoubleValidator(0.1, 2, 1))
self.provider_type_combobox = QComboBox(self)
self.provider_type_combobox.addItem("Indirect", 0)
self.provider_type_combobox.addItem("Direct", 1)
side_menu_layout.addRow(self.provider_type_combobox, QLabel("Provider Type"))
previous_chapter_button_side_menu = QPushButton("Previous")
next_chapter_button_side_menu = QPushButton("Next")
self.reload_chapter_button = QPushButton(QIcon(f"{self.data_folder}/empty.png"), "")
self.reload_content_button = QPushButton(QIcon(f"{self.data_folder}/empty.png"), "")
side_menu_buttons_layout = QHBoxLayout()
side_menu_buttons_layout.addWidget(previous_chapter_button_side_menu)
side_menu_buttons_layout.addWidget(next_chapter_button_side_menu)
side_menu_buttons_layout.addWidget(self.reload_chapter_button)
side_menu_buttons_layout.addWidget(self.reload_content_button)
side_menu_layout.addRow(side_menu_buttons_layout)
[side_menu_layout.addRow(QWidget()) for _ in range(3)]
blacklist_button = QPushButton("Blacklist Current URL")
side_menu_layout.addRow(blacklist_button)
[side_menu_layout.addRow(QWidget()) for _ in range(3)]
self.hover_effect_all_checkbox = QCheckBox("Hover effect all")
self.borderless_checkbox = QCheckBox("Borderless")
hover_borderless_layout = QHBoxLayout()
hover_borderless_layout.setContentsMargins(0, 0, 0, 0)
hover_borderless_layout.addWidget(self.hover_effect_all_checkbox)
hover_borderless_layout.addWidget(self.borderless_checkbox)
self.acrylic_menus_checkbox = QCheckBox("Acrylic Menus")
self.acrylic_background_checkbox = QCheckBox("Acrylic Background")
acrylic_layout = QHBoxLayout()
acrylic_layout.setContentsMargins(0, 0, 0, 0)
acrylic_layout.addWidget(self.acrylic_menus_checkbox)
acrylic_layout.addWidget(self.acrylic_background_checkbox)
side_menu_layout.addRow(hover_borderless_layout)
side_menu_layout.addRow(acrylic_layout)
[side_menu_layout.addRow(QWidget()) for _ in range(3)]
# Scale checkboxes
self.downscale_checkbox = QCheckBox("Downscale if larger than window")
self.upscale_checkbox = QCheckBox("Upscale if smaller than window")
self.lazy_loading_checkbox = QCheckBox("LL")
lazy_loading_layout = QHBoxLayout()
lazy_loading_layout.setContentsMargins(0, 0, 0, 0)
lazy_loading_layout.addWidget(self.upscale_checkbox)
lazy_loading_layout.addWidget(self.lazy_loading_checkbox)
side_menu_layout.addRow(self.downscale_checkbox)
side_menu_layout.addRow(lazy_loading_layout)
# SpinBox for manual width input and Apply Button
self.manual_width_spinbox = QSpinBox()
self.manual_width_spinbox.setRange(10, 2000)
side_menu_layout.addRow(self.manual_width_spinbox)
apply_manual_width_button = QPushButton("Apply Width")
side_menu_layout.addRow(apply_manual_width_button)
[side_menu_layout.addRow(QWidget()) for _ in range(3)]
# Window style checkboxes
self.hide_title_bar_checkbox = QCheckBox("Hide titlebar")
self.hide_scrollbar_checkbox = QCheckBox("Hide Scrollbar")
hide_layout = QHBoxLayout()
hide_layout.setContentsMargins(0, 0, 0, 0)
hide_layout.addWidget(self.hide_title_bar_checkbox)
hide_layout.addWidget(self.hide_scrollbar_checkbox)
side_menu_layout.addRow(hide_layout)
self.stay_on_top_checkbox = QCheckBox("Stay on top")
side_menu_layout.addRow(self.stay_on_top_checkbox)
[side_menu_layout.addRow(QWidget()) for _ in range(3)]
self.scroll_sensitivity_scroll_bar = QScrollBar(Qt.Orientation.Horizontal)
self.scroll_sensitivity_scroll_bar.setMinimum(1) # QScrollBar uses integer values
self.scroll_sensitivity_scroll_bar.setMaximum(80) # We multiply by 10 to allow decimal
self.scroll_sensitivity_scroll_bar.setValue(10) # Default value set to 1.0 (10 in this scale)
self.scroll_sensitivity_scroll_bar.setSingleStep(1)
self.scroll_sensitivity_scroll_bar.setPageStep(1)
# Label to display the current sensitivity
self.sensitivity_label = QLabel("Current Sensitivity: 1.0")
side_menu_layout.addRow(self.sensitivity_label, self.scroll_sensitivity_scroll_bar)
[side_menu_layout.addRow(QWidget()) for _ in range(3)]
self.save_last_titles_checkbox = QCheckBox("Save last titles")
side_menu_layout.addRow(self.save_last_titles_checkbox)
export_settings_button = QPushButton("Export Settings")
advanced_settings_button = QPushButton("Adv Settings")
side_menu_layout.addRow(export_settings_button, advanced_settings_button)
# Menu Button
self.menu_button = QPushButton(QIcon(f"{self.data_folder}/empty.png"), "", self.centralWidget())
self.menu_button.setFixedSize(40, 40)
# Timer to regularly check for resizing needs
timer = QTimer(self)
timer.start(500)
# Connect GUI components
self.search_bar_toggle_button.clicked.connect(self.toggle_search_bar)
# Checkboxes
self.downscale_checkbox.toggled.connect(self.downscale_checkbox_toggled)
self.upscale_checkbox.toggled.connect(self.upscale_checkbox_toggled)
self.borderless_checkbox.toggled.connect(self.reload_borderless_setting)
self.acrylic_menus_checkbox.toggled.connect(self.reload_acrylic_menus_setting)
self.acrylic_background_checkbox.toggled.connect(self.reload_acrylic_background_setting)
self.hide_scrollbar_checkbox.toggled.connect(self.reload_hide_scrollbar_setting)
self.stay_on_top_checkbox.toggled.connect(self.reload_stay_on_top_setting)
self.hide_title_bar_checkbox.toggled.connect(self.reload_hide_titlebar_setting)
self.hover_effect_all_checkbox.toggled.connect(self.reload_hover_effect_all_setting)
self.save_last_titles_checkbox.toggled.connect(self.toggle_save_last_titles_checkbox)
# Selectors
self.title_selector.textChanged.connect(self.set_title)
self.chapter_selector.textChanged.connect(self.set_chapter)
self.chapter_rate_selector.textChanged.connect(self.set_chapter_rate)
# Menu components
self.menu_button.clicked.connect(self.toggle_side_menu) # Menu
apply_manual_width_button.clicked.connect(self.apply_manual_content_width) # Menu
previous_chapter_button.clicked.connect(self.previous_chapter) # Menu
next_chapter_button.clicked.connect(self.next_chapter) # Menu
self.reload_chapter_button.clicked.connect(self.reload_chapter) # Menu
self.reload_content_button.clicked.connect(self.reload) # Menu
previous_chapter_button_side_menu.clicked.connect(self.previous_chapter)
next_chapter_button_side_menu.clicked.connect(self.next_chapter)
advanced_settings_button.clicked.connect(self.advanced_settings) # Menu
export_settings_button.clicked.connect(self.export_settings) # Menu
blacklist_button.clicked.connect(self.blacklist_current_url) # Menu
# Rest
self.provider_combobox.currentIndexChanged.connect(self.change_provider) # Menu
self.provider_type_combobox.currentIndexChanged.connect(self.change_provider_type)
self.side_menu_animation.valueChanged.connect(self.side_menu_animation_value_changed) # Menu
timer.timeout.connect(self.timer_tick)
self.search_bar_animation.valueChanged.connect(self.search_bar_animation_value_changed)
self.search_widget.selectedItem.connect(self.selected_chosen_result)
self.scroll_sensitivity_scroll_bar.valueChanged.connect(self.update_sensitivity)
# Style GUI components
self.centralWidget().setStyleSheet("background: transparent;")
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
self.content_layout.setSpacing(0)
self.content_layout.setContentsMargins(0, 0, 0, 0)
self.menu_button.setIcon(QIcon(f"{self.data_folder}/menu_icon.png"))
if self.theme == "light":
self.reload_chapter_button.setIcon(QIcon(f"{self.data_folder}/reload_chapter_icon_dark.png"))
self.reload_content_button.setIcon(QIcon(f"{self.data_folder}/reload_icon_dark.png"))
else:
self.reload_chapter_button.setIcon(QIcon(f"{self.data_folder}/reload_chapter_icon_light.png"))
self.reload_content_button.setIcon(QIcon(f"{self.data_folder}/reload_icon_light.png"))
# Disable some components
blacklist_button.setEnabled(False)
# self.save_last_titles_checkbox.setEnabled(False)
# export_settings_button.setEnabled(False)
# advanced_settings_button.setEnabled(False)
def toggle_save_last_titles_checkbox(self):
self.settings.set_save_last_titles(self.save_last_titles_checkbox.isChecked())
def advanced_settings(self):
settings = self.settings.get_advanced_settings()
default_settings = json.loads(self.settings.get_default_setting("advanced_settings"))
self.settings.close()
available_themes = tuple(key for key in Themes.__dict__.keys() if not (key.startswith("__") or key.endswith("__")))
dialog = AdvancedSettingsDialog(parent=self, current_settings=settings, default_settings=default_settings, master=self, available_themes=available_themes)
dialog.exec()
if not self.settings.is_open:
self.settings.connect()
if dialog.selected_settings is not None:
self.settings.set_advanced_settings(dialog.selected_settings)
font = QFont(self.settings.get_advanced_settings().get("themes").get("font"), self.font().pointSize())
self.setFont(font)
for child in self.findChildren(QWidget):
child.setFont(font)
self.update()
self.repaint()
if settings["misc"]["num_workers"] != dialog.selected_settings["misc"]["num_workers"]:
self.switch_provider(self.provider_combobox.currentText())
if (settings["themes"]["light"] != dialog.selected_settings["themes"]["light"]
or settings["themes"]["dark"] != dialog.selected_settings["themes"]["dark"]):
result = QMessageBox.question(self, "Restart Client?",
"You must restart the client for the theme changes to take effect.\nDo you wish to continue?",
QMessageBox.StandardButtons(QMessageBox.Yes | QMessageBox.No),
QMessageBox.Yes)
if result == QMessageBox.Yes:
print("Exiting ...")
self.save_settings()
sys.stdout.close()
self.settings.close()
QApplication.exit(1000)
@staticmethod
def fetch_all_data_as_json(db_file, return_dict: bool = False):
# Connect to the SQLite database
connection = sqlite3.connect(db_file)
cursor = connection.cursor()
try:
# Get all table names
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
# Dictionary to hold data from all tables
all_data = {}
for table_name in tables:
table_name = table_name[0]
cursor.execute(f"SELECT * FROM {table_name}")
# Fetch rows as dictionaries
rows = cursor.fetchall()
columns = [description[0] for description in cursor.description]
all_data[table_name] = [dict(zip(columns, row)) for row in rows]
if not return_dict:
# Convert all data to JSON string
json_data = json.dumps(all_data, indent=4)
return json_data
else:
return all_data
finally:
# Close the cursor and connection
cursor.close()
connection.close()
@classmethod
def merge_dicts(cls, original, new):
""" Recursively merge two dictionaries. """
for key, value in new.items():
if isinstance(value, dict) and value.get(key):
cls.merge_dicts(original.get(key, {}), value)
else:
original[key] = value
return original
@classmethod
def modify_json_file(cls, original_loc, new_data):
""" Modify a JSON file with new data. """
with open(original_loc, 'r+') as file:
existing_data = json.load(file)
updated_data = cls.merge_dicts(existing_data, new_data)
file.seek(0)
file.write(json.dumps(updated_data, indent=4))
file.truncate()
@staticmethod
def modify_sqlite_db(db_path, updates):
"""
Modify an SQLite database to update or insert settings.
:param db_path: Path to the SQLite database file.
:param updates: A dictionary containing key-value pairs to update or insert.
"""
# Connect to the SQLite database
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
# Ensuring the table exists
cursor.execute("""
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT
);
""")
# Prepare the SQL for updating or inserting settings
for key, value in updates.items():
cursor.execute("""
INSERT INTO settings(key, value)
VALUES (?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value;
""", (key, value))
# Commit the changes and close the connection
connection.commit()
cursor.close()
connection.close()
def export_settings(self):
sett = self.settings.get_advanced_settings()
loc = sett.get("settings_file_path")
mode = sett.get("settings_file_mode")
if not os.path.isfile(loc) and os.path.exists(loc):
return
is_db_file = loc.endswith(".db")
is_json_file = loc.endswith((".json", ".yaml", ".yml"))
if mode == "overwrite":
if os.path.exists(loc):
os.remove(loc)
if is_db_file:
shutil.copyfile(f"{self.data_folder}/data.db", loc)
elif is_json_file:
with open(loc, "w") as f:
f.write(self.fetch_all_data_as_json(f"{self.data_folder}/data.db"))
elif mode == "modify":
if is_db_file:
self.modify_sqlite_db(loc, self.fetch_all_data_as_json(f"{self.data_folder}/data.db", return_dict=True))
elif is_json_file:
new_data = self.fetch_all_data_as_json(f"{self.data_folder}/data.db", return_dict=True)
self.modify_json_file(loc, new_data)
else:
if not os.path.exists(loc):
if is_db_file:
shutil.copyfile(f"{self.data_folder}/data.db", loc)
elif is_json_file:
with open(loc, "w") as f:
f.write(self.fetch_all_data_as_json(f"{self.data_folder}/data.db"))
def switch_provider(self, name: str):
provider_name = f"AutoProviderPlugin{name}"
if provider_name not in self.provider_dict:
provider_name = f"AutoProviderPlugin{self.settings.get_default_setting('provider')}"
provider_cls = self.provider_dict[provider_name]
self.provider = provider_cls(self.settings.get_title(), self.settings.get_chapter(),
self.settings.get_chapter_rate(), self.data_folder, self.cache_folder,
self.settings.get_provider_type(), num_workers=self.settings.get_advanced_settings()["misc"]["num_workers"])
self.provider.set_blacklisted_websites(self.settings.get_blacklisted_websites())
if self.provider.get_search_results(None):
self.search_widget.set_search_results_func(self.provider.get_search_results)
self.search_widget.setEnabled(True) # self.search_toggle_button.setEnabled(False)
else:
self.search_widget.setEnabled(False) # self.search_toggle_button.setEnabled(False)
new_pixmap = QPixmap(os.path.abspath(self.provider.get_logo_path()))
self.transparent_image.setPixmap(new_pixmap)
self.update_provider_logo()
def reload_window_title(self):
new_title = ' '.join(word[0].upper() + word[1:] if word else '' for word in self.provider.get_title().split())
self.setWindowTitle(f'MV 166 | {new_title}, Chapter {self.provider.get_chapter()}')
def get_content_paths(self, allowed_file_formats: tuple = None):
if allowed_file_formats is None:
allowed_file_formats = ('.png', ".jpg", ".jpeg", ".webp", ".http", '.mp4', '.txt')
content_files = sorted([f for f in os.listdir(self.cache_folder) if
f.endswith(allowed_file_formats)])
content_paths = [os.path.join(self.cache_folder, f) for f in content_files]
return content_paths
# Helper Functions
def reload_hide_titlebar_setting(self):
if self.hide_title_bar_checkbox.isChecked():
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
else:
self.setWindowFlags(
self.windowFlags() & ~Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint)
self.settings.set_hide_titlebar(self.hide_title_bar_checkbox.isChecked())
self.show()
def deepen_color(self, color, darken_factor=100, saturation_factor=1.3):
# Increase saturation and darken the color
# Convert to HSL for control over lightness and saturation
color = color.toHsl()
deepened_color = color.darker(darken_factor) # 100 is original, higher values are darker
# Optionally adjust saturation using HSV
deepened_color = deepened_color.toHsv()
deepened_color.setHsv(deepened_color.hue(),
min(255, int(deepened_color.saturation() * saturation_factor)),
deepened_color.value())
return deepened_color
def reload_hover_effect_all_setting(self, callback: bool = False):
style_sheet = """\nQPushButton:hover,\nQListWidget:hover,\nQSpinBox:hover,\nQLabel:hover,
QComboBox:hover,\nQLineEdit:hover,\nQCheckBox:hover,\nQScrollBar:hover"""
if self.hover_effect_all_checkbox.isChecked():
bg_color = self.deepen_color(self.menu_button.palette().color(self.menu_button.backgroundRole()), darken_factor=120)
if self.acrylic_menus_checkbox.isChecked():
bg_color.setAlpha(30)
defbg_color = self.menu_button.palette().color(self.menu_button.backgroundRole())
defbg_color.setAlpha(30)
if self.theme == "light":
style_sheet_non_transparent = style_sheet + f" {{background-color: {bg_color.name(QColor.HexArgb)};}}"
style_sheet += f" {{background-color: {defbg_color.name(QColor.HexArgb)};}}"
else:
style_sheet_non_transparent = style_sheet + f" {{background-color: {bg_color.name(QColor.HexArgb)};}}"
style_sheet += f" {{background-color: {defbg_color.name(QColor.HexArgb)};}}"
self.menu_button.setStyleSheet(self.menu_button.styleSheet() + style_sheet_non_transparent)
self.side_menu.setStyleSheet(self.side_menu.styleSheet() + style_sheet)
self.search_bar_toggle_button.setStyleSheet(self.search_bar_toggle_button.styleSheet() + style_sheet_non_transparent)
# self.search_widget.setStyleSheet(self.search_widget.styleSheet() + style_sheet_non_transparent)
# self.search_widget.search_bar.setStyleSheet(self.search_widget.styleSheet() + style_sheet_non_transparent)
self.buttons_widget.setStyleSheet(self.buttons_widget.styleSheet() + style_sheet_non_transparent)
else:
self.menu_button.setStyleSheet("")
self.side_menu.setStyleSheet("")
self.search_bar_toggle_button.setStyleSheet("")
# self.search_widget.setStyleSheet("")
# self.search_widget.search_bar.setStyleSheet("")
self.buttons_widget.setStyleSheet("")
# if self.theme == "light":
# style_sheet += " {background-color: rgba(85, 85, 85, 30%);}"
# else:
# style_sheet += " {background-color: rgba(192, 192, 192, 30%);}"
# for widget in [self.centralWidget(), self.side_menu, self.search_bar_toggle_button, self.search_widget,
# self.buttons_widget]:
# original_style_sheet = widget.styleSheet().removesuffix(style_sheet)
# widget.setStyleSheet(original_style_sheet)
if not callback:
self.reload_acrylic_menus_setting(callback=True)
self.settings.set_hover_effect_all(self.hover_effect_all_checkbox.isChecked())
def reload_borderless_setting(self):
if self.borderless_checkbox.isChecked():
# Set the central layout margins and spacing to 0
self.window_layout.setContentsMargins(0, 0, 0, 0)
self.window_layout.setSpacing(0)
else:
# Set the central layout margins and spacing to 0
self.window_layout.setContentsMargins(9, 9, 9, 9)
self.window_layout.setSpacing(6)
self.settings.set_borderless(self.borderless_checkbox.isChecked())
def reload_acrylic_menus_setting(self, callback: bool = False):
if self.acrylic_menus_checkbox.isChecked():
style_sheet = "\nQPushButton:hover,\nQComboBox:hover"
bg_color = self.menu_button.palette().color(self.menu_button.backgroundRole())
bg_color.setAlpha(30)
deep_bg_color = self.deepen_color(bg_color)
if self.theme == "light":
style_sheet = (f"* {{background-color: {bg_color.name(QColor.HexArgb)};}}"
+ style_sheet + f" {{background-color: {deep_bg_color.name(QColor.HexArgb)};}}")
else:
style_sheet = (f"* {{background-color: rgba( 0, 0, 0, 30% );}}"
+ style_sheet + f" {{background-color: {deep_bg_color.name(QColor.HexArgb)};}}")
self.centralWidget().setStyleSheet(style_sheet)
self.side_menu.setStyleSheet(style_sheet)
self.search_bar_toggle_button.setStyleSheet(style_sheet)
self.search_widget.setStyleSheet(style_sheet)
self.search_widget.search_bar.setStyleSheet(style_sheet)
self.buttons_widget.setStyleSheet(style_sheet)
else:
self.centralWidget().setStyleSheet("")
self.side_menu.setStyleSheet("")
self.search_bar_toggle_button.setStyleSheet("")
self.search_widget.setStyleSheet("")
self.search_widget.search_bar.setStyleSheet("")
self.buttons_widget.setStyleSheet("")
if not callback:
self.reload_hover_effect_all_setting(callback=True)
self.settings.set_acrylic_menus(self.acrylic_menus_checkbox.isChecked())
def reload_acrylic_background_setting(self):
if self.acrylic_background_checkbox.isChecked():
self.setWindowOpacity(0.8)
else:
self.setWindowOpacity(1.0)
self.settings.set_acrylic_background(self.acrylic_background_checkbox.isChecked())
def reload_hide_scrollbar_setting(self):
if self.hide_scrollbar_checkbox.isChecked():
self.scrollarea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.scrollarea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
else:
self.scrollarea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.scrollarea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.settings.set_hide_scrollbar(self.hide_scrollbar_checkbox.isChecked())
def reload_stay_on_top_setting(self):
if self.stay_on_top_checkbox.isChecked():
self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
else:
self.setWindowFlags(
self.windowFlags() & ~Qt.WindowStaysOnTopHint | Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint)
self.settings.set_stay_on_top(self.stay_on_top_checkbox.isChecked())
self.show()
def downscale_checkbox_toggled(self):
self.settings.set_downscaling(self.downscale_checkbox.isChecked())
self.downscaling = self.downscale_checkbox.isChecked()
self.force_rescale = True
def upscale_checkbox_toggled(self):
self.settings.set_upscaling(self.upscale_checkbox.isChecked())
self.upscaling = self.upscale_checkbox.isChecked()
self.force_rescale = True
def apply_manual_content_width(self):
self.settings.set_manual_content_width(self.manual_width_spinbox.value())
self.force_rescale = True
def set_title(self):
new_title = self.title_selector.text().strip()
self.settings.set_title(new_title)
self.provider.set_title(new_title)
def set_chapter(self):
new_chapter = float("0" + self.chapter_selector.text())
if 0.0 <= new_chapter < 1000.0:
self.provider.set_chapter(new_chapter)
else:
self.provider.set_chapter(0)
self.chapter_selector.setText("0")
def set_chapter_rate(self):
new_chapter_rate = float("0" + self.chapter_rate_selector.text())
if 0.1 <= new_chapter_rate <= 2.0:
self.settings.set_chapter_rate(new_chapter_rate)
self.provider.set_chapter_rate(new_chapter_rate)
self.chapter_rate_selector.setText(str(new_chapter_rate))
else:
self.settings.set_chapter_rate(0.1)
self.provider.set_chapter_rate(0.1)
self.chapter_rate_selector.setText("0.1")
def update_sensitivity(self, value):
sensitivity = value / 10
self.settings.set_scrolling_sensitivity(sensitivity)
self.sensitivity_label.setText(f"Current Sensitivity: {sensitivity:.1f}")
self.scrollarea.sensitivity = sensitivity
def selected_chosen_result(self, new_title, toggle_search_bar: bool = True):
self.title_selector.setText(new_title)
self.title_selector.textChanged.emit(new_title)
self.chapter_selector.setText("1")
self.chapter_selector.textChanged.emit("1")
self.settings.set_chapter(1)
self.reload_chapter()
if toggle_search_bar:
self.toggle_search_bar()
self.save_last_title(self.provider.get_title())
def save_last_title(self, title):
if self.settings.get_save_last_titles():
sett = self.settings.get_advanced_settings()
title = title.lower()
print(title)
if title in sett["recent_titles"]:
sett["recent_titles"].remove(title)
sett["recent_titles"].append(title)
self.settings.set_advanced_settings(sett)
def change_provider_type(self):
self.settings.set_provider_type(self.provider_type_combobox.currentText().lower())
self.provider.set_provider_type(self.settings.get_provider_type())
def blacklist_current_url(self):
blk_urls = self.provider.get_blacklisted_websites() + [urlparse(self.provider.get_current_url()).netloc]
self.provider.set_blacklisted_websites(blk_urls)
self.settings.set_blacklisted_websites(self.provider.get_blacklisted_websites())
def change_provider(self, *args, callback: bool = False):
if not callback:
self.previous_provider = self.provider
self.switch_provider(self.provider_combobox.currentText())
if not callback:
QTimer.singleShot(50, self.change_provider_callback)
def change_provider_callback(self):
self.change_provider(callback=True)
print("PREV", self.previous_provider, "->", self.provider)
if type(self.provider) is not type(self.previous_provider):
self.provider.redo_prep()
self.reload_content()
# Dynamic movement methods
def toggle_search_bar(self):
is_visible = self.search_widget.y() >= 0
if is_visible:
end_rect = QRect(0, -self.search_widget.height(), self.search_widget.width(), self.search_widget.height())
else:
end_rect = QRect(0, self.search_bar_toggle_button.height() - 20, self.search_widget.width(),
self.search_widget.height())
self.search_bar_animation.setStartValue(self.search_widget.geometry())
self.search_bar_animation.setEndValue(end_rect)
self.search_bar_animation.start()
def search_bar_animation_value_changed(self, value):
move_value = value.y() + self.search_widget.height()
self.search_bar_toggle_button.move(0, move_value)
self.update_menu_button_position(value2=move_value)
def toggle_side_menu(self):
width = max(200, int(self.width() / 3))
height = self.height()
if self.side_menu.x() >= self.width():
start_value = QRect(self.width(), 0, width, height)
end_value = QRect(self.width() - width, 0, width, height)
else:
start_value = QRect(self.width() - width, 0, width, height)
end_value = QRect(self.width(), 0, width, height)
self.side_menu_animation.setStartValue(start_value)
self.side_menu_animation.setEndValue(end_value)
self.side_menu_animation.start()
def update_menu_button_position(self, value=None, value2=None):
if not value:
value = self.side_menu.x()
else:
value = value.x()
if not value2: value2 = self.search_widget.y() + self.search_widget.height()
self.menu_button.move(value - self.menu_button.width(), (20 + value2 if value2 >= 0 else 20))
def update_search_geometry(self, value):
self.search_bar_toggle_button.setFixedWidth(value.x()) # Adjust the width of the toggle button
self.search_widget.setFixedWidth(value.x()) # Adjust the width of the search bar
def side_menu_animation_value_changed(self, value):
self.update_menu_button_position(value)
self.update_search_geometry(value)
# Window management methods
def update_font_size(self):
if self.width() <= 800:
new_font_size = min(max(6, math.log(self.width() * 4)), 14)
else:
new_font_size = min(max(6, self.width() // 80), 14)
font = QFont()
font.setPointSize(new_font_size)
self.setFont(font)
# print(self.side_menu.children())
for widget in self.side_menu.children():
if hasattr(widget, "setFont"):
widget.setFont(font)
# print(type(widget).__name__) # Debug
def update_provider_logo(self):
max_size = self.width() // 3
min_size = self.width() // 10
content_width = self.transparent_image.pixmap().width() if self.transparent_image.pixmap() else 0 # Adjust the size of the transparent image based on window width
if not min_size <= content_width <= max_size: # If the current image width is outside the min and max size range, resize it
scaled_pixmap = QPixmap(os.path.abspath(self.provider.get_logo_path())).scaledToWidth(max_size, Qt.SmoothTransformation)
self.transparent_image.setPixmap(scaled_pixmap)
self.transparent_image.setFixedSize(max_size, max_size)
# Rest
def reload_providers(self):
provider_manager = AutoProviderManager(self.extensions_folder, AutoProviderPlugin, [
AutoProviderPlugin, AutoProviderBaseLike, AutoProviderBaseLike2])
self.provider_dict = provider_manager.get_providers()
self.provider_combobox.clear()
for i, provider_name in enumerate(self.provider_dict.keys()):
provider = self.provider_dict[provider_name]("", 1, 0.5, self.data_folder, self.cache_folder, "direct")
icon_path = provider.get_logo_path()
image = QImage(os.path.abspath(icon_path))
if provider.clipping_space is not None:
start_x, start_y, end_x, end_y = provider.clipping_space
print("Cropping", image.height(), "x", image.width(), "for", provider_name)
cropped_image = image.copy(start_y if start_y != "max" else image.width(),
start_x if start_x != "max" else image.height(),
end_y if end_y != "max" else image.width(),
end_x if end_x != "max" else image.height())
else:
print("Cube cropping", image.height(), "for", provider_name)
cropped_image = image.copy(0, 0, image.height(), image.height())
icon = QIcon(QPixmap.fromImage(cropped_image))
# Add item to the dropdown
self.provider_combobox.addItem(icon, provider_name.replace("AutoProviderPlugin", ""))
if "AutoProviderPlugin" not in provider_name:
self.provider_combobox.setItemUnselectable(i)
self.provider_combobox.setCurrentText(self.settings.get_provider())
def save_settings(self):
if hasattr(self, "settings") and self.settings.is_open:
self.settings.set_provider(self.provider_combobox.currentText())
self.settings.set_title(self.provider.get_title())
self.settings.set_chapter(self.provider.get_chapter())
self.settings.set_chapter_rate(self.provider.get_chapter_rate())
self.settings.set_provider_type(self.provider.get_provider_type())
self.settings.set_blacklisted_websites(self.provider.get_blacklisted_websites())
self.settings.set_hover_effect_all(self.hover_effect_all_checkbox.isChecked())
self.settings.set_borderless(self.borderless_checkbox.isChecked())
self.settings.set_acrylic_menus(self.acrylic_menus_checkbox.isChecked())
self.settings.set_acrylic_background(self.acrylic_background_checkbox.isChecked())