-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathmain.py
More file actions
1733 lines (1393 loc) · 73 KB
/
Copy pathmain.py
File metadata and controls
1733 lines (1393 loc) · 73 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
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 (C) 2023-2026 Johannes Habel
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 <https://www.gnu.org/licenses/>.
Contact:
E-Mail: EchterAlsFake@proton.me
Discord: echteralsfake (faster response)
"""
import os
import sys
import tempfile
from string import Template
# Pre-Load PySide6 to show a loading splashscreen
from PySide6.QtWidgets import QApplication
from backend.clients import AllowedVideoType
app = QApplication(sys.argv)
# macOS Setup...
if sys.platform == "darwin":
from src.backend.macos_setup import macos_setup
from src.backend.update_service import SparkleUpdater
macos_setup()
# Handles Sparkle Updates + macOS Installation
# Necessary imports for splashscreen
import src.frontend.UI.resources # This may not seem to be used, but it needs to be imported!
from PySide6.QtGui import QPixmap
from src.frontend.UI.splashscreen import ModernSplashScreen
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
os.environ["QT_QUICK_CONTROLS_MATERIAL_THEME"] = "Dark"
splash_pixmap = QPixmap(":/images/graphics/splashscreen.png")
splash = ModernSplashScreen(splash_pixmap)
splash.show() # Starts showing the actual Splash Screen
app.processEvents()
if "NUITKA_ONEFILE_PARENT" in os.environ:
splash_filename = os.path.join(
tempfile.gettempdir(),
f"onefile_{int(os.environ['NUITKA_ONEFILE_PARENT'])}_splash_feedback.tmp"
)
if os.path.exists(splash_filename):
os.unlink(splash_filename)
# Stops the Nuitka Splash Screen
splash.showMessage("Importing (General).")
app.processEvents()
# General imports
import re
import time
import uuid
import logging
import asyncio
import argparse
import markdown
import traceback
import webbrowser
from pathlib import Path
from datetime import datetime
from threading import Event, Lock
from asyncstdlib import islice, chain
from typing import AsyncGenerator, AsyncIterator
splash.showMessage("Importing (PySide6).")
app.processEvents()
# Qt / PySide6 related imports
import PySide6.QtAsyncio as QtAsyncio # Needed because porn fetch's network backend is now async since v3.9
from PySide6.QtQuickWidgets import QQuickWidget
from PySide6.QtQml import QQmlEngine
from PySide6.QtGui import QIcon, QFontDatabase, QPixmap, QShortcut, QKeySequence
from PySide6.QtCore import (QTextStream, QRunnable, QLocale, QSize, QUrl, Signal, QFile, Slot,
QTranslator, QCoreApplication, QStandardPaths, QObject, Qt, QSettings)
from PySide6.QtWidgets import (QTreeWidgetItem, QButtonGroup, QFileDialog, QHeaderView, QSizePolicy, QLayout,
QInputDialog, QMainWindow, QProgressBar, QComboBox, QWidget, QPushButton,
QHBoxLayout)
splash.showMessage("Importing (Backend).")
app.processEvents()
# Backend imports
from src.backend import clients # Singleton instance for the client objects (really important)
import src.backend.config as config
from src.backend.check_license import LicenseManager
import src.backend.shared_functions as shared_functions
from src.backend.database import save_video_metadata, init_db
from src.backend.config import (__version__, PUBLIC_KEY_B64, IS_SOURCE_RUN, TEMP_DIRECTORY,
TEMP_DIRECTORY_STATES, TEMP_DIRECTORY_SEGMENTS, app_settings)
from src.backend.shared_functions import handle_error_gracefully
from src.backend.shared_gui import (ui_popup, reset_pornfetch, Signals,
available_title_formatting_options, on_checkbox_clicked)
from src.backend.helper_functions import (default_license_path, safe_rmtree, make_debug_log, get_widget_value,
set_widget_value)
from src.backend.installation import InstallPornFetch
from src.backend.uninstallation import UninstallPornFetch
from src.backend.errors import (UnsupportedPlatform, AppDownloadFailed, AppNetworkError, AppNotFoundError,
AppBotBlocked, safe_api_call)
from src.backend.download_manager import DownloadManager, VideoObject, VideoFilters
splash.showMessage("Importing (Frontend).")
app.processEvents()
# Frontend imports
from src.frontend.UI.ui_form_main_window import Ui_PornFetch_UI
from src.frontend.UI.custom_combo_box import ComboPopupFitter, make_quality_combobox
from src.frontend.UI.theme import (apply_theme, apply_theme_light, mark, install_focus_outline,
pretty_combo)
from src.frontend.translations.strings import (TRANSLATE_MAIN, TRANSLATE_PAGE_DOWNLOAD, TRANSLATE_PAGE_LOGIN,
TRANSLATE_PAGE_SETTINGS, TRANSLATE_ERRORS)
splash.showMessage("Importing (APIs).")
app.processEvents()
# Errors from different APIs
from base_api.modules.errors import (ProxySSLError, InvalidProxy, AccessDeniedError, BotProtectionDetected,
SecurityAbort, RateLimitError, ChallengeMathError, DataNotLoadedError)
from pornhub_api.modules.errors import VideoDisabled, GifPendingReview
splash.showMessage("Importing (AV - FFMPEG).")
app.processEvents()
try:
from av import open as av_open # Don't ask
from av.audio.resampler import AudioResampler # Don't ask
FORCE_DISABLE_AV = False
except Exception:
FORCE_DISABLE_AV = True
qml_engine = QQmlEngine()
qml_engine.rootContext().setContextProperty("appSettings", app_settings)
FORCE_PORTABLE_RUN: bool = False # Holds a value for argparse later (see main function)
total_segments: int = 0 # Total segments kept in a queue (for total progress tracking)
downloaded_segments: int = 0 # Amount of segments that have been downloaded (for total progress tracking)
total_downloaded_videos: int = 0 # All videos that actually successfully downloaded
session_urls: list = [] # This list saves all URLs used in the current session. Used for the URL export function (CTRL + E)
logger = shared_functions.configure_app_logging(logger_name="Porn Fetch - [MAIN]", log_file="PornFetch.log", level=logging.DEBUG)
license_storage_path: str = os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppConfigLocation), "pornfetch.license")
last_index = 0 # Tracks the last index of the tree widget in case the user does not have auto-clear enabled
x: bool = False # Don't ask (this is a secret ;)
w = None
class ProcessVideos(QObject):
error_signal = Signal(str)
"""
This class is responsible for processing the videos in the background, loading the data, adjusting paths and
handling errors
"""
def __init__(self, iterator: AsyncGenerator, custom_path_options: str, max_attempts: int,
download_manager: DownloadManager, reverse_videos: bool, stop_flag: asyncio.Event, output_path: Path,
video_filters: VideoFilters, result_limit: int) -> None:
super().__init__()
self.iterator = iterator
self.custom_path_options = custom_path_options
self.max_attempts = max_attempts
self.download_manager = download_manager
self.reverse_videos = reverse_videos
self.stop_flag = stop_flag
self.output_path = output_path
self.video_filters = video_filters
self.result_limit = result_limit
@staticmethod
async def reverse_iterator(iterator: AsyncIterator):
videos = []
async for video in iterator:
videos.append(video) # This is very stupid, please don't use this „feature"!
return videos.reverse()
def process_filter(self, filters: VideoFilters, attributes: VideoObject) -> bool:
# 1. Duration Filters
if filters.duration_minimum is not None or filters.duration_maximum is not None:
if filters.duration_minimum is not None and attributes.length < filters.duration_minimum:
return False
if filters.duration_maximum is not None and attributes.length > filters.duration_maximum:
return False
# 2. Regex Filters
if filters.author_regex:
if not re.search(filters.author_regex, attributes.author, re.IGNORECASE):
return False
if filters.title_regex:
if not re.search(filters.title_regex, attributes.title, re.IGNORECASE):
return False
if filters.tags_regex:
# Fails immediately if the video has no tags to match against
if not attributes.tags:
return False
pattern = re.compile(filters.tags_regex, re.IGNORECASE)
# Passes if at least one tag matches the regex
if not any(pattern.search(tag) for tag in attributes.tags):
return False
# 3. Quality Filters (Evaluated based on the highest available quality)
if filters.quality_minimum or filters.quality_maximum:
max_quality = self._get_max_quality(attributes.qualities)
if filters.quality_minimum:
min_q = self._parse_quality(filters.quality_minimum)
if max_quality < min_q:
return False
if filters.quality_maximum:
max_q = self._parse_quality(filters.quality_maximum)
if max_quality > max_q:
return False
# 4. Date Filters
if filters.published_after:
# .replace(tzinfo=None) safely handles timezone-aware datetimes for comparison
after_date = datetime.fromisoformat(filters.published_after).replace(tzinfo=None)
pub_date = attributes.publish_date.replace(tzinfo=None)
if pub_date < after_date:
return False
if filters.published_before:
before_date = datetime.fromisoformat(filters.published_before).replace(tzinfo=None)
pub_date = attributes.publish_date.replace(tzinfo=None)
if pub_date > before_date:
return False
# If it survives all the checks, all applied filters are True!
return True
@staticmethod
def _parse_quality(quality_str: str) -> int:
"""Extracts the integer resolution from strings like '1080p', '720', '4K'."""
if not quality_str:
return 0
# Simple handler for "4k" edge cases
if quality_str.lower() == "4k":
return 2160
# Strips all non-digit characters (e.g., "1080p60" -> 108060, so we just grab the resolution part safely)
# Assuming typical formats like "1080p", "720p"
match = re.search(r'\d+', quality_str)
return int(match.group()) if match else 0
def _get_max_quality(self, qualities: list[str]) -> int:
"""Finds the highest resolution available in the list of qualities."""
if not qualities:
return 0
parsed_qualities = [self._parse_quality(q) for q in qualities]
return max(parsed_qualities)
@staticmethod
async def process_single_video(video_object: str | AllowedVideoType) -> tuple[AllowedVideoType, VideoObject]:
video = await clients.get_video(video_object)
video_attributes = await clients.load_video_attributes(video=video)
return video, video_attributes
def create_output_path(self, video_attributes: VideoObject, index: int, user_pattern: str) -> Path:
base_path = self.output_path
context = {
"output_path": base_path,
"author": video_attributes.author,
"title": video_attributes.title,
"video_id": video_attributes.video_id,
"index": f"{index:02d}", # Zero-padded index (01, 02, etc.)
"publish_date": video_attributes.publish_date,
"length": video_attributes.length,
}
template = Template(user_pattern)
resolved_string = template.safe_substitute(context)
return Path(resolved_string).expanduser()
async def start_processing(self):
global last_index
logger.info("Starting Processing of Iterator!")
self.iterator = islice(self.iterator, self.result_limit)
if self.reverse_videos:
self.iterator = self.reverse_iterator(self.iterator)
async for idx, video in shared_functions.aenumerate(self.iterator):
last_error = None # Keeps track of the
if self.stop_flag.is_set():
return # User hit the abort button
try:
logger.debug(f"Current Index: {idx}")
video, video_object = await safe_api_call(self.process_single_video, video)
logger.info("Checking Filters...")
if self.process_filter(self.video_filters, video_object):
identifier = uuid.uuid4().hex
logger.info(f"Successfully received Video! [Identifier ->: {identifier}]")
output_path = self.create_output_path(video_object, idx, self.custom_path_options)
video_object.output_path = output_path
video_object.identifier = identifier
self.download_manager.add_video(video_object)
last_index += 1
# General Errors
except AppNetworkError as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message="""
A network error happened, I'll try retrying...""")
continue # Maybe it solves by itself ;)
except AppNotFoundError as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message="""
I was trying to access a website, but turns out, it doesn't exist. Please verify if you entered
the correct URL.
If you are sure you did, please report this issue
""")
break # If the resource is not there, it won't magically appear lmao
except (VideoDisabled, GifPendingReview) as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message="""
The Video / GIF seems to be disabled or pending a review! It can't be downloaded (yet) :(
""")
break
except (SecurityAbort, ChallengeMathError, ChallengeMathError) as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message="""
An error occurred while solving a challenge from PornHub, please report this immediately, I need to
fix this quickly!""")
break
except RateLimitError as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message="""
You got rate limited by the server. I have already tried solving this, which didn't work.
Please use a (different) proxy or VPN.""")
break
except DataNotLoadedError as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message=f"""
If you see this I fucked up developing my API packages and you should immediately open an issue on
GitHub lol""")
break
except (AccessDeniedError, BotProtectionDetected, AppBotBlocked) as e:
last_error = make_debug_log(e=e, video_url=video.url, function="start_processing", user_message="""
The website denied access, probably because it detected you as a bot. Please report this, as I probably
need to update the headers.
""")
finally:
self.error_signal.emit(last_error)
class PornFetch(QMainWindow):
COL_DOWNLOAD = 0
COL_TITLE = 1
COL_AUTHOR = 2
COL_LENGTH = 3
COL_QUALITY = 4
COL_STOP = 5
COL_PROGRESS = 6
def __init__(self, parent=None):
super().__init__(parent)
self.settings = None
self.last_update_time = time.time()
self.signals = Signals()
self.signals.error_signal.connect(ui_popup)
self.download_manager = DownloadManager() # Used to track all videos
#self.download_manager.video_added.connect() # TODO
self.update_app_font(app_settings.font_size)
app_settings.fontSizeChanged.connect(self.update_app_font)
app_settings.themeChanged.connect(self.theme_changed)
self.ui = Ui_PornFetch_UI()
self.ui.setupUi(self)
self.logger = shared_functions.configure_app_logging(logger_name="Porn Fetch - [PornFetch]", log_file="PornFetch.log", level=logging.DEBUG)
# Inject the Settings QML Widget
settings_widget = QQuickWidget(qml_engine, self)
settings_widget.rootContext().setContextProperty("appSettings", app_settings)
settings_widget.setClearColor(Qt.GlobalColor.transparent)
settings_widget.setResizeMode(QQuickWidget.ResizeMode.SizeRootObjectToView)
settings_widget.setSource(QUrl.fromLocalFile("src/frontend/UI/Settings.qml"))
self.ui.settings_vlayout_1.addWidget(settings_widget)
self.last_index = 0 # Keeps track of the last index of videos added to the tree widget
self._anonymous_mode = False
#self.ensure_temp()
#self._row = {} # Video ID -> dict of widgets + state
self.load_style()
#self._setup_modern_tabs()
#self.load_strings()
#self.license_manager = LicenseManager(storage_path=default_license_path(), public_key_b64=PUBLIC_KEY_B64)
#self.setup_license_restrictions()
"""
! INDEX LIST !
0) Main application (downloading, login, tree widget etc.)
:: Index list for main application ::
- 0: Download
- 1: Login
- 2: Tools (removed)
- 3: Progressbars
- 4: Range selector
1) Settings
2) Credits
3) License
4) Keyboard Shortcuts
5) Install Dialog
6) Supported websites
7) Donation Nag
8) Disclaimer text
9) One-Time Information
10) Batch Feature (Not implemented yet)
This may look a little bit confusing, but once you understand it, it makes sense, trust me :)
"""
#self.default_max_height = self.ui.main_stacked_widget_top.maximumHeight()
self.button_connections() # Connects the buttons to their functions
#self.shortcuts() # Activates the keyboard shortcuts
#self.logger.debug("Startup: [3/5] Initialized the User Interface")
#self.load_user_settings() # Loads the user settings and applies selected values to the UI
#self.app_config = config.SettingsManager()
#self.logger.debug("Startup: [4/5] Loaded the user settings")
#self.download_scheduler = DownloadScheduler(self.app_config, self)
#self.download_scheduler.worker_started.connect(self._wire_worker_signals)
#self.progress_widgets = {} # video_id -> {'label': QLabel, 'progressbar': QProgressBar}
#if config.app_settings.update_checks:
# self.logger.info("Running update checks")
# self.check_for_updates()
#if config.app_settings.anonymous_mode:
# self.logger.info("Enabling anonymous mode")
# self.anonymous_mode()
#self.semaphore = asyncio.Semaphore(config.app_settings.parallel_downloads)
#self.logger.debug("Startup: [5/5] OK")
#self.initialize_pornfetch()
"""
The following functions just switch the Stacked Widget to the different widgets
"""
"""Stacked Widget Main:"""
def switch_to_main(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(0)
def switch_to_settings(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(1)
def switch_to_credits(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(2)
def switch_to_license(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(3)
def switch_to_keyboard_shortcuts(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(4)
def switch_to_install_dialog(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(5)
def switch_to_supported_sites(self):
if self._anonymous_mode:
self.supported_sites_qml.hide()
self.ui.supported_sites_textbrowser.show()
self.ui.supported_sites_textbrowser.setHtml("Running in anonymous mode...")
else:
self.ui.supported_sites_textbrowser.hide()
self.supported_sites_qml.show()
self.ui.main_CentralStackedWidget.setCurrentIndex(6)
def switch_to_disclaimer(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(7)
def switch_to_one_time_setup(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(8)
def switch_to_update_available(self):
self.ui.main_CentralStackedWidget.setCurrentIndex(9)
"""Stacked Widget Top:"""
def switch_to_download(self):
self.ui.main_stacked_widget_top.setCurrentIndex(0)
self.ui.main_stacked_widget_top.setMaximumHeight(120)
self.switch_to_main()
def switch_to_login(self):
self.ui.main_stacked_widget_top.setCurrentIndex(1)
self.ui.main_stacked_widget_top.setMaximumHeight(180)
self.switch_to_login_pornhub()
self.switch_to_main()
def switch_to_login_pornhub(self):
self.ui.login_stacked_widget.setCurrentIndex(0)
def switch_to_login_xvideos(self):
self.ui.login_stacked_widget.setCurrentIndex(1)
# Stacked Widget Tree
def switch_to_treewidget_downloads(self):
self.ui.main_stacked_widget_tree.setCurrentIndex(0)
self.switch_to_main()
def switch_to_treewidget_advanced_configuration(self):
self.ui.main_stacked_widget_tree.setCurrentIndex(1)
self.switch_to_main()
def _setup_modern_tabs(self):
# Setup Credits QML
self.ui.credits_textbrowser.hide()
self.credits_qml = QQuickWidget(qml_engine, self)
self.credits_qml.setResizeMode(QQuickWidget.ResizeMode.SizeRootObjectToView)
self.credits_qml.setSource(QUrl.fromLocalFile(str(Path(__file__).parent / "src" / "frontend" / "UI" / "CreditsWidget.qml")))
self.ui.scrollarea_credits_vboxlayout.addWidget(self.credits_qml)
# Setup Supported Sites QML
self.ui.supported_sites_textbrowser.hide()
self.supported_sites_qml = QQuickWidget(qml_engine, self)
self.supported_sites_qml.setResizeMode(QQuickWidget.ResizeMode.SizeRootObjectToView)
self.supported_sites_qml.setSource(QUrl.fromLocalFile(str(Path(__file__).parent / "src" / "frontend" / "UI" / "SupportedSitesWidget.qml")))
self.ui.gridLayout_20.addWidget(self.supported_sites_qml, 0, 0, 1, 1)
def load_style(self):
icons = {
self.ui.main_button_switch_home: "download.svg",
self.ui.main_button_switch_settings: "settings.svg",
self.ui.main_button_switch_credits: "information.svg",
self.ui.main_button_switch_account: "account.svg",
}
self.setWindowIcon(QIcon(":/images/graphics/logo_transparent.ico"))
for btn, name in icons.items():
btn.setIcon(QIcon(f":/images/graphics/{name}"))
btn.setIconSize(QSize(24, 24)) # consistent size for all
# --- top nav becomes segmented & exclusive ---
nav = [
self.ui.main_button_switch_home,
self.ui.main_button_switch_account,
self.ui.main_button_switch_settings,
self.ui.main_button_switch_credits,
]
group_menu_bar = QButtonGroup(self)
group_menu_bar.setExclusive(True)
for b in nav:
b.setCheckable(True)
group_menu_bar.addButton(b)
mark(b, seg=True) # <- gives the segmented style
self.ui.main_button_switch_home.setChecked(True)
tree_nav = [
self.ui.treewidget_button_downloads,
self.ui.treewidget_button_advanced_configuration,
]
group_tree_nav = QButtonGroup(self)
group_tree_nav.setExclusive(True)
for b in tree_nav:
b.setCheckable(True)
group_tree_nav.addButton(b)
mark(b, seg=True)
self.ui.treewidget_button_downloads.setChecked(True)
login_nav = [
self.ui.login_button_switch_pornhub,
self.ui.login_button_switch_xvideos
]
group_login_bar = QButtonGroup(self)
group_login_bar.setExclusive(True)
for b in login_nav:
b.setCheckable(True)
group_login_bar.addButton(b)
mark(b, seg=True)
self.ui.login_button_switch_pornhub.setChecked(True)
# --- intent & size instead of dozens of QSS files ---
mark(self.ui.download_button_download, intent="primary", size="lg")
mark(self.ui.login_button_login, intent="primary")
mark(self.ui.login_xvideos_button_login, intent="primary")
mark(self.ui.credits_button_send_feedback, intent="primary")
mark(self.ui.treewidget_button_stop, intent="danger")
mark(self.ui.treewidget_button_advanced_configuration, seg=True)
mark(self.ui.main_progressbar_total, role="total")
mark(self.ui.login_xvideos_button_help, intent="success")
mark(self.ui.one_time_setup_button_info_enable_all, intent="success")
mark(self.ui.one_time_setup_button_info_disable_all, intent="danger")
mark(self.ui.one_time_setup_button_info_enable_update, intent="primary")
# most of these are secondary or flat so they don’t compete visually
for b in [
self.ui.main_button_switch_supported_websites,
self.ui.update_available_button_acknowledged,
]:
mark(b, flat=True)
# things that start/queue work but aren’t “the” CTA: make them secondary
for b in [
self.ui.download_button_playlist_get_videos,
self.ui.download_button_model,
self.ui.tree_advanced_button_keyboard_shortcuts,
]:
mark(b) # no intent ⇒ secondary
for cb in self.findChildren(QComboBox):
pretty_combo(cb)
# --- progress bars: mark roles instead of separate QSS files ---
mark(self.ui.main_progressbar_total, role="total")
# --- tree header sizing / behavior ---
self.ui.main_tree_widget.setColumnCount(7)
self.ui.main_tree_widget.setHeaderLabels([
"Download", "Title", "Author", "Length", "Quality", "Stop", "Progress"
])
self.ui.main_tree_widget.setRootIsDecorated(False) # looks more like a table
self.ui.main_tree_widget.setAlternatingRowColors(True)
self.ui.main_tree_widget.setSelectionBehavior(self.ui.main_tree_widget.SelectionBehavior.SelectRows)
# Make it look reasonable
self.ui.main_tree_widget.setColumnWidth(self.COL_DOWNLOAD, 110)
self.ui.main_tree_widget.setColumnWidth(self.COL_TITLE, 120)
self.ui.main_tree_widget.setColumnWidth(self.COL_AUTHOR, 180)
self.ui.main_tree_widget.setColumnWidth(self.COL_LENGTH, 120)
self.ui.main_tree_widget.setColumnWidth(self.COL_QUALITY, 120)
self.ui.main_tree_widget.setColumnWidth(self.COL_PROGRESS, 220)
self.ui.main_tree_widget.header().setSectionResizeMode(self.COL_DOWNLOAD, QHeaderView.ResizeMode.ResizeToContents)
self.ui.main_tree_widget.header().setSectionResizeMode(self.COL_QUALITY, QHeaderView.ResizeMode.ResizeToContents)
self.ui.main_tree_widget.header().setSectionResizeMode(self.COL_STOP, QHeaderView.ResizeMode.ResizeToContents)
self.ui.main_tree_widget.header().setSectionResizeMode(self.COL_LENGTH, QHeaderView.ResizeMode.ResizeToContents)
# Let the title take the free space
self.ui.main_tree_widget.header().setSectionResizeMode(self.COL_TITLE, QHeaderView.ResizeMode.Stretch)
# Progress is last: let it stretch too (it will consume remaining space)
self.ui.main_tree_widget.header().setStretchLastSection(True)
# --- misc you already had ---
self.ui.main_tree_widget.sortByColumn(2, Qt.SortOrder.AscendingOrder)
self.setWindowTitle(f"Porn Fetch v{__version__} Copyright (C) Johannes Habel 2023-2026")
self.ui.main_tree_widget.sortByColumn(2, Qt.SortOrder.AscendingOrder)
install_focus_outline(self)
self.filter = ComboPopupFitter()
self.switch_to_download()
self.switch_to_treewidget_downloads()
def load_strings(self):
"""
This loads and applies the strings to the UI from src/frontend/translations/strings.py
"""
self.disable_anonymous_mode()
def enable_anonymous_mode(self):
"""
This mode will hide that you are using Porn Fetch by hiding video title names, hiding author names,
hiding the window title and removing all placeholders from lineedits. May not be the most efficient approach,
but it works.
"""
if self._anonymous_mode:
self.logger.info("Already running anonymous, resetting back...")
self.disable_anonymous_mode()
return
self.setWindowTitle("Running in Anonymous mode...")
self.ui.download_lineedit_url.setPlaceholderText(" ")
self.ui.download_lineedit_model_url.setPlaceholderText(" ")
self.ui.download_lineedit_playlist_url.setPlaceholderText(" ")
self.ui.login_lineedit_password.setPlaceholderText(" ")
self.ui.login_lineedit_username.setPlaceholderText(" ")
self.ui.settings_button_system_install_pornfetch.setText("Install Program")
self.ui.settings_button_uninstall_porn_fetch.setText("Uninstall Program")
self.ui.settings_button_reset.setText("Reset Application")
self.ui.supported_sites_textbrowser.setText(
"Running in anonymous mode, please deactivate to display...")
self._anonymous_mode = True # Makes sense, trust
self.logger.info("Enabled anonymous mode!")
def disable_anonymous_mode(self):
"""
This loads the UI state back to normal
"""
self.setWindowTitle(TRANSLATE_MAIN.title)
self.ui.download_lineedit_url.setPlaceholderText(TRANSLATE_PAGE_DOWNLOAD.download_url_placeholder)
self.ui.download_lineedit_playlist_url.setPlaceholderText(TRANSLATE_PAGE_DOWNLOAD.download_playlist_placeholder)
self.ui.download_lineedit_model_url.setPlaceholderText(TRANSLATE_PAGE_DOWNLOAD.download_model_placeholder)
self.ui.login_lineedit_password.setPlaceholderText(TRANSLATE_PAGE_LOGIN.login_email_password)
self.ui.login_lineedit_username.setPlaceholderText(TRANSLATE_PAGE_LOGIN.login_email_password)
self.ui.settings_button_system_install_pornfetch.setText(TRANSLATE_PAGE_SETTINGS.settings_button_install_pf)
self.ui.download_lineedit_playlist_url.setPlaceholderText(TRANSLATE_PAGE_DOWNLOAD.download_playlist_placeholder)
self.ui.settings_button_reset.setText(TRANSLATE_PAGE_SETTINGS.settings_button_reset_pf)
self.ui.settings_button_uninstall_porn_fetch.setText(TRANSLATE_PAGE_SETTINGS.settings_button_uninstall_pf)
self._anonymous_mode = False # Makes sense, trust
self.logger.info("Disabled anonymous mode!")
self.setWindowTitle(f"Porn Fetch v{__version__} Copyright (C) Johannes Habel 2023-2026")
def button_connections(self):
"""a function to link the buttons to their functions"""
# Menu Bar Switch Button Connections
self.ui.main_button_switch_home.clicked.connect(self.switch_to_download)
self.ui.main_button_switch_settings.clicked.connect(self.switch_to_settings)
self.ui.main_button_switch_credits.clicked.connect(self.switch_to_credits)
self.ui.main_button_switch_account.clicked.connect(self.switch_to_login)
self.ui.main_button_switch_supported_websites.clicked.connect(self.switch_to_supported_sites)
# Video Download Button Connections
self.ui.download_button_download.clicked.connect(self.start_single_video)
self.ui.download_button_model.clicked.connect(self.start_model)
self.ui.download_button_playlist_get_videos.clicked.connect(self.start_playlist)
# Info Dialog
self.ui.one_time_setup_button_info_enable_all.clicked.connect(self.info_dialog_enable_all)
self.ui.one_time_setup_button_info_disable_all.clicked.connect(self.info_dialog_disable_all)
self.ui.one_time_setup_button_info_enable_update.clicked.connect(self.info_dialog_enable_update)
self.ui.button_install.clicked.connect(self.install_pornfetch)
# Account
self.ui.login_button_login.clicked.connect(self.login)
self.ui.login_button_get_watched_videos.clicked.connect(self.get_watched_videos)
self.ui.login_button_get_liked_videos.clicked.connect(self.get_liked_videos)
self.ui.login_button_get_recommended_videos.clicked.connect(self.get_recommended_videos)
self.ui.login_button_switch_pornhub.clicked.connect(self.switch_to_login_pornhub)
self.ui.login_button_switch_xvideos.clicked.connect(self.switch_to_login_xvideos)
# Other stuff IDK
self.ui.treewidget_button_stop.clicked.connect(switch_stop_state)
self.ui.tree_advanced_button_keyboard_shortcuts.clicked.connect(self.switch_to_keyboard_shortcuts)
self.ui.tree_advanced_button_custom_title_options.clicked.connect(available_title_formatting_options)
# Stacked Tree Widget
self.ui.treewidget_button_downloads.clicked.connect(self.switch_to_treewidget_downloads)
self.ui.treewidget_button_advanced_configuration.clicked.connect(self.switch_to_treewidget_advanced_configuration)
def initialize_pornfetch(self):
"""
After all stylesheets and icons are loaded, this function will initiate the process for checking
if the License was shown and accepted, if the disclaimer text was shown, if the user downloaded the amount
of videos to show the sponsoring dialog and after all that switch to the main widget.
"""
global FORCE_PORTABLE_RUN
self.ui.main_progressbar_total.setMaximum(4)
if not self.license.check_license():
self.switch_to_license()
return
self.ui.main_progressbar_total.setValue(1)
if not self.disclaimer.check_disclaimer():
self.switch_to_disclaimer()
return
self.ui.main_progressbar_total.setValue(2)
first = settings.value("Misc/first_run_gui", True, type=bool)
if first:
settings.setValue("Misc/first_run_gui", False)
settings.sync()
ui_popup("""
VERY IMPORTANT INFORMATION (must read)
With this release, Porn Fetch gets a license system with paid only features.
So you need to buy a license for 5€ to get all features, HOWEVER...
Because I live in Germany and in this country you need to create a company even if you want to make one cent,
and I haven't done that yet, you get the full license FOR FREE!
I am currently using a stripe checkout form which is in test mode. That means that while this looks like a real payment,
your card will NOT be charged.
To get a license, please go to:
https://echteralsfake.me/buy_license
For the E-Mail enter:
test@test.com
Enter this for the payment information:
Card Number: 4242 4242 4242 4242
MM / JJ: 05/28
CVC: 999
Name: Max Mustermann
This serves as a test environment for the real license system later on.
Thank you very much for participating :)
If you need help, please write to:
EchterAlsFake@proton.me
""")
self.switch_to_one_time_setup()
ui_popup("""
Warning:
You are using Porn Fetch from the latest source code. This can cause weird behaviour or other issues.
Do not report issues when using Porn Fetch from source code.
You have all paid features unlocked :)
""")
return
self.ui.main_progressbar_total.setValue(3)
if not FORCE_PORTABLE_RUN:
if sys.platform == "darwin":
self.ui.main_CentralStackedWidget.setCurrentIndex(0)
return
if settings.value("Misc/install_type") == "unknown":
self.switch_to_install_dialog()
return
self.ui.main_progressbar_total.setValue(0) # Clear
self.ui.main_progressbar_total.setMaximum(100)
if first:
self.save_user_settings()
self.ui.main_CentralStackedWidget.setCurrentIndex(0)
def info_dialog_enable_update(self):
self.ui.settings_checkbox_system_enable_network_logging.setChecked(False)
self.ui.settings_checkbox_system_update_checks.setChecked(True)
self.save_user_settings(show_dialog=False)
self.initialize_pornfetch()
def info_dialog_disable_all(self):
self.ui.settings_checkbox_system_enable_network_logging.setChecked(False)
self.ui.settings_checkbox_system_update_checks.setChecked(False)
self.save_user_settings(show_dialog=False)
self.initialize_pornfetch()
def info_dialog_enable_all(self):
self.ui.settings_checkbox_system_enable_network_logging.setChecked(True)
self.ui.settings_checkbox_system_update_checks.setChecked(True)
self.save_user_settings(show_dialog=False)
self.initialize_pornfetch()
def shortcuts(self):
quit_shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
quit_shortcut.activated.connect(self.close)
download_all = QShortcut(QKeySequence("Ctrl+T"), self)
download_all.activated.connect(self.download_all)
export_urls_shortcut = QShortcut(QKeySequence("Ctrl+E"), self)
export_urls_shortcut.activated.connect(export_urls)
enable_anonymous_mode = QShortcut(QKeySequence("Ctrl+A"), self)
enable_anonymous_mode.activated.connect(self.enable_anonymous_mode)
save_settings = QShortcut(QKeySequence("Ctrl+S"), self)
save_settings.activated.connect(self.save_user_settings)
def download_all(self):
"""Automatically downloads all videos in the tree widget"""
for i in range(self.ui.main_tree_widget.topLevelItemCount()):
item = self.ui.main_tree_widget.topLevelItem(i)
identifier = item.data(self.COL_TITLE, Qt.ItemDataRole.UserRole)
self.queue_download(video_id=identifier)
def load_user_settings(self):
# Video related
quality = config.app_settings.quality
key = next((k for k, v in config.app_settings.mappings_quality.items() if v == quality), None)
self.ui.settings_video_combobox_quality.setCurrentIndex(key)
self.ui.settings_video_combobox_model_videos.setCurrentIndex(config.app_settings.model_videos)
self.ui.settings_spinbox_videos_result_limit.setValue(config.app_settings.result_limit)
self.ui.settings_lineedit_videos_output_path.setText(config.app_settings.output_path)
self.ui.settings_checkbox_videos_write_metadata.setChecked(config.app_settings.write_metadata)
self.ui.settings_checkbox_videos_skip_existing_files.setChecked(config.app_settings.skip_existing_files)
self.ui.settings_checkbox_videos_track_downloaded_videos.setChecked(config.app_settings.track_videos)
self.ui.settings_lineedit_videos_database_path.setText(config.app_settings.database_path)
# Performance related
self.ui.settings_spinbox_performance_simultaneous_downloads.setValue(config.app_settings.parallel_downloads)
self.ui.settings_spinbox_performance_network_delay.setValue(config.app_settings.network_delay)
self.ui.settings_spinbox_performance_videos_concurrency.setValue(config.app_settings.videos_concurrency)
self.ui.settings_spinbox_performance_pages_concurrency.setValue(config.app_settings.pages_concurrency)
self.ui.settings_spinbox_performance_download_workers.setValue(config.app_settings.download_workers)
self.ui.settings_spinbox_performance_maximal_timeout.setValue(config.app_settings.maximal_timeout)
self.ui.settings_spinbox_performance_maximal_retries.setValue(config.app_settings.retries)
self.ui.settings_doublespinbox_performance_speed_limit.setValue(config.app_settings.speed_limit)
self.ui.settings_spinbox_performance_processing_delay.setValue(config.app_settings.processing_delay)
# System / Misc related
self.ui.settings_checkbox_system_update_checks.setChecked(config.app_settings.update_checks)
self.ui.settings_checkbox_system_enable_anonymous_mode.setChecked(config.app_settings.enable_anonymous_mode)
self.ui.settings_checkbox_system_supress_errors.setChecked(config.app_settings.supress_errors)
self.ui.settings_checkbox_system_enable_network_logging.setChecked(config.app_settings.enable_logging)
self.ui.settings_checkbox_system_enable_debug_mode.setChecked(config.app_settings.debug_mode)
self.ui.settings_checkbox_use_truststore.setChecked(config.app_settings.use_truststore)
# UI
language = config.app_settings.language
key = next((key for key, value in config.app_settings.mappings_ui_language.items() if value == language), None)
self.ui.settings_ui_combobox_language.setCurrentIndex(key)
theme = config.app_settings.theme
if hasattr(self.ui, "settings_combobox_ui_theme"):
self.ui.settings_combobox_ui_theme.setCurrentIndex(theme)
self.ui.settings_spinbox_ui_font_size.setValue(config.app_settings.font_size)
def save_user_settings(self):
config.app_settings.quality = self.ui.settings_video_combobox_quality.currentIndex()
config.app_settings.model_videos = self.ui.settings_video_combobox_model_videos.currentIndex()
config.app_settings.result_limit = self.ui.settings_spinbox_videos_result_limit.value()
config.app_settings.output_path = self.ui.settings_lineedit_videos_output_path.text()
config.app_settings.write_metadata = self.ui.settings_checkbox_videos_write_metadata.isChecked()
config.app_settings.skip_existing_files = self.ui.settings_checkbox_videos_skip_existing_files.isChecked()
config.app_settings.track_videos = self.ui.settings_checkbox_videos_track_downloaded_videos.isChecked()
config.app_settings.database_path = self.ui.settings_lineedit_videos_database_path.text()
config.app_settings.parallel_downloads = self.ui.settings_spinbox_performance_simultaneous_downloads.value()
config.app_settings.network_delay = self.ui.settings_spinbox_performance_network_delay.value()
config.app_settings.videos_concurrency = self.ui.settings_spinbox_performance_videos_concurrency.value()
config.app_settings.pages_concurrency = self.ui.settings_spinbox_performance_pages_concurrency.value()
config.app_settings.download_workers = self.ui.settings_spinbox_performance_download_workers.value()
config.app_settings.timeout = self.ui.settings_spinbox_performance_maximal_timeout.value()
config.app_settings.retries = self.ui.settings_spinbox_performance_maximal_retries.value()
config.app_settings.speed_limit = self.ui.settings_doublespinbox_performance_speed_limit.value()
config.app_settings.processing_delay = self.ui.settings_spinbox_performance_processing_delay.value()
config.app_settings.update_checks = self.ui.settings_checkbox_system_update_checks.isChecked()
config.app_settings.anonymous_mode = self.ui.settings_checkbox_system_enable_anonymous_mode.isChecked()
config.app_settings.suppress_errors = self.ui.settings_checkbox_system_supress_errors.isChecked()
config.app_settings.enable_logging = self.ui.settings_checkbox_system_enable_network_logging.isChecked()
config.app_settings.debug_mode = self.ui.settings_checkbox_system_enable_debug_mode.isChecked()
config.app_settings.use_truststore = self.ui.settings_checkbox_use_truststore.isChecked()
config.app_settings.language = self.ui.settings_ui_combobox_language.currentIndex()
config.app_settings.font_size = self.ui.settings_spinbox_ui_font_size.value()
if hasattr(self.ui, "settings_combobox_ui_theme"):
config.app_settings.theme = self.ui.settings_combobox_ui_theme.currentIndex()
def set_proxies(self):
message = self.tr("""
Please read this before setting proxies:
I am not a genius in programming and I can NOT guarantee for your safety. However, I did everything possible (in my abilities)
to make sure this works perfectly. When you apply proxies you need to make sure that they are in the correct format. You'll
see a few examples down below.
Also, if you use PUBLIC proxies, then it's really a gamble if they work or if they don't. Usually they are really slow and
inconsistent, but maybe you are lucky.
About SSL encryption:
If your proxy does NOT support SSL / TLS or delivers incorrect self-signed certificates, then you can choose to ignore that
by disabling SSL verification. However, this reduces your security a lot and people in your network will be able to intercept
your network traffic.
This is not my fault, it's just how the internet works. So, get yourself a good proxy and then you are good to go :)
Here are a few examples of valid proxies:
1) http://89.3.64.185:1111
2) socks5://45.115.114.57:9090
Important:
Even if your proxy supports https, you need to put it as 'http://'. This will NOT disable encryption.