3636 QDialogButtonBox , QButtonGroup , QToolButton
3737)
3838from PySide6 .QtCore import (
39- Qt , QTimer , QThread , Signal , QUrl , QObject , QEventLoop , QSize , QMutex
39+ Qt , QTimer , QThread , Signal , QUrl , QObject , QEventLoop , QSize , QMutex , QRegularExpression
4040)
4141from PySide6 .QtGui import (
42- QPalette , QColor , QPixmap , QPainter , QFont , QIcon , QCloseEvent
42+ QPalette , QColor , QPixmap , QPainter , QFont , QIcon , QCloseEvent , QRegularExpressionValidator
4343)
4444from PySide6 .QtNetwork import (
4545 QNetworkAccessManager , QNetworkRequest , QNetworkReply
@@ -1709,6 +1709,13 @@ def init_config_tab(self):
17091709
17101710 self .collection_name = QLineEdit ("AI Recommended" )
17111711 plex_layout .addRow ("Collection To Add Movies To:" , self .collection_name )
1712+ self .auto_collect_threshold = QLineEdit ()
1713+ self .auto_collect_threshold .setPlaceholderText ("Leave empty to disable" )
1714+ self .auto_collect_threshold .setToolTip ("Automatically add items to collection if rated at or above this value (1-10)" )
1715+ validator = QRegularExpressionValidator ()
1716+ validator .setRegularExpression (QRegularExpression ("^([1-9]|10)$" ))
1717+ self .auto_collect_threshold .setValidator (validator )
1718+ plex_layout .addRow ("Auto-add to Collection if Rating >=:" , self .auto_collect_threshold )
17121719
17131720 plex_group .setLayout (plex_layout )
17141721 layout .addWidget (plex_group )
@@ -1775,6 +1782,27 @@ def init_config_tab(self):
17751782 config_widget .setLayout (layout )
17761783 self .tabs .addTab (config_widget , "Configuration" )
17771784
1785+
1786+ def load_plex_libraries (self ):
1787+ try :
1788+ QApplication .setOverrideCursor (Qt .WaitCursor )
1789+
1790+ self .library_list .clear ()
1791+
1792+ plex = PlexServer (self .plex_url .text (), self .plex_token .text ())
1793+
1794+ for library in plex .library .sections ():
1795+ if library .type in ['movie' , 'show' ]:
1796+ item = QListWidgetItem (f"{ library .title } ({ library .type } )" )
1797+ self .library_list .addItem (item )
1798+
1799+ QMessageBox .information (self , "Success" , "Libraries loaded successfully!" )
1800+
1801+ except Exception as e :
1802+ QMessageBox .critical (self , "Error" , f"Failed to load libraries: { str (e )} " )
1803+ finally :
1804+ QApplication .restoreOverrideCursor ()
1805+
17781806 def show_rating_dialog (self , rating_type , media_type ):
17791807 dialog = QDialog (self )
17801808 dialog .setWindowTitle (f"Rate how much you { 'liked' if rating_type == 'like' else 'disliked' } it" )
@@ -1826,12 +1854,26 @@ def submit_rating(self, rating: int, media_type: str):
18261854 if row :
18271855 columns = [description [0 ] for description in cursor .description ]
18281856 content_data = dict (zip (columns , row ))
1829-
1830-
1857+
18311858 if self .current_items [media_type ] is not None :
18321859 self .item_history [media_type ].append (self .current_items [media_type ])
18331860
18341861 self .recommender .train_with_feedback (current_id , rating , content_data )
1862+
1863+ threshold_text = self .auto_collect_threshold .text ().strip ()
1864+ if (threshold_text and
1865+ media_type == 'movie' and
1866+ rating >= float (threshold_text )):
1867+ try :
1868+ self .add_to_collection (media_type )
1869+ except Exception as e :
1870+ self .logger .error (f"Auto-collection failed: { e } " )
1871+ QMessageBox .warning (
1872+ self ,
1873+ "Auto-Collection Failed" ,
1874+ f"Failed to automatically add to collection: { str (e )} "
1875+ )
1876+
18351877 self .show_next_recommendation (media_type )
18361878
18371879 except Exception as e :
@@ -1841,6 +1883,7 @@ def submit_rating(self, rating: int, media_type: str):
18411883 finally :
18421884 self ._rating_mutex .unlock ()
18431885
1886+
18441887
18451888 def load_config (self ):
18461889 config_path = 'config.json'
@@ -2309,33 +2352,14 @@ def reset_model(self):
23092352 except Exception as e :
23102353 QMessageBox .critical (self , "Error" , f"Failed to reset system: { str (e )} " )
23112354
2312- def load_plex_libraries (self ):
2313- try :
2314- QApplication .setOverrideCursor (Qt .WaitCursor )
2315-
2316- self .library_list .clear ()
2317-
2318- plex = PlexServer (self .plex_url .text (), self .plex_token .text ())
2319-
2320- for library in plex .library .sections ():
2321- if library .type in ['movie' , 'show' ]:
2322- item = QListWidgetItem (f"{ library .title } ({ library .type } )" )
2323- self .library_list .addItem (item )
2324-
2325- QMessageBox .information (self , "Success" , "Libraries loaded successfully!" )
2326-
2327- except Exception as e :
2328- QMessageBox .critical (self , "Error" , f"Failed to load libraries: { str (e )} " )
2329- finally :
2330- QApplication .restoreOverrideCursor ()
2331-
23322355 def save_config (self ):
23332356 config = {
23342357 'plex_url' : self .plex_url .text ().strip (),
23352358 'plex_token' : self .plex_token .text ().strip (),
23362359 'tvdb_key' : self .tvdb_key .text ().strip (),
23372360 'tmdb_key' : self .tmdb_key .text ().strip (),
2338- 'collection_name' : self .collection_name .text ().strip ()
2361+ 'collection_name' : self .collection_name .text ().strip (),
2362+ 'auto_collect_threshold' : self .auto_collect_threshold .text ().strip ()
23392363 }
23402364
23412365 try :
@@ -2347,6 +2371,27 @@ def save_config(self):
23472371 except Exception as e :
23482372 QMessageBox .critical (self , "Error" , f"Failed to save configuration: { str (e )} " )
23492373
2374+ def load_config (self ):
2375+ config_path = 'config.json'
2376+ try :
2377+ if os .path .exists (config_path ):
2378+ with open (config_path , 'r' ) as f :
2379+ config = json .load (f )
2380+ self .plex_url .setText (config .get ('plex_url' , '' ))
2381+ self .plex_token .setText (config .get ('plex_token' , '' ))
2382+ self .tvdb_key .setText (config .get ('tvdb_key' , '' ))
2383+ self .tmdb_key .setText (config .get ('tmdb_key' , '' ))
2384+ self .collection_name .setText (config .get ('collection_name' , 'AI Recommended' ))
2385+ self .auto_collect_threshold .setText (config .get ('auto_collect_threshold' , '' ))
2386+ print ("Configuration loaded successfully!" )
2387+ else :
2388+ print ("Configuration file not found." )
2389+ except json .JSONDecodeError as e :
2390+ print (f"Error parsing configuration file: { e } " )
2391+ except Exception as e :
2392+ print (f"Error loading configuration: { e } " )
2393+
2394+
23502395
23512396
23522397 def populate_library_list (self ):
0 commit comments