ebook-downloader/main.py

43 lines
1.2 KiB
Python
Raw Normal View History

2023-03-28 17:56:26 +00:00
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()