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

39
main.py
View File

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