Reference

A technical reference for the libgentools package.

Contents:


libgentools.make_soup(url)

Make soup-making easier.

Parameters:

url (str) – The URL of the LibGen page to be scraped.

Returns:

The raw scraped results from the LibGen page.

Return type:

BeautifulSoup object

Raises:

ConnectionError – If the LibGen website is unreachable.

SearchRequest class

class libgentools.SearchRequest(query=None)

Handles search requests and generates a list of results.

Attributes:
query (str): The search query for the request.

Could be an author, title or ISBN. Serves as a parameter for the constructor.

results (list): A list of SEDs generated from the search query.

SearchRequest.__init__(query=None)

Constructor method.

Parameters:

query (str) – The search query for the request (default is None).

Raises:

QueryError – If query is empty or less than 3 characters.

SearchRequest.get_results(url)

Scrape and return results from the LibGen website.

Parameters:

url (str) – The Libgen URL of the request. Concatenated from the url_base and query variables.

Returns:

A raw list of BeautifulSoup objects. The list contains the <tr> tags from every page of search results from the LibGen website.

Return type:

list

SearchRequest.create_entry_list(table)

Create and return a list of entries as a list of SEDs.

Parameters:

table (list) – A raw list of BeautifulSoup objects. Contains <tr> tags, returned by the get_results method.

Returns:

A list of standard entry dictionaries.

Return type:

list

Results class

class libgentools.Results(results)

Stores and manages search results.

Attributes:

entries (list): Stores the results as a list of SEDs.

Methods:
filter_entries(filters, mode=”partial”):

Filters results by a standard filtering dictionary. Partial or exact filtering are both available modes.

download(entry, path):

Downloads the selected entry to a specified location.

Results.__init__(results)

Constructor method.

Parameters:

results (list) – A list of SEDs, returned either by SearchRequest.create_entry_list or Results.filter_entries.

Results.filter_entries(filters, mode='partial')

Filter by entry properties and return a new Results instance.

Parameters:
  • filters (dict) – A standard filter dictionary.

  • mode (str) – The filtering mode used by the method (exact/partial).

Returns:

A new instance of the Results class. The constructor of the new instance uses the list of SEDs generated by this method as a parameter.

Return type:

Results

Raises:

FilterError – If an invalid filter is encountered.

Results.get_download_urls(entry)

Resolve links from mirror(s).

Parameters:

entry (dict) – The entry (SED) selected for downloading.

Returns:

A list of the download URLs as strings.

Return type:

list

Results.download(entry, path)

Download entry, default method is GET from the first mirror.

Parameters:
  • entry (dict) – The entry (SED) selected for downloading.

  • path (str) – The path of the folder where the file should be downloaded to.

QueryError exception

exception libgentools.QueryError

Raise when query is too short.

FilterError exception

exception libgentools.FilterError

Raise when an invalid filter is encountered.