From 87e0efaaf82bcb30abb79f2b1df903065927ae36 Mon Sep 17 00:00:00 2001 From: kassarole Date: Tue, 28 Mar 2023 13:56:26 -0400 Subject: [PATCH] initial commit --- .gitignore | 1 + main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b333c38 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.epub \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..7ea15d6 --- /dev/null +++ b/main.py @@ -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() \ No newline at end of file