Added unattended mode

This commit is contained in:
Kass Rode 2023-03-28 16:56:48 -04:00
parent 87e0efaaf8
commit a598ce3b1c
2 changed files with 28 additions and 12 deletions

23
main.py
View File

@ -1,7 +1,7 @@
from libgen_api import *
import requests, sys
import requests, sys, getopt
def searchBook(book):
def searchBook(book, unattended=False):
s = LibgenSearch()
filter = {"Extension": "epub"}
results = s.search_title_filtered(book, filter)
@ -11,12 +11,16 @@ def searchBook(book):
sys.exit()
for i in results:
i = i['Title']
if unattended == False:
print(f'[{j}]: {i}')
j+=1
if unattended is False:
choice = input('Please select the book to download or press enter to exit: ')
if choice == '':
print('Quiting...')
sys.exit()
elif unattended is True:
choice = 0
download = results[int(choice)]
download = s.resolve_download_links(download)
link = download['GET']
@ -34,10 +38,21 @@ def downloadBook(bookDict):
print('Book Downloaded!')
def main():
def main(argv):
if len(argv) == 0:
book = input('Please enter the title of the book you are looking for: ')
results = searchBook(book)
downloadBook(results)
else:
opts, args = getopt.getopt(argv, "hb:",["help=","book="])
for opt, arg in opts:
if opt in ('-h', "--help"):
print('main.py -b <booktitle>')
elif opt in ('-b', '--book'):
book = arg
results = searchBook(book, unattended=True)
downloadBook(results)
main()
if __name__ == "__main__":
main(sys.argv[1:])

1
requirments.txt Normal file
View File

@ -0,0 +1 @@
libgen_api==1.0.0