@@ -72,6 +72,7 @@ class BlacklistedTagProcessor implements RunnableScanner<StatusBase> {
7272 const blacklistedTagsArr = blacklistedTags . split ( ',' ) ;
7373
7474 const pageLimit = settings . main . blacklistedTagsLimit ;
75+ const invalidKeywords = new Set < string > ( ) ;
7576
7677 if ( blacklistedTags . length === 0 ) {
7778 return ;
@@ -87,6 +88,19 @@ class BlacklistedTagProcessor implements RunnableScanner<StatusBase> {
8788
8889 // Iterate for each tag
8990 for ( const tag of blacklistedTagsArr ) {
91+ const keywordDetails = await tmdb . getKeywordDetails ( {
92+ keywordId : Number ( tag ) ,
93+ } ) ;
94+
95+ if ( keywordDetails === null ) {
96+ logger . warn ( 'Skipping invalid keyword in blacklisted tags' , {
97+ label : 'Blacklisted Tags Processor' ,
98+ keywordId : tag ,
99+ } ) ;
100+ invalidKeywords . add ( tag ) ;
101+ continue ;
102+ }
103+
90104 let queryMax = pageLimit * SortOptionsIterable . length ;
91105 let fixedSortMode = false ; // Set to true when the page limit allows for getting every page of tag
92106
@@ -102,24 +116,51 @@ class BlacklistedTagProcessor implements RunnableScanner<StatusBase> {
102116 throw new AbortTransaction ( ) ;
103117 }
104118
105- const response = await getDiscover ( {
106- page,
107- sortBy,
108- keywords : tag ,
109- } ) ;
110- await this . processResults ( response , tag , type , em ) ;
111- await new Promise ( ( res ) => setTimeout ( res , TMDB_API_DELAY_MS ) ) ;
112-
113- this . progress ++ ;
114- if ( page === 1 && response . total_pages <= queryMax ) {
115- // We will finish the tag with less queries than expected, move progress accordingly
116- this . progress += queryMax - response . total_pages ;
117- fixedSortMode = true ;
118- queryMax = response . total_pages ;
119+ try {
120+ const response = await getDiscover ( {
121+ page,
122+ sortBy,
123+ keywords : tag ,
124+ } ) ;
125+
126+ await this . processResults ( response , tag , type , em ) ;
127+ await new Promise ( ( res ) => setTimeout ( res , TMDB_API_DELAY_MS ) ) ;
128+
129+ this . progress ++ ;
130+ if ( page === 1 && response . total_pages <= queryMax ) {
131+ // We will finish the tag with less queries than expected, move progress accordingly
132+ this . progress += queryMax - response . total_pages ;
133+ fixedSortMode = true ;
134+ queryMax = response . total_pages ;
135+ }
136+ } catch ( error ) {
137+ logger . error ( 'Error processing keyword in blacklisted tags' , {
138+ label : 'Blacklisted Tags Processor' ,
139+ keywordId : tag ,
140+ errorMessage : error . message ,
141+ } ) ;
119142 }
120143 }
121144 }
122145 }
146+
147+ if ( invalidKeywords . size > 0 ) {
148+ const currentTags = blacklistedTagsArr . filter (
149+ ( tag ) => ! invalidKeywords . has ( tag )
150+ ) ;
151+ const cleanedTags = currentTags . join ( ',' ) ;
152+
153+ if ( cleanedTags !== blacklistedTags ) {
154+ settings . main . blacklistedTags = cleanedTags ;
155+ await settings . save ( ) ;
156+
157+ logger . info ( 'Cleaned up invalid keywords from settings' , {
158+ label : 'Blacklisted Tags Processor' ,
159+ removedKeywords : Array . from ( invalidKeywords ) ,
160+ newBlacklistedTags : cleanedTags ,
161+ } ) ;
162+ }
163+ }
123164 }
124165
125166 private async processResults (
0 commit comments