Skip to main content

A Python library for downloading content from Library Genesis.

Project description

libgentools

A Python library for downloading content from Library Genesis.

The library serves as a backend for libgenx, a GUI/CLI application for using LibGen, but it is available for implementation in any other Python project as well.

Developers are welcome to fork this repository.

Contents:

Installation

It is always recommended to use a Python environment manager, like pipenv: pipenv install libgentools

But it is also possible to install the package system-wide: pip install libgentools

Requirements

Usage

After installing from pip, import the library to your Python script:

import libgentools

or

from libgentools import SearchRequest, Results # ...

Classes

SearchRequest

The class handles search requests and generates a list of results.

A new instance can be created with the query parameter. The query should be an author, title (or both) or an ISBN number:

request = SearchRequest('principles of geology')

The request.results variable now holds the search results as a list of Standard Entry Dictionaries (SEDs).

Standard Entry Dictionary:

entries = [{'id': 1234,
            'isbn': ["ISBN", "ISBN"],
            'auth': "Author",
            'title': "Title",
            'pub': "Publisher",
            'year': 1999,
            'pp': "Pages",
            'lang': "Language",
            'size': "Size",
            'ext': "Extension",
            'mirrors': ["url", "url"]}]

A new Results instance can be constructed from the request.results variable:

results = Results(request.results)

Results

The class stores and manages search results.

A new instance can be created from the results variable of a SearchRequest instance:

results = Results(request.results)

The results are now stored in the results.entries variable of the new instance as a list of SEDs.

Filtering

The filter_entries method filters the results using a Standard Filter Dictionary and the filtering mode as parameters.

Standard Filter Dictionary:

filters = {'auth': "Author", 'ext': "Extension", 'year': "1999-2010"}

Every value must be a string! The following fields can be used in the filter:

  • auth: author
  • title: title
  • year: as an interval (e.g. "1999-2010") or exact year (e.g. "2000")
  • lang: use standard language codes
  • ext: use any of the popular formats (e.g. "pdf", "epub", "mobi", etc.)

The FILTERS dictionary can be used to interpret command line arguments in applications.

The second parameter is the filtering mode: "exact" or "partial" (the default is "partial"). The method returns exact or partial matches based on this parameter.

The filtered results are returned by the method as a new Results instance:

filtered_results = results.filter_entries(filters, "exact")
Downloading

Any entry from a list of results (SEDs) can be downloaded using the download method:

downloaded = results.download(entry, dirname(abspath(sys.argv[0])))

The first parameter is the entry (an SED), the second is the path where the file should be downloaded (in this case the location of the script - dirname() and abspath() can be imported from os.path). The name of the downloaded file will be the LibGen ID of the entry. The value of the downloaded variable will be true if the download was successful or false otherwise.

Exceptions

QueryError

The constructor of the SearchRequest class raises this error if the query is empty or its length is less than three characters.

FilterError

The filter_entries method of the Results class raises this error if there is an invalid key in the filtering dictionary (validated by FILTERS) or the year filter has a wrong format.

Reporting errors

Any error can be reported through e-mail with the exact error message and/or console screenshot. Alternatively, an issue can be opened.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libgentools-0.0.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libgentools-0.0.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file libgentools-0.0.1.tar.gz.

File metadata

  • Download URL: libgentools-0.0.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for libgentools-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3a2cfdcac5b48b8092096270d75b36b7d73be881cc06a9e7099b948f6601c08c
MD5 7a141d65e6db2dbddc0f56d76d89a1d6
BLAKE2b-256 ee9a58bc69127441e420a34d143ad064654f4d2c6b0da7dd928504e442679f30

See more details on using hashes here.

File details

Details for the file libgentools-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: libgentools-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for libgentools-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9373b51cfdd6348ec6c086b3bc0e73ea6285b05add314a1dd99a4415ba816ab3
MD5 216047c7aecdf9d2138cbe234d7f41c0
BLAKE2b-256 f5e0876727b535b8c4cdc52c1cdcb152bfe54f4db39ba71f1a0befa9d4710b04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page