initial commit

This commit is contained in:
kassarole 2023-03-28 13:56:26 -04:00
commit 87e0efaaf8
2 changed files with 44 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.epub

43
main.py Normal file
View File

@ -0,0 +1,43 @@
from libgen_api import *
import requests, sys
def searchBook(book):
s = LibgenSearch()
filter = {"Extension": "epub"}
results = s.search_title_filtered(book, filter)
j = 0
if len(results) == 0:
print('No results found. Quiting...')
sys.exit()
for i in results:
i = i['Title']
print(f'[{j}]: {i}')
j+=1
choice = input('Please select the book to download or press enter to exit: ')
if choice == '':
print('Quiting...')
sys.exit()
download = results[int(choice)]
download = s.resolve_download_links(download)
link = download['GET']
result = {"title": results[int(choice)]['Title'],
"author": results[int(choice)]['Author'],
"link": link
}
return result
def downloadBook(bookDict):
print('Downloading book. Please wait...')
r = requests.get(bookDict['link'], allow_redirects=True)
open(bookDict['title']+'.epub', 'wb').write(r.content)
print('Book Downloaded!')
def main():
book = input('Please enter the title of the book you are looking for: ')
results = searchBook(book)
downloadBook(results)
main()