@@ -515,11 +515,11 @@ def __init__(self, iterator, search_limit, data_mode, is_reverse, is_checked, la
515
515
self .delay = delay
516
516
self .output_path = output_path
517
517
self .directory_system = directory_system
518
- self .url = url
519
-
520
- def process_video (self , index ):
521
- video = check_video (self .url , delay = self .delay )
522
518
519
+ def process_video (self , video , index ):
520
+ print (f"Requesting processing of video: { video .url } " )
521
+ video = check_video (video , delay = self .delay )
522
+ print (type (video ))
523
523
try :
524
524
data = load_video_attributes (video , self .data_mode )
525
525
@@ -624,7 +624,7 @@ def run(self):
624
624
break # Respect search limit
625
625
626
626
627
- text_data = self .process_video (i )
627
+ text_data = self .process_video (video , i ) # Passes video and index object / int
628
628
if text_data is False :
629
629
break # Skip to the next video if processing failed
630
630
@@ -656,7 +656,7 @@ def run(self):
656
656
class DownloadThread (QRunnable ):
657
657
"""Refactored threading class to download videos with improved performance and logic."""
658
658
659
- def __init__ (self , video , quality , output_path , threading_mode , workers , timeout , skip_existing_files ):
659
+ def __init__ (self , video , quality , output_path , threading_mode , workers , timeout , skip_existing_files , data ):
660
660
super ().__init__ ()
661
661
self .ffmpeg = None
662
662
self .video = video
@@ -668,6 +668,7 @@ def __init__(self, video, quality, output_path, threading_mode, workers, timeout
668
668
self .skip_existing_files = skip_existing_files
669
669
self .workers = int (workers )
670
670
self .timeout = int (timeout )
671
+ self .data = data
671
672
self .video_progress = {}
672
673
self .last_update_time = 0
673
674
self .progress_signals = {
@@ -803,7 +804,7 @@ def run(self):
803
804
# ... other video types ...
804
805
805
806
finally :
806
- self .signals .download_completed .emit ()
807
+ self .signals .download_completed .emit (self . data )
807
808
808
809
809
810
class PostProcessVideoThread (QRunnable ):
@@ -824,25 +825,33 @@ def __init__(self, write_tags_, data, ffmpeg_path, video_format):
824
825
825
826
826
827
def run (self ):
827
- os .rename (f"{ self .path } " , f"{ self .path } _.tmp" )
828
- logger .debug (f"FFMPEG PATH: { self .ffmpeg_path } " )
828
+ if self .ffmpeg_path is None :
829
+ logger .warning ("FFmpeg couldn't be found during initialization. Video post processing will be skipped!" )
830
+ return
831
+
832
+ try :
833
+ os .rename (f"{ self .path } " , f"{ self .path } _.tmp" )
834
+ logger .debug (f"FFMPEG PATH: { self .ffmpeg_path } " )
829
835
830
- if self .format == "mp4" :
831
- cmd = [self .ffmpeg_path , "-i" , f"{ self .path } _.tmp" , "-c" , "copy" , self .path ]
836
+ if self .format == "mp4" :
837
+ cmd = [self .ffmpeg_path , "-i" , f"{ self .path } _.tmp" , "-c" , "copy" , self .path ]
832
838
833
- else :
834
- self .path = str (self .path ).replace (".mp4" , f"{ self .format } " )
835
- cmd = [self .ffmpeg_path , '-i' , f"{ self .path } _.tmp" , self .path ]
839
+ else :
840
+ self .path = str (self .path ).replace (".mp4" , f"{ self .format } " )
841
+ cmd = [self .ffmpeg_path , '-i' , f"{ self .path } _.tmp" , self .path ]
836
842
837
843
838
- ff = FfmpegProgress (cmd )
839
- for progress in ff .run_command_with_progress ():
840
- self .signals .ffmpeg_converting_progress .emit (round (progress ), 100 )
844
+ ff = FfmpegProgress (cmd )
845
+ for progress in ff .run_command_with_progress ():
846
+ self .signals .ffmpeg_converting_progress .emit (round (progress ), 100 )
841
847
842
- os .remove (f"{ self .path } _.tmp" )
848
+ os .remove (f"{ self .path } _.tmp" )
843
849
844
- if self .write_tags_ :
845
- write_tags (path = self .path , data = self .data )
850
+ if self .write_tags_ :
851
+ write_tags (path = self .path , data = self .data )
852
+
853
+ except Exception as e :
854
+ self .signals .error_signal .emit (e )
846
855
847
856
848
857
class QTreeWidgetDownloadThread (QRunnable ):
@@ -859,12 +868,14 @@ def __init__(self, tree_widget, threading_mode, semaphore, quality):
859
868
def run (self ):
860
869
self .signals .start_undefined_range .emit ()
861
870
video_objects = []
871
+ data_objects = []
862
872
863
873
for i in range (self .treeWidget .topLevelItemCount ()):
864
874
item = self .treeWidget .topLevelItem (i )
865
875
check_state = item .checkState (0 )
866
876
if check_state == Qt .CheckState .Checked :
867
877
video_objects .append (item .data (0 , Qt .ItemDataRole .UserRole ))
878
+ data_objects .append (item .data (2 , Qt .ItemDataRole .UserRole ))
868
879
869
880
if not self .threading_mode == "FFMPEG" :
870
881
logger .debug ("Getting segments..." )
@@ -890,12 +901,12 @@ def run(self):
890
901
downloaded_segments = 0
891
902
self .signals .stop_undefined_range .emit ()
892
903
893
- for video in video_objects :
904
+ for idx , video in enumerate ( video_objects ) :
894
905
self .semaphore .acquire () # Trying to start the download if the thread isn't locked
895
906
if stop_flag .is_set ():
896
907
return
897
908
logger .debug ("Semaphore Acquired" )
898
- self .signals .progress_send_video .emit (video ) # Now emits the video to the main class for further processing
909
+ self .signals .progress_send_video .emit (video , data_objects [ idx ] ) # Now emits the video to the main class for further processing
899
910
900
911
901
912
class AddUrls (QRunnable ):
@@ -962,6 +973,8 @@ def __init__(self, parent=None, start_installation=False, app_name="Porn Fetch")
962
973
self .download_thread = None
963
974
self .video_loader_thread = None
964
975
self .video_converting_thread = None
976
+ self .post_processing_thread = None
977
+ self .download_tree_thread = None
965
978
966
979
# Button groups
967
980
self .group_threading_mode = None
@@ -1715,17 +1728,20 @@ def download_tree_widget(self):
1715
1728
Starts the thread for downloading the tree widget (All selected videos)
1716
1729
"""
1717
1730
tree_widget = self .ui .treeWidget
1718
- download_tree_thread = QTreeWidgetDownloadThread (tree_widget = tree_widget , quality = self .quality ,
1731
+ self . download_tree_thread = QTreeWidgetDownloadThread (tree_widget = tree_widget , quality = self .quality ,
1719
1732
semaphore = self .semaphore , threading_mode = self .threading_mode )
1720
- download_tree_thread .signals .start_undefined_range .connect (self .start_undefined_range )
1721
- download_tree_thread .signals .stop_undefined_range .connect (self .stop_undefined_range )
1722
- self .threadpool .start (download_tree_thread )
1733
+ self .download_tree_thread .signals .start_undefined_range .connect (self .start_undefined_range )
1734
+ self .download_tree_thread .signals .stop_undefined_range .connect (self .stop_undefined_range )
1735
+ self .download_tree_thread .signals .progress_send_video .connect (self .process_video_thread )
1736
+
1737
+ self .threadpool .start (self .download_tree_thread )
1723
1738
1724
1739
def process_video_thread (self , video , data ):
1725
1740
"""Checks which of the three types of threading the user selected and handles them."""
1726
1741
self .download_thread = DownloadThread (video = video , output_path = self .output_path , quality = self .quality ,
1727
1742
threading_mode = self .threading_mode , workers = self .workers ,
1728
- timeout = self .timeout , skip_existing_files = self .skip_existing_files )
1743
+ timeout = self .timeout , skip_existing_files = self .skip_existing_files ,
1744
+ data = data )
1729
1745
self .download_thread .signals .progress_pornhub .connect (self .update_progressbar )
1730
1746
self .download_thread .signals .total_progress .connect (self .update_total_progressbar )
1731
1747
self .download_thread .signals .progress_hqporner .connect (self .update_progressbar_hqporner )
@@ -1750,9 +1766,23 @@ def download_completed(self, data):
1750
1766
self .ui .progressbar_hqporner .setValue (0 )
1751
1767
self .ui .progressbar_eporner .setValue (0 )
1752
1768
1769
+ self .post_processing_thread = PostProcessVideoThread (ffmpeg_path = self .ffmpeg_path , write_tags_ = self .write_metadata ,
1770
+ data = data , video_format = self .format )
1771
+ self .post_processing_thread .signals .ffmpeg_converting_progress .connect (self .update_converting )
1772
+ self .post_processing_thread .signals .error_signal .connect (self .show_error )
1773
+ self .threadpool .start (self .post_processing_thread )
1774
+
1753
1775
# TODO: Add the post processing into this method
1754
1776
self .semaphore .release ()
1755
1777
1778
+ def show_error (self , error ):
1779
+ err = self .tr (f"""
1780
+ An error happened inside of Porn Fetch!
1781
+
1782
+ { error } """ )
1783
+ ui_popup (err )
1784
+
1785
+
1756
1786
1757
1787
1758
1788
def reindex (self ):
@@ -2167,14 +2197,18 @@ def check_ffmpeg(self):
2167
2197
2168
2198
if ffmpeg_path is None :
2169
2199
# If ffmpeg is not in PATH, check the current directory for ffmpeg binaries
2170
- ffmpeg_binary = "ffmpeg.exe" if os .path .isfile ("ffmpeg.exe" ) else "ffmpeg" if os .path .isfile (
2200
+ ffmpeg_path = "ffmpeg.exe" if os .path .isfile ("ffmpeg.exe" ) else "ffmpeg" if os .path .isfile (
2171
2201
"ffmpeg" ) else None
2172
2202
2173
- if ffmpeg_binary is None :
2174
- # If ffmpeg binaries are not found in the current directory, display warning and disable features
2175
- if self .conf .get ("Performance" , "ffmpeg_warning" ) == "true" :
2176
- ffmpeg_warning_message = self .tr (
2177
- """
2203
+ if not ffmpeg_path is None :
2204
+ ffmpeg_path = os .path .abspath (ffmpeg_path )
2205
+
2206
+
2207
+ if ffmpeg_path is None :
2208
+ # If ffmpeg binaries are not found in the current directory, display warning and disable features
2209
+ if self .conf .get ("Performance" , "ffmpeg_warning" ) == "true" :
2210
+ ffmpeg_warning_message = self .tr (
2211
+ """
2178
2212
FFmpeg isn't installed on your system... Some features won't be available:
2179
2213
2180
2214
- The FFmpeg threading mode
@@ -2187,24 +2221,20 @@ def check_ffmpeg(self):
2187
2221
local PATH (e.g, through your linux package manager, or through the Windows PATH)
2188
2222
2189
2223
This warning won't be shown again.
2190
- """ , None )
2191
- ui_popup (ffmpeg_warning_message )
2192
- self .conf .set ("Performance" , "ffmpeg_warning" , "false" )
2193
- with open ("config.ini" , "w" ) as config_file : # type: TextIOWrapper
2194
- self .conf .write (config_file )
2224
+ """ , None )
2225
+ ui_popup (ffmpeg_warning_message )
2226
+ self .conf .set ("Performance" , "ffmpeg_warning" , "false" )
2227
+ with open ("config.ini" , "w" ) as config_file : # type: TextIOWrapper
2228
+ self .conf .write (config_file )
2195
2229
2196
- self .ui .settings_radio_threading_mode_ffmpeg .setDisabled (True )
2197
-
2198
- else :
2199
- # If ffmpeg binary is found in the current directory, set it as the ffmpeg path
2200
- ffmpeg_path = os .path .abspath (ffmpeg_binary )
2230
+ self .ui .settings_radio_threading_mode_ffmpeg .setDisabled (True )
2231
+ self .ffmpeg_path = None
2201
2232
2202
2233
else :
2203
- # If ffmpeg is found in system PATH, use it directly
2204
- ffmpeg_path = shutil .which ("ffmpeg" )
2205
2234
consts .FFMPEG_EXECUTABLE = ffmpeg_path
2206
2235
bs_consts .FFMPEG_PATH = ffmpeg_path
2207
- logger .debug (f"FFMPEG: { ffmpeg_path } " )
2236
+ self .ffmpeg_path = ffmpeg_path
2237
+ logger .debug (f"FFmpeg found at: { ffmpeg_path } " )
2208
2238
2209
2239
def download_ffmpeg (self ):
2210
2240
if sys .platform == "linux" :
0 commit comments