Giter VIP home page Giter VIP logo

libgen_to_txt's Introduction

Libgen to txt

This repo will convert books from libgen to plain txt or markdown format. This repo does not contain any books, only the scripts to download and convert them.

The scripts use a seedbox to download the libgen torrents, copy them to your machine/cloud instance, convert them, and enrich them with metadata. Processing will be by chunk, with configurable parallelization.

It currently only works for the libgen rs nonfiction section, but PRs welcome for additional compatibility. It will cost about $300 to convert all of libgen rs nonfiction if you're using a cloud instance, and take about 1 week to process everything (bandwidth-bound). You'll need 3TB of disk space.

Community

Discord is where we discuss future development.

Install

This was only tested on Ubuntu 23.04 and Python 3.11. It should work with Python 3.8+.

Setup dependencies

  • apt-get update
  • xargs apt-get install -y < apt-requirements.txt
  • pip install -r requirements.txt

Import libgen rs metadata

  • Download the metadata DB (look for "metadata" and the nonfiction one)
  • bsdtar -xf libgen.rar
  • Start mariadb
    • systemctl start mariadb.service
  • Setup DB user
    • mariadb
    • GRANT ALL ON *.* TO 'libgen'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION; # Replace with your password
    • FLUSH PRIVILEGES;
    • create database libgen;
    • exit
  • Import metadata
    • git clone https://annas-software.org/AnnaArchivist/annas-archive.git
    • pv libgen.sql | PYTHONIOENCODING=UTF8:ignore python3 annas-archive/data-imports/scripts/helpers/sanitize_unicode.py | mariadb -h localhost --default-character-set=utf8mb4 -u libgen -ppassword libgen
      • You may need to add the --binary-mode -o flag to the mariadb command above
      • And the --force flag if you get errors

Setup seedbox

Configuration

  • Get a putio oauth token following these instructions
  • Either set the env var PUTIO_TOKEN, or create a local.env file with PUTIO_TOKEN=yourtoken
  • Inspect libgen_to_txt/settings.py. You can edit settings directly to override them, set an env var, or add the key to a local.env file.
    • You may particularly want to look at CONVERSION_WORKERS and DOWNLOAD_WORKERS to control parallelization. The download step is the limiting factor, and too many download workers will saturate your bandwidth.

Usage

  • python download_and_clean.py to download and clean the data
    • --workers to control number of download workers (how many parallel downloads happen at once)
    • --no_download to only process libgen chunks that already exist on the seedbox
    • --max controls how many chunks at most to process (for testing)
    • --no_local_delete to avoid deleting chunks locally after they're downloaded. Mainly useful for debugging.

You should see progress information printed out - it will take several weeks to finish depending on bandwidth and conversion method (see below). Check the txt and processed folders to monitor.

Markdown conversion

This can optionally be integrated with marker to do high-accuracy pdf to markdown conversion. To use marker, first install it, then:

  • CONVERSION_METHOD to marker
  • MARKER_FOLDER to the path to the marker folder

CONVERSION_WORKERS will control how many marker processes per GPU are run in parallel. Marker takes about 2.5GB of VRAM per process, so set this accordingly.

You can adjust additional settings around how marker is integrated using the MARKER_* settings. In particular, pay attention to the timeouts. These ensure that conversion doesn't get stuck on a chunk. Marker can run on CPU or GPU, but is much faster on GPU. With 4x GPUs, a single libgen chunk should take about 1 hour to process.

Cloud storage

You can store the converted txt/markdown files in a s3-compatible storage backend as they're processed using s3fs. Here's how:

  • sudo apt install s3fs
  • echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
  • chmod 600 ${HOME}/.passwd-s3fs
  • s3fs BUCKET_NAME LOCAL_DIR -o url=STORAGE_URL -o use_cache=/tmp -o allow_other -o use_path_request_style -o uid=1000 -o gid=1000 -o passwd_file=${HOME}/.passwd-s3fs

libgen_to_txt's People

Contributors

vikparuchuri avatar

Stargazers

Caleb Fenton avatar Jiajun Zou avatar 深圳弘谷科技有限公司 avatar Volkan Çiçek avatar  avatar hltdev8642 avatar  avatar Robert avatar  avatar Ryan Riebling avatar Shankar Sivarajan avatar  avatar Jean Kaddour avatar Fabio Dias Rollo avatar vv111y avatar Rok Gerželj avatar Jeff Carpenter avatar Mark Kusper avatar Brian Wilcox avatar tom bouillut avatar  avatar kingfly avatar Simon avatar Jo Kroese avatar Jacopo Parvizi avatar Titusz avatar  avatar  avatar Noah Persaud avatar Abe Isleem avatar German Novikov avatar Sebastian Nehrdich avatar Mohio Din Farhan avatar Tripp Lyons avatar RyzeNGrind avatar  avatar Andrew Zhu avatar  avatar  avatar Junyan Xu avatar  avatar Hussein Lezzaik avatar Dhruv Anand avatar Grandad avatar Adrian Dayrit avatar  avatar Kadu Diógenes avatar Ian Maurer avatar Christian avatar Alun Cennyth Stokes avatar kemo avatar karlmc15 avatar  avatar  avatar khalid ghiboub avatar Arpan Tripathi avatar  avatar  avatar Sam avatar PKG avatar Satyam Tiwary avatar  avatar Brandon C. Rojas avatar  avatar  avatar Clayton Kehoe avatar Lê Anh Duy avatar Bryan Lim avatar Alex Wu avatar Sushil avatar weiliang avatar Enes GUL avatar  avatar Prakhar Agarwal avatar Pablo P. avatar Wang Qi avatar  avatar Rex O. Amin avatar Marko avatar my avatar Jeff Hammerbacher avatar Sofian Mejjoute avatar  avatar  avatar Matthew McAteer avatar  avatar Remy J Kim avatar  avatar moneya avatar  avatar Abdullah Mohammed avatar Ross Hartmann avatar lzghades avatar Hongwei Qin avatar LCK avatar Matt Stancliff avatar  avatar mutian avatar Joseph Jennings avatar Xiao avatar

Watchers

Vishal Goklani avatar Sholto Maud avatar  avatar Junyan Xu avatar  avatar  avatar

libgen_to_txt's Issues

Sharing dataset

Thanks for sharing! Could you possibly share the collected dataset to help avoid spending time and resources (bandwidth and money) again? Thanks!

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.