@@ -120,10 +120,17 @@ class LubimyCzytacProvider {
120120 }
121121
122122 return { ...match , similarity : combinedSimilarity } ;
123- } ) . sort ( ( a , b ) => b . similarity - a . similarity ) ;
123+ } ) . sort ( ( a , b ) => {
124+ // Primary sort: by similarity (descending)
125+ if ( b . similarity !== a . similarity ) {
126+ return b . similarity - a . similarity ;
127+ }
124128
125- // Limit the number of matches if needed
126- allMatches = allMatches . slice ( 0 , 20 ) ; // Max 20 matches
129+ // Secondary sort: prioritize audiobooks if similarity is equal
130+ const typeValueA = a . type === 'audiobook' ? 1 : 0 ;
131+ const typeValueB = b . type === 'audiobook' ? 1 : 0 ;
132+ return typeValueB - typeValueA ;
133+ } ) . slice ( 0 , 20 ) ; // Max 20 matches
127134
128135 const fullMetadata = await Promise . all ( allMatches . map ( match => this . getFullMetadata ( match ) ) ) ;
129136
@@ -136,38 +143,6 @@ class LubimyCzytacProvider {
136143 }
137144 }
138145
139- parseSearchResults ( responseData , type ) {
140- const decodedData = this . decodeText ( responseData ) ;
141- const $ = cheerio . load ( decodedData ) ;
142- const matches = [ ] ;
143-
144- $ ( '.authorAllBooks__single' ) . each ( ( index , element ) => {
145- const $book = $ ( element ) ;
146- const $bookInfo = $book . find ( '.authorAllBooks__singleText' ) ;
147-
148- const title = $bookInfo . find ( '.authorAllBooks__singleTextTitle' ) . text ( ) . trim ( ) ;
149- const bookUrl = $bookInfo . find ( '.authorAllBooks__singleTextTitle' ) . attr ( 'href' ) ;
150- const authors = $bookInfo . find ( 'a[href*="/autor/"]' ) . map ( ( i , el ) => $ ( el ) . text ( ) . trim ( ) ) . get ( ) ;
151-
152- if ( title && bookUrl ) {
153- matches . push ( {
154- id : bookUrl . split ( '/' ) . pop ( ) ,
155- title : this . decodeUnicode ( title ) ,
156- authors : authors . map ( author => this . decodeUnicode ( author ) ) ,
157- url : `${ this . baseUrl } ${ bookUrl } ` ,
158- type : type ,
159- source : {
160- id : this . id ,
161- description : this . name ,
162- link : this . baseUrl ,
163- } ,
164- } ) ;
165- }
166- } ) ;
167-
168- return matches ;
169- }
170-
171146 async getFullMetadata ( match ) {
172147 try {
173148 const response = await axios . get ( match . url , { responseType : 'arraybuffer' } ) ;
0 commit comments