GithubHelp home page GithubHelp logo

costis94 / bookcut Goto Github PK

View Code? Open in Web Editor NEW
186.0 3.0 10.0 177 KB

Command Line Interface tool to download, organise and search free ebooks from your terminal in a moment.

License: MIT License

Python 100.00%
libgen free-ebooks isbn genre organiser python3 python epub ebook openlibrary

bookcut's Introduction

Downloads pypi Code style: black

BookCut is a Python Command Line Interface tool, that help the user to download free e-books, organise them in folders by genre, retrieve book details by ISBN or title, get a list with all the books from a writer and save them to .txt file.

With the help of LibGen, ArXiv and OpenLibrary.

REQUIREMENTS

  • Python 3
  • python3-pip

Installation

  • Install with pip:
pip install bookcut
#or if you have also Python 2
pip3 install bookcut

Usage

Searching and downloading books:

  • Download a single book:
bookcut book -b "White Fang" -a "Jack London"
  • Download a list of books:
bookcut list "FreeEbooksToDownload.txt"
  • Organise a folder full of e-books to folders according to genre:
bookcut organise "full/path/to/folder"

  • Search LibGen, output the results and download e-book:
bookcut search -t 'Homer Odyssey'
  • Search more book repositories with the --repos option:
bookcut search -t 'Homer Odyssey' --repos 'libgen,arxiv'

Available book repositories: Libgen, ArXiv


  • Get the details of a book by title and author, or simply ISBN.
bookcut details -b 'Homer Iliad'
  • Get a list with all the books from an author,with an option to save to .txt:
bookcut all-books -author 'Stephen King'

Searching and downloading articles:

Now you can use bookcut to search and download scientific articles.

  • Search with the Digital Object Identifier:
 bookcut article --doi "10.1126/science.196.4287.293"
  • Search with the exact title:
 bookcut article --title "Ribulose Bisphosphate Carboxylase  A Two-Layered, Square-Shaped Molecule of Symmetry"

Configuration

  • Also you can change some basic settings of BookCut. For more check:
bookcut config --help

TO-DO

  • Add Tests
  • Add documentation
  • Add more sources with free e-books
  • Fix organiser so it can use all types of files
  • Add a logger.

Copyrights

Please use the bookcut app to download only free e-books that are legally distributing through BookCut repositories. Bookcut contributors do not have any responsibility for the use of the tool.

Contributing

Pull requests are welcome, this is my first project so be kind. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

bookcut's People

Contributors

costis94 avatar derphysiker avatar dmwyatt avatar jonasw234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bookcut's Issues

Retrieval error

bookcut, version 1.3.3

Error when retrieving a book. Copy of entire activity.

di@MacPro downloads % bookcut search -t "Theory and Practice of Contrast: Integrating Science, Art and Philosophy"


| __ ) ___ ___ | | / | | |
| _ \ / _ \ / _ | |/ / | | | | | __|
| |
) | (
) | (
) | <| |
| || | |
|/ _/ _/||_\_,|_|


Welcome to BookCut! I'm here to
help you to read your favourite books!


Searching for: Theory and practice of contrast: integrating science, art and philosophy
Connected to: http://libgen.li/
Author(s) ... Extension
1 Mariusz Stanowski ... pdf

[1 rows x 8 columns]

Please enter a number from 1 to 1 to download a book or press "C" to abort search: 1
Connected to: http://libgen.li/
First Link: http://libgen.li//ads.php?md5=a62d7fc594b25398b9ebad673a40ae5c
Traceback (most recent call last):
File "/usr/local/bin/bookcut", line 8, in
sys.exit(entry())
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1137, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/bookcut/bookcut.py", line 130, in searching
details = link_finder(link, mirror_used)
File "/usr/local/lib/python3.9/site-packages/bookcut/search.py", line 40, in link_finder
filename = soup.find('input')['value']
TypeError: 'NoneType' object is not subscriptable

fails when no ~/Documents/Bookcut/ dir is present

~$ bookcut search -t 'catcher in the rye'
Traceback (most recent call last):
File "/usr/local/bin/bookcut", line 5, in
from bookcut.bookcut import entry
File "/usr/local/lib/python3.8/dist-packages/bookcut/bookcut.py", line 42, in
default=pathfinder())
File "/usr/local/lib/python3.8/dist-packages/bookcut/downloader.py", line 42, in pathfinder
os.mkdir(path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/Documents/BookCut'

creating the dir solves this

No mirrors available or no Internet Connection!

When I tried the example command it gave these errors.

Searching for White Fang by Jack London
No mirrors available or no Internet Connection!
No mirrors available or no Internet Connection!
No mirrors available or no Internet Connection!

No mirrors found or bad Internet connection.
Please,try again.

all-books error: JSONDecodeError when doing search

I'm getting error from other types of searches as well, but as an example here's the results of all-books author search.

$ bookcut all-books --author 'Stephen King'

results in:

 ____              _     ____      _
| __ )  ___   ___ | | __/ ___|   _| |_
|  _ \ / _ \ / _ \| |/ / |  | | | | __|
| |_) | (_) | (_) |   <| |__| |_| | |_
|____/ \___/ \___/|_|\_\\____\__,_|\__|


**********************************
Welcome to BookCut! I'm here to
help you to read your favourite books!
**********************************

Start searching for all books by Stephen king:
Connected to: http://www.openlibrary.org
Traceback (most recent call last):
  File "/home/dmwyatt/.local/bin/bookcut", line 8, in <module>
    sys.exit(entry())
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/bookcut/bookcut.py", line 103, in bibliography
    lista = allbooks(author, ratio)
  File "/home/dmwyatt/.local/pipx/venvs/bookcut/lib/python3.8/site-packages/bookcut/bibliography.py", line 21, in main
    data = json.loads(jason)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 3 column 1 (char 2)

Not sure if it's an error from openlibrary or an error in parsing and don't have time to investigate at the moment...

More efficient testing

Hi

In general, test cases should be independent of real server connections.
They should run fast so that one can run them frequently during development.
Also, they shouldn't spam webpages with requests, every time a developer runs the tests.
If a test would require a server connection, use pytest.monkeypatch or something similar to mock it.

However, having a few connection dependent test cases, which run only once before deployment, is probably a good idea.
But, for the previously mentioned reasons, they should be separated from the rest of the tests.
I suggest using @pytest.mark.online or something similar.

Pytest marks allow you to skip specific tests if for example the option -m "not online" is passed.
I would create a conftest.py file to make this behavior the default and only if a new custom --online option is passed to pytest, the tests marked with @pytest.mark.online are run.

I can send you a merge request for that if you want.

Also, don't use copyrighted material, like Hararis "Sapiens", in your test cases, that screams for legal trouble.
On the contrary, I would love for bookcut to also support entirely legal book repositories like project gutenberg in the future, maybe even scientific publications from platforms like arxiv.

IndexError: list index out of range

After selecting a book, the following error is produced:
Traceback (most recent call last):

  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\Scripts\bookcut.exe\__main__.py", line 7, in <module>
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\bookcut.py", line 166, in searching
    choose_a_book(libgen_data)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\search.py", line 284, in choose_a_book
    details = link_finder(link, mirror_used)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\search.py", line 54, in link_finder
    if searcher[0].startswith("http") is False:
IndexError: list index out of range

Can't download articles due to TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

Connected to: https://api.openaccessbutton.org/find
Do you want to download:
High Prevalence of Pericardial Involvement in College Student Athletes Recovering From COVID-19.pdf [y/N]: y
Traceback (most recent call last):
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\Scripts\bookcut.exe_main
.py", line 7, in
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1130, in call
return self.main(*args, **kwargs)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\bookcut.py", line 188, in article
article_search(doi, title)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\article.py", line 20, in article_search
ask_for_downloading(filename, url)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\article.py", line 28, in ask_for_downloading
search_downloader(articlefilename, url)
File "C:\Users\kingb\AppData\Local\Programs\Python\Python310\lib\site-packages\bookcut\search.py", line 17, in search_downloader
total_size = int(response.headers.get("content-length"))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

'NoneType' object is not subscriptable

Hey. I am running into this issue while running the command bookcut book -b "White Fang" -a "Jack London"

Searching for White fang by Jack london
Connected to: http://libgen.li/
'NoneType' object is not subscriptable
Downloading Link:NOT FOUND

no form matching name 'libgen'

$ bookcut book -b "White Fang" -a "Jack London"

Searching for White fang by Jack london
Connected to: http://libgen.li/
Traceback (most recent call last):
  File "c:\users\dustin\.pyenv\pyenv-win\versions\3.9.6\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\dustin\.pyenv\pyenv-win\versions\3.9.6\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\Scripts\bookcut.exe\__main__.py", line 7, in <module>
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\click\core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\click\core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\bookcut\bookcut.py", line 98, in book
    libgen_book_find(
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\bookcut\book.py", line 18, in libgen_book_find
    result = book.search()
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\bookcut\book.py", line 69, in search
    br.select_form("libgen")
  File "C:\Users\dustin\.local\pipx\.cache\3b1d662aa11f0ae\lib\site-packages\mechanize\_mechanize.py", line 681, in select_form
    raise FormNotFoundError("no form matching " + description)
mechanize._mechanize.FormNotFoundError: no form matching name 'libgen'

Probably some HTML changes at libgen.li...

Feature Request: Dot File Configuration / Download Folder Issue

It would be great if we could have a dotfile config for options. Something stored in $HOME/.config so we can keep configured cross platform. Not that there is a lot to configure at the moment. Sans a configuration it might be nice to ask where files should be saved on first run. Lastly setting the Download Folder doesn't seem to work.

macOS Catalina 10.15.6 (19G73)
Bookcut install 8/10/20 from Source

$ bookcut config --download_folder ~/Downloads

>>> Destination path changed!
 >>> /Users/<userName>/Downloads

However, after setting this when I download some book, it does not seem to work.

add md5 parsing to list download option

Can you add support for parsing a list for md5 values that a book is associated with? It would be much cleaner for downloading a specific version of a book. Thanks!

Add more book repositories.

Hi.

The addition of more book repositories, like Project Gutenberg, is a high priority which will enchase the overall usefulness of BookCut.

The first idea is to create a new command, for example:
bookcut gutenberg --search "Moby Dick"

Any recommendation about free book repositories or implementation of the addition is welcome.

Add auto code formatter

Hi

Would you consider adding an auto code formatter like black to the dev dependencies?

In my experience, although it can feel odd in the beginning, not having to care about manually formatting the code definitely helps with refactoring.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.