Remove LibGen provider and package

This commit is contained in:
advplyr 2022-07-04 19:14:52 -05:00
parent 354cefb9f4
commit 6fc70b8656
4 changed files with 5 additions and 2247 deletions

2157
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -42,11 +42,10 @@
"fs-extra": "^10.0.0",
"htmlparser2": "^8.0.1",
"jsonwebtoken": "^8.5.1",
"libgen": "^2.1.0",
"node-ffprobe": "^3.0.0",
"node-stream-zip": "^1.15.0",
"recursive-readdir-async": "^1.1.8",
"socket.io": "^4.4.1",
"xml2js": "^0.4.23"
}
}
}

View File

@ -1,5 +1,4 @@
const OpenLibrary = require('../providers/OpenLibrary')
const LibGen = require('../providers/LibGen')
const GoogleBooks = require('../providers/GoogleBooks')
const Audible = require('../providers/Audible')
const iTunes = require('../providers/iTunes')
@ -10,7 +9,6 @@ const { levenshteinDistance } = require('../utils/index')
class BookFinder {
constructor() {
this.openLibrary = new OpenLibrary()
this.libGen = new LibGen()
this.googleBooks = new GoogleBooks()
this.audible = new Audible()
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) {
var books = await this.openLibrary.searchTitle(title)
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)
} else if (provider === 'itunes') {
books = await this.getiTunesAudiobooksResults(title, author)
} else if (provider === 'libgen') {
books = await this.getLibGenResults(title, author, maxTitleDistance, maxAuthorDistance)
} else if (provider === 'openlibrary') {
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 {
books = await this.getOpenLibResults(title, author, maxTitleDistance, maxAuthorDistance)
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)
}
books = await this.getGoogleBooksResults(title, author)
}
if (!books.length && !options.currentlyTryingCleaned) {

View File

@ -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