mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Remove LibGen provider and package
This commit is contained in:
		
							parent
							
								
									354cefb9f4
								
							
						
					
					
						commit
						6fc70b8656
					
				
							
								
								
									
										2157
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2157
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -42,11 +42,10 @@ | |||||||
|     "fs-extra": "^10.0.0", |     "fs-extra": "^10.0.0", | ||||||
|     "htmlparser2": "^8.0.1", |     "htmlparser2": "^8.0.1", | ||||||
|     "jsonwebtoken": "^8.5.1", |     "jsonwebtoken": "^8.5.1", | ||||||
|     "libgen": "^2.1.0", |  | ||||||
|     "node-ffprobe": "^3.0.0", |     "node-ffprobe": "^3.0.0", | ||||||
|     "node-stream-zip": "^1.15.0", |     "node-stream-zip": "^1.15.0", | ||||||
|     "recursive-readdir-async": "^1.1.8", |     "recursive-readdir-async": "^1.1.8", | ||||||
|     "socket.io": "^4.4.1", |     "socket.io": "^4.4.1", | ||||||
|     "xml2js": "^0.4.23" |     "xml2js": "^0.4.23" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| const OpenLibrary = require('../providers/OpenLibrary') | const OpenLibrary = require('../providers/OpenLibrary') | ||||||
| const LibGen = require('../providers/LibGen') |  | ||||||
| const GoogleBooks = require('../providers/GoogleBooks') | const GoogleBooks = require('../providers/GoogleBooks') | ||||||
| const Audible = require('../providers/Audible') | const Audible = require('../providers/Audible') | ||||||
| const iTunes = require('../providers/iTunes') | const iTunes = require('../providers/iTunes') | ||||||
| @ -10,7 +9,6 @@ const { levenshteinDistance } = require('../utils/index') | |||||||
| class BookFinder { | class BookFinder { | ||||||
|   constructor() { |   constructor() { | ||||||
|     this.openLibrary = new OpenLibrary() |     this.openLibrary = new OpenLibrary() | ||||||
|     this.libGen = new LibGen() |  | ||||||
|     this.googleBooks = new GoogleBooks() |     this.googleBooks = new GoogleBooks() | ||||||
|     this.audible = new Audible() |     this.audible = new Audible() | ||||||
|     this.iTunesApi = new iTunes() |     this.iTunesApi = new iTunes() | ||||||
| @ -123,20 +121,6 @@ class BookFinder { | |||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance) { |  | ||||||
|     var books = await this.libGen.search(title) |  | ||||||
|     if (this.verbose) Logger.debug(`LibGen Book Search Results: ${books.length || 0}`) |  | ||||||
|     if (books.errorCode) { |  | ||||||
|       Logger.error(`LibGen Search Error ${books.errorCode}`) |  | ||||||
|       return [] |  | ||||||
|     } |  | ||||||
|     var booksFiltered = this.filterSearchResults(books, title, author, maxTitleDistance, maxAuthorDistance) |  | ||||||
|     if (!booksFiltered.length && books.length) { |  | ||||||
|       if (this.verbose) Logger.debug(`Search has ${books.length} matches, but no close title matches`) |  | ||||||
|     } |  | ||||||
|     return booksFiltered |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) { |   async getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) { | ||||||
|     var books = await this.openLibrary.searchTitle(title) |     var books = await this.openLibrary.searchTitle(title) | ||||||
|     if (this.verbose) Logger.debug(`OpenLib Book Search Results: ${books.length || 0}`) |     if (this.verbose) Logger.debug(`OpenLib Book Search Results: ${books.length || 0}`) | ||||||
| @ -185,27 +169,10 @@ class BookFinder { | |||||||
|       books = await this.getAudibleResults(title, author, asin) |       books = await this.getAudibleResults(title, author, asin) | ||||||
|     } else if (provider === 'itunes') { |     } else if (provider === 'itunes') { | ||||||
|       books = await this.getiTunesAudiobooksResults(title, author) |       books = await this.getiTunesAudiobooksResults(title, author) | ||||||
|     } else if (provider === 'libgen') { |  | ||||||
|       books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance) |  | ||||||
|     } else if (provider === 'openlibrary') { |     } else if (provider === 'openlibrary') { | ||||||
|       books = await this.getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) |       books = await this.getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) | ||||||
|     } else if (provider === 'all') { |  | ||||||
|       var lbBooks = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance) |  | ||||||
|       var olBooks = await this.getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) |  | ||||||
|       books = books.concat(lbBooks, olBooks) |  | ||||||
|     } else { |     } else { | ||||||
|       books = await this.getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance) |       books = await this.getGoogleBooksResults(title, author) | ||||||
|       var hasCloseMatch = books.find(b => (b.totalDistance < 2 && b.totalPossibleDistance > 6)) |  | ||||||
|       if (!hasCloseMatch) { |  | ||||||
|         Logger.debug(`Book Search, openlib has no super close matches - get libgen results also`) |  | ||||||
|         var lbBooks = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance) |  | ||||||
|         books = books.concat(lbBooks) |  | ||||||
|       } |  | ||||||
| 
 |  | ||||||
|       if (!books.length && author && options.fallbackTitleOnly) { |  | ||||||
|         Logger.debug(`Book Search, no matches for title and author.. check title only`) |  | ||||||
|         return this.search(provider, title, null, options) |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (!books.length && !options.currentlyTryingCleaned) { |     if (!books.length && !options.currentlyTryingCleaned) { | ||||||
|  | |||||||
| @ -1,57 +0,0 @@ | |||||||
| var libgen = require('libgen') |  | ||||||
| 
 |  | ||||||
| class LibGen { |  | ||||||
|   constructor() { |  | ||||||
|     this.mirror = null |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async init() { |  | ||||||
|     this.mirror = await libgen.mirror() |  | ||||||
|     console.log(`${this.mirror} is currently fastest`) |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async search(queryTitle) { |  | ||||||
|     if (!this.mirror) { |  | ||||||
|       await this.init() |  | ||||||
|     } |  | ||||||
|     queryTitle = queryTitle.replace(/'/g, '') |  | ||||||
|     queryTitle = encodeURIComponent(queryTitle); |  | ||||||
|     var options = { |  | ||||||
|       mirror: this.mirror, |  | ||||||
|       query: queryTitle, |  | ||||||
|       search_in: 'title' |  | ||||||
|     } |  | ||||||
|     var httpsMirror = this.mirror |  | ||||||
|     if (httpsMirror.startsWith('http:')) { |  | ||||||
|       httpsMirror = httpsMirror.replace('http:', 'https:') |  | ||||||
|     } |  | ||||||
|     // console.log('LibGen Search Options', options)
 |  | ||||||
|     try { |  | ||||||
|       const data = await libgen.search(options) |  | ||||||
|       let n = data.length |  | ||||||
|       // console.log(`${n} results for "${options.query}"`)
 |  | ||||||
|       var cleanedResults = [] |  | ||||||
|       while (n--) { |  | ||||||
|         var resultObj = { |  | ||||||
|           id: data[n].id, |  | ||||||
|           title: data[n].title, |  | ||||||
|           author: data[n].author, |  | ||||||
|           publisher: data[n].publisher, |  | ||||||
|           description: data[n].descr, |  | ||||||
|           cover: `${httpsMirror}/covers/${data[n].coverurl}`, |  | ||||||
|           year: data[n].year |  | ||||||
|         } |  | ||||||
|         if (!resultObj.title) continue; |  | ||||||
|         cleanedResults.push(resultObj) |  | ||||||
|       } |  | ||||||
|       return cleanedResults |  | ||||||
|     } catch (err) { |  | ||||||
|       console.error(err) |  | ||||||
|       return { |  | ||||||
|         errorCode: 500 |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| module.exports = LibGen |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user