initial commit
This commit is contained in:
commit
87e0efaaf8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.epub
|
43
main.py
Normal file
43
main.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user