Skip to content

Commit d0260eb

Browse files
committed
- fixed serious downloading issues in code (lmao)
1 parent 79b9af9 commit d0260eb

File tree

3 files changed

+3707
-2525
lines changed

3 files changed

+3707
-2525
lines changed

main.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class Signals(QObject):
262262

263263
progress_video = Signal(int, int, int)
264264
progress_video_range = Signal(int, int)
265+
progress_video_converting = Signal(int, int)
265266

266267
error_signal = Signal(object)
267268

@@ -704,13 +705,16 @@ def __init__(self, video, video_id):
704705
self.last_update_time = 0
705706
self._range_emitted = False
706707

707-
def generic_callback(self, pos, total, video_source):
708+
def callback_remux(self, pos, total):
709+
self.signals.progress_video_converting.emit(pos, total)
710+
711+
def generic_callback(self, pos, total, video_source="general"):
708712
"""Generic callback function to emit progress signals with rate limiting."""
709713
current_time = time.time()
710714
if self.stop_flag.is_set():
711715
return
712716
# Emit signal for individual progress
713-
if video_source == "hqporner" or video_source == "eporner":
717+
if video_source == "raw":
714718

715719
# Check if the current time is at least 0.5 seconds greater than the last update time
716720
if current_time - self.last_update_time < 0.5:
@@ -728,7 +732,7 @@ def generic_callback(self, pos, total, video_source):
728732

729733
self.signals.progress_video.emit(self.video_id, pos, total) # Although we don't use total, we need to accept it
730734
# Update total progress only if the video source uses segments
731-
if video_source not in ['hqporner', 'eporner']:
735+
if video_source == "general":
732736
self.update_total_progress()
733737

734738
# Update the last update time to the current time
@@ -763,45 +767,30 @@ def run(self):
763767
self.signals.total_progress_range.emit(total_segments)
764768

765769
# We need to specify the sources, so that it knows which individual progressbar to use
766-
if isinstance(self.video, shared_functions.hq_Video):
767-
video_source = "hqporner"
770+
if isinstance(self.video, shared_functions.hq_Video) or isinstance(self.video, shared_functions.ep_Video):
771+
video_source = "raw"
768772
try:
769773
self.video.download(quality=self.quality, path=self.output_path, no_title=True,
770774
callback=lambda pos, total: self.generic_callback(pos, total, video_source))
771775

772776
except Exception:
773777
error = traceback.format_exc()
774-
handle_error_gracefully(data=self.consistent_data, self=self, error_message=f"An error happened while downloading a video from HQPorner: {error}", needs_network_log=True)
775-
776-
elif isinstance(self.video, shared_functions.ep_Video):
777-
video_source = "eporner"
778-
try:
779-
self.video.download(quality=self.quality, path=self.output_path, no_title=True,
780-
callback=lambda pos, total: self.generic_callback(pos, total, video_source))
781-
782-
except Exception:
783-
error = traceback.format_exc()
784-
handle_error_gracefully(data=self.consistent_data, self=self, error_message=f"An error happened while downloading a video from EPorner: {error}", needs_network_log=True)
785-
778+
handle_error_gracefully(data=self.consistent_data, self=self, error_message=f"An error happened while downloading a video from HQPorner / EPorner: {error}", needs_network_log=True)
786779

787-
else: # Assuming 'Video' is the class for Pornhub
788-
path = self.output_path
780+
elif isinstance(self.video, shared_functions.ph_Video): # Assuming 'Video' is the class for Pornhub
789781
video_source = "general"
790782
self.logger.debug("Starting the Download!")
791-
try:
792-
self.video.download(downloader=str(self.threading_mode), path=path, quality=self.quality, remux=True,
793-
display=lambda pos, total: self.generic_callback(pos, total, video_source))
794-
795-
except TypeError:
796-
try:
797-
self.video.download(downloader=str(self.threading_mode), path=path, quality=self.quality, remux=True, no_title=True,
798-
callback=lambda pos, total: self.generic_callback(pos, total, video_source))
783+
self.video.download(downloader=str(self.threading_mode), path=self.output_path, quality=self.quality, remux=True, display_remux=self.callback_remux,
784+
display=lambda pos, total: self.generic_callback(pos, total))
799785

800-
except Exception:
801-
error = traceback.format_exc()
802-
error = f"An error occurred when trying to download video: {error}. This will be reported!"
803-
handle_error_gracefully(self, data=video_data.consistent_data, error_message=error, needs_network_log=True)
786+
else:
787+
self.video.download(downloader=str(self.threading_mode), path=self.output_path, callback_remux=self.callback_remux, no_title=True,
788+
quality=self.quality, remux=True, callback=lambda pos, total: self.generic_callback(pos, total))
804789

790+
except Exception:
791+
error = traceback.format_exc()
792+
error = f"An error occurred when trying to download video: {error}. This will be reported!"
793+
handle_error_gracefully(self, data=video_data.consistent_data, error_message=error, needs_network_log=True)
805794

806795
finally:
807796
if self.consistent_data.get("write_metadata"):
@@ -966,6 +955,7 @@ def __init__(self, parent=None):
966955
class PornFetch(QMainWindow):
967956
def __init__(self, parent=None):
968957
super().__init__(parent)
958+
self.last_update_time = time.time()
969959
self.last_thumbnail_change = time.time()
970960
self.stylesheets = None
971961
self._pixmap_item = None
@@ -2077,6 +2067,7 @@ def process_video_thread(self, video, video_id):
20772067
"""Checks which of the three types of threading the user selected and handles them."""
20782068
self.create_video_progressbar(video_id=video_id, title=video.title)
20792069
self.download_thread = DownloadThread(video=video, video_id=video_id)
2070+
self.download_thread.signals.progress_video_converting.connect(self.progress_video_remuxing)
20802071
self.download_thread.signals.progress_video.connect(self.update_video_progressbar)
20812072
self.download_thread.signals.progress_video_range.connect(self.set_video_progress_range)
20822073
self.download_thread.signals.total_progress_range.connect(self.update_total_progressbar_range)
@@ -2094,6 +2085,9 @@ def download_completed(self, video_id):
20942085
self.ui.progress_lineedit_download_info.setText(
20952086
f"Downloaded: {total_downloaded_videos} video(s) this session.")
20962087
self.ui.main_progressbar_total.setMaximum(100)
2088+
self.ui.main_progressbar_total.setValue(0)
2089+
self.ui.main_progressbar_converting.setMaximum(100)
2090+
self.ui.main_progressbar_converting.setValue(0)
20972091
video_data.clean_dict(video_id)
20982092
self.semaphore.release()
20992093
widgets = self.progress_widgets.pop(video_id, None)
@@ -2269,6 +2263,15 @@ def set_video_progress_range(self, video_id, maximum):
22692263
# optional: reset to zero if you like
22702264
bar.setValue(0)
22712265

2266+
def progress_video_remuxing(self, pos, total):
2267+
"""Updates the progress when the video gets remuxed"""
2268+
if time.time() - self.last_thumbnail_change < 0.3:
2269+
return
2270+
2271+
self.ui.main_progressbar_converting.setMaximum(total)
2272+
self.ui.main_progressbar_converting.setValue(pos)
2273+
self.last_update_time = time.time()
2274+
22722275
def update_video_progressbar(self, video_id, pos, maximum):
22732276
"""Fired repeatedly—only updates the current value."""
22742277
widget_set = self.progress_widgets.get(video_id)

src/build/pysidedeploy_windows.spec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title = Porn Fetch
88
project_dir = .
99

1010
# source file path
11-
input_file = main.py
11+
input_file = C:\Users\habel\PycharmProjects\Porn_Fetch\main.py
1212

1313
# directory where exec is stored
1414
exec_directory = .
@@ -22,7 +22,7 @@ icon = src/frontend/graphics/logo_transparent.ico
2222
[python]
2323

2424
# python path
25-
python_path =
25+
python_path = C:\Users\habel\PycharmProjects\Porn_Fetch\.venv\Scripts\python.exe
2626

2727
# python packages to install
2828
# ordered-set = increase compile time performance of nuitka packaging
@@ -42,7 +42,7 @@ qml_files =
4242
excluded_qml_plugins =
4343

4444
# qt modules used. comma separated
45-
modules = Core,Gui,Widgets
45+
modules = QuickControls2,Widgets,Core,Qml,Gui
4646

4747
# qt plugins used by the application
4848
plugins = egldeviceintegrations,iconengines,platforms/darwin,xcbglintegrations,imageformats,platforms,platformthemes,styles,platforminputcontexts,accessiblebridge,generic
@@ -63,7 +63,7 @@ plugins =
6363
# usage description for permissions requested by the app as found in the info.plist file
6464
# of the app bundle
6565
# eg = extra_args = --show-modules --follow-stdlib
66-
macos.permissions =
66+
macos.permissions =
6767

6868
# (str) specify any extra nuitka arguments
6969
extra_args = --noinclude-qt-translations --assume-yes-for-downloads --disable-cache=all --clean-cache=all --remove-output --show-memory --company-name=None --product-name=PornFetch --file-version=3.6 --product-version=3.6 --copyright=JohannesHabel --enable-plugin=data-files --include-package-data=certifi --user-package-configuration-file=src/build/user.nuitka-package.config.yml

0 commit comments

Comments
 (0)