36
36
QDialogButtonBox , QButtonGroup , QToolButton
37
37
)
38
38
from PySide6 .QtCore import (
39
- Qt , QTimer , QThread , Signal , QUrl , QObject , QEventLoop , QSize , QMutex
39
+ Qt , QTimer , QThread , Signal , QUrl , QObject , QEventLoop , QSize , QMutex , QRegularExpression
40
40
)
41
41
from PySide6 .QtGui import (
42
- QPalette , QColor , QPixmap , QPainter , QFont , QIcon , QCloseEvent
42
+ QPalette , QColor , QPixmap , QPainter , QFont , QIcon , QCloseEvent , QRegularExpressionValidator
43
43
)
44
44
from PySide6 .QtNetwork import (
45
45
QNetworkAccessManager , QNetworkRequest , QNetworkReply
@@ -1709,6 +1709,13 @@ def init_config_tab(self):
1709
1709
1710
1710
self .collection_name = QLineEdit ("AI Recommended" )
1711
1711
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 )
1712
1719
1713
1720
plex_group .setLayout (plex_layout )
1714
1721
layout .addWidget (plex_group )
@@ -1775,6 +1782,27 @@ def init_config_tab(self):
1775
1782
config_widget .setLayout (layout )
1776
1783
self .tabs .addTab (config_widget , "Configuration" )
1777
1784
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
+
1778
1806
def show_rating_dialog (self , rating_type , media_type ):
1779
1807
dialog = QDialog (self )
1780
1808
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):
1826
1854
if row :
1827
1855
columns = [description [0 ] for description in cursor .description ]
1828
1856
content_data = dict (zip (columns , row ))
1829
-
1830
-
1857
+
1831
1858
if self .current_items [media_type ] is not None :
1832
1859
self .item_history [media_type ].append (self .current_items [media_type ])
1833
1860
1834
1861
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
+
1835
1877
self .show_next_recommendation (media_type )
1836
1878
1837
1879
except Exception as e :
@@ -1841,6 +1883,7 @@ def submit_rating(self, rating: int, media_type: str):
1841
1883
finally :
1842
1884
self ._rating_mutex .unlock ()
1843
1885
1886
+
1844
1887
1845
1888
def load_config (self ):
1846
1889
config_path = 'config.json'
@@ -2309,33 +2352,14 @@ def reset_model(self):
2309
2352
except Exception as e :
2310
2353
QMessageBox .critical (self , "Error" , f"Failed to reset system: { str (e )} " )
2311
2354
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
-
2332
2355
def save_config (self ):
2333
2356
config = {
2334
2357
'plex_url' : self .plex_url .text ().strip (),
2335
2358
'plex_token' : self .plex_token .text ().strip (),
2336
2359
'tvdb_key' : self .tvdb_key .text ().strip (),
2337
2360
'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 ()
2339
2363
}
2340
2364
2341
2365
try :
@@ -2347,6 +2371,27 @@ def save_config(self):
2347
2371
except Exception as e :
2348
2372
QMessageBox .critical (self , "Error" , f"Failed to save configuration: { str (e )} " )
2349
2373
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
+
2350
2395
2351
2396
2352
2397
def populate_library_list (self ):
0 commit comments