News for hackers. Stuff that matters.
Re:LibGen's Bloat Problem by c-fe on Sunday August 21, 2022 @09:36AM (#32540057)
This is a bit anecdotal, but I did upload a book to libgen. I am am avid user of the site, and during my thesis research I was looking for a specific book and could not find it on there. I did however find it on archive.org. I spent the better half of one afternoon extracting the book from archive.org with some Adobe software, since I had to circumvent some DRM and other things, and all of this was also novel to me. In the end I got a scanned PDF, which had several hundred MB. I managed to reduce it to 47 MB, however further reduction was not easily possible at least not with the means I knew or had at my disposal. I uploaded this version to libgen.

I do agree that there may be some large files on there, however I dont agree with removing them. I spent some hours to put this book on there so others who need it can access it within seconds. Removing it because it is too large would void all this effort and require future users to go through a similar process than i did just to browse through the book.

Also any book published today is most likely available in some ebook format, which is much smaller in size, so I dont think that the size of libgen will continue to grow at the same pace as it is doing now.

Re:LibGen's Bloat Problem by liberalgeneral on Sunday August 21, 2022 @10:35AM (#32540592)
Thank you for your efforts!

To be clear, I am not advocating for the removal of any files larger than 30 MiB (or any other arbitrary hard limits). It'd be great of course to flag large files for further review, but the current software doesn't do a great job at crowdsourcing these kinds of tasks (another one being deduplication) sadly.

Given the very little amount of volunteer-power, I'm suggesting that a "lean edition" of LibGen can still be immensely useful to many people.

Re:LibGen's Bloat Problem by ssivark on Sunday August 21, 2022 @11:12AM (#32540950)
Files are a very bad unit to elevate in importance, and number of files or file size are really bad proxy metrics, especially without considering the statistical distribution of downloads (leave alone the question of what is more "important"!). Eg: Junk that’s less than the size limit is implicitly being valued over good content that happens to be larger in size. Textbooks & reference books will likewise get filtered out with higher likelihood — and that would screw students in countries where they cannot afford them (which might arguable be a more important audience to some, compared to those downloading comics). Etc.

After all this, the most likely human response from people who really depend on this platform would be to slice a big file into volumes under the size limit. Seems to be a horrible UX downgrade in the medium to long term for no other reason than satisfying some arbitrary metric of legibility[1].

Here's a different idea -- might it be worthwhile to convert the larger files to better compressed versions eg. PDF -> DJVU? This would lead to a duplication in the medium term, but if one sees a convincing pattern that users switch to the compressed versions without needing to come back to the larger versions, that would imply that the compressed version works and the larger version could eventually be garbage collected.

Thinking in an even more open-ended manner, if this corpus is not growing at a substantial rate, can we just wait out a decade or so of storage improvements before this becomes a non-issue? How long might it take for storage to become 3x, 10x, 30x cheaper?

[1]: https://www.ribbonfarm.com/2010/07/26/a-big-little-idea-call...

Re:LibGen's Bloat Problem by didgetmaster on Sunday August 21, 2022 @02:55PM (#32543272)
> can we just wait out a decade or so of storage improvements before this becomes a non-issue?

I'm not sure that there is anything on the horizon which would make duplicate data a 'non-issue'. Capacities are certainly growing, so within a decade we might see 100TB HDDs available and affordable 20TB SSDs. But that does not solve the bandwidth issues. It still takes a long, long time to transfer all the data.

The fastest HDD is still under 300MB/s which means it takes a minimum of 20 hours to read all the data off a 20TB HDD. That is if you could somehow get it to read the whole thing at the maximum sustained read speed.

SSDs are much faster, but it will always be easier to double the capacity than it is to double the speed.

Re:LibGen's Bloat Problem by fragmede on Sunday August 21, 2022 @06:28PM (#32545129)
The problem isn't the technology, it's the cost. Given a far larger budget, you wouldn't run the hard drives at anywhere near capacity, in order to gain a read speed advantage by running a ton in parallel. That'll let you read 20 TB in a hour if you can afford it. Put it this way; Netflix is able to do 4k video and that's far more intensive.
Re:LibGen's Bloat Problem by titoCA321 on Monday August 22, 2022 @02:12AM (#32547929)
There's people that contribute to the LibGen ecosystem but unfortunately it in areas that don't really benefit the community. Users don't need another CLI tool for LibGen, nor does the community need another Bot. Unfortunately that's what folks do, make extensions, CLI tools and bots that benefit next to no one and release all over silly willy with no support.
Re:LibGen's Bloat Problem by account42 on Monday August 22, 2022 @10:14AM (#32551669)
So what have you done that benefits the community and why do you think you get to make that decision for others?
Re:LibGen's Bloat Problem by titoCA321 on Monday August 22, 2022 @04:58PM (#32557154)
I'm not the OP that's calling for reducing Bloat. I don't use LibGen enough to give a care one way or the other.
Re:LibGen's Bloat Problem by culi on Sunday August 21, 2022 @02:50PM (#32543233)
I've always wanted to contribute to LibGen. Got me through college and has powered my Wikipedia editing hobby

Are there any good guides out there for best practices for minimizing files, scanning books, etc?

Re:LibGen's Bloat Problem by generationP on Sunday August 21, 2022 @03:33PM (#32543599)
There's a bunch. Here's what I do (for black-and-white text; I'm not sure how to deal with more complex scenarios):

Scan with 600dpi resolution. Nevermind that this gives huge output files; you'll compress them to something much smaller at the end, and the better your resolution, the stronger compression you can use without losing readability.

While scanning, periodically clean the camera or the scanner screen, to avoid speckles of dirt on the scan.

The ideal output formats are TIF and PNG; use them if your scanner allows. PDF is also fine (you'll then have to extract the pages into TIF using pdfimages or using ScanKromsator). Use JPG only as a last resort, if nothing else works.

Once you have TIF, PNG or JPG files, put them into a folder. Make sure that the files are sorted correctly: IIRC, the numbers in their names should match their order (i.e., blob030 must be an earlier page than blah045; it doesn't matter whether the numbers are contiguous or what the non-numerical characters are). (I use the shell command mmv for convenient renaming.)

Import this folder into ScanTailor ( https://github.com/4lex4/scantailor-advanced/releases ), save the project, and run it through all 6 stages.

Stage 1 (Fix Orientation): Use the arrow buttons to make sure all text is upright. Use Q and W to move between pages.

Stage 2 (Split Pages): You can auto-run this using the |> button, but you should check that the result is correct. It doesn't always detect the page borders correctly. (Again, use Q and W to move between pages.)

Stage 3 (Deskew): Auto-run using |>. This is supposed to ensure that all text is correctly rotated. If some text is still skew, you can detect and fix this later.

Stage 4 (Select Content): This is about cutting out the margins. This is the most grueling and boring stage of the process. You can auto-run it using |>, but it will often cut off too much and you'll have to painstakingly fix it by hand. Alternatively (and much more quickly), set "Content Box" to "Disable" and manually cut off the most obvious parts without trying to save every single pixel. Don't worry: White space will not inflate the size of the ultimate file; it compresses well. The important thing is to cut off the black/grey parts beyond the pages. In this process, you'll often discover problems with your scan or with previous stages. You can always go back to previous stages to fix them.

Stage 5 (Margins): I auto-run this.

Stage 6 (Output): This is important to get right. The despeckling algorithm often breaks formulas (e.g., "..."s get misinterpreted as speckles and removed), so I typically uncheck "Despeckle" when scanning anything technical (it's probably fine for fiction). I also tend to uncheck "Savitzki-Golay smoothing" and "Morphological smoothing" for some reason; don't remember why (probably they broke something for me in some case). The "threshold" slider is important: Experiment with it! (Check which value makes a typical page of your book look crisp. Be mindful of pages that are paler or fatter than others. You can set it for each page separately, but most of the time it suffices to find one value for the whole book, except perhaps the cover.) Note the "Apply To..." buttons; they allow you to promote a setting from a single page to the whole book. (Keep in mind that there are two -- the second one is for the despeckling setting.)

Now look at the tab on the right of the page. You should see "Output" as the active one, but you can switch to "Fill Zones". This lets you white-out (or black-out) certain regions of the page. This is very useful if you see some speckles (or stupid write-ins, or other imperfections) that need removal. I try not to be perfectionistic: The best way to avoid large speckles is by keeping the scanner clean at the scanning stage; small ones aren't too big a deal; I often avoid this stage unless I know I got something dirty. Some kinds of speckles (particularly those that look like mathematical symbols) can be confusing in a scan.

There is also a "Picture Zones" rider for graphics and color; that's beyond my paygrade.

Auto-run stage 6 again at the end (even if you think you've done everything -- it needs to recompile the output TIFFs).

Now, go to the folder where you have saved your project, and more precisely to its "out/" subfolder. You should see a bunch of .tif files, each one corresponding to a page. Your goal is to collect them into one PDF. I usually do this as follows:

  tiffcp *.tif ../combined.tif
  tiff2pdf -o ../combined.pdf ../combined.tif
  rm -v ../combined.tif
Thus you end up with a PDF in the folder in which your project is.

Optional: add OCR to it; add bookmarks for chapters and sections; add metadata; correct the page numbering (so that page 1 is actual page 1). I use PDF-XChangeLite for this all; but use whatever tool you know best.

At that point, your PDF isn't super-compressed (don't know how to get those), but it's reasonable (about 10MB per 200 pages), and usually the quality is almost professional.

Uploading to LibGen... well, I think they've made the UI pretty intuitive these days :)

PS. If some of this is out of date or unnecessarily complicated, I'd love to hear!

Re:LibGen's Bloat Problem by crazygringo on Sunday August 21, 2022 @06:16PM (#32545030)
> At that point, your PDF isn't super-compressed (don't know how to get those)

As far as I know, it's making sure your text-only pages are monochrome (not grayscale) and to use Group4 compression for them, which is actually what fax machines use (!) and is optimized specifically for monochrome text. Both TIFF and PDF's support Group4 -- I use ImageMagick to take a scanned input page and run grayscale, contrast, Group4 monochrome encoding, and PDF conversion in one fell swoop which generates one PDF per page, and then "pdfunite" to join the pages. Works like a charm.

I'm not aware of anything superior to Group4 for regular black and white text pages, but would love to know if there is.

Re:LibGen's Bloat Problem by generationP on Sunday August 21, 2022 @06:51PM (#32545299)
Oh, I should have said that I scan in grayscale, but ScanTailor (at stage 6) makes the output monochrome; that's what the slider is about (it determines the boundary between what will become black and what will become white). So this isn't what I'm missing.

I am not sure if the result is G4-compressed, though. Is there a quick way to tell?

Re:LibGen's Bloat Problem by crazygringo on Sunday August 21, 2022 @07:03PM (#32545381)
On my system I can run 'pdfimages -list' on a PDF it gives me all the images in a PDF with their encoding format. The utility comes with 'poppler-utils' I believe.

And I'm just now discovering by checking on my own PDF's, that 'ocrmypdf' will automatically convert Group4 to lossless JBIG2 (if optimizations are enabled) which is supposedly even more efficient for monochrome -- but encoders aren't always available [1].

I don't think ImageMagick has been updated yet to support outputting JBIG2 for PDF's.

[1] https://ocrmypdf.readthedocs.io/en/latest/jbig2.html

Re:LibGen's Bloat Problem by generationP on Monday August 22, 2022 @03:32AM (#32548421)
Ah. It says the encoding is ccitt, which I hope is indeed the same as Group4.

How is the lossless JBIG2 in terms of reading speed? I've seen some very well-compressed PDF files around that unfortunately load so slow that they are almost unreadable on mobile; I think this was JBIG2. In that case, I'm wondering if this can be avoided by proper use or is a necessary downside of the encoding.

Re:LibGen's Bloat Problem by crazygringo on Tuesday August 23, 2022 @11:55AM (#32566791)
As fast as anything else for all practical purposes.

I too have encountered molasses-slow PDF's, and I can't even begin to guess what causes that. Book PDF's from OpenLibrary are often like that for me. Like it genuinely makes me wonder if it's producing each page's image with embedded JavaScript writing to a canvas or something... except that might actually still be faster.

Re:LibGen's Bloat Problem by homarp on Monday August 22, 2022 @01:37AM (#32547735)
beware with JBIG: "Undetectable Data Corruption in JB2/JBIG2" https://news.ycombinator.com/item?id=32537073
Re:LibGen's Bloat Problem by generationP on Monday August 22, 2022 @04:10AM (#32548666)
I suspect this is referring to the lossy version of JBIG2 (which is essentially the same as DjVU encoding).
Re:LibGen's Bloat Problem by kragen on Sunday August 21, 2022 @11:46PM (#32547107)
I really appreciate having grayscale or color scans of books rather than bilevel black and white. It's often much easier to read, and often illustrations come out mangled into illegibility by thresholding. Occasionally even text does.
Re:LibGen's Bloat Problem by crazygringo on Tuesday August 23, 2022 @12:03PM (#32566941)
I do too, but I find that they're just too big in file size.

Bilevel at around 300 DPI means scanned books that run 2-5 MB. Grayscale/color tends to mean 10-50 MB.

For me it's less about the storage and more about performance -- for everything from downloading to copying to e-mailing to previews to autosaving while highlighting, apps and cloud services seem to cope well and quickly with 3 MB PDF's, but just seem to slow down dramatically with 30 MB ones.

Re:LibGen's Bloat Problem by ajot on Sunday August 21, 2022 @11:44PM (#32547094)
Nice write up, thank you! I've tried to do some bookscanning a couple of years ago (well, it was mostly getting better and cleaner PDFs than scanning), and the best guide back then was the one by Nate Craun (former maintainer of ScanTailor).

Would you mind writing this guide in a less forum-y site? Or do you know any place to look for a good tutorial and best practices for this hobby?

Re:LibGen's Bloat Problem by generationP on Monday August 22, 2022 @03:37AM (#32548448)
Thank you for the kind words. I'm not sure I know a less forum-y site for these things. The standard places for knowledge like this are forums: e.g., https://diybookscanner.org/forum/viewtopic.php?f=21&t=3455&s... or https://forum.mhut.org/ or https://dxdy.ru/sozdanie-elektronnyh-knig-f7.html .
Re:LibGen's Bloat Problem by c-fe on Monday August 22, 2022 @09:24AM (#32550989)
I followed (and learned a lot) from this excellent post:

https://www.reddit.com/r/Piracy/comments/l9exis/how_to_downl...

Re:LibGen's Bloat Problem by jtbayly on Sunday August 21, 2022 @09:43AM (#32540115)
Agreed. Deduplication should be the bigger goal, in my opinion.
Re:LibGen's Bloat Problem by DiggyJohnson on Sunday August 21, 2022 @10:35AM (#32540594)
Even then, I wouldn’t want a file with text + illustrations to be considered a dupe of a text-only copy of the same work.
Re:LibGen's Bloat Problem by samatman on Sunday August 21, 2022 @10:50AM (#32540742)
IMHO a process which is lossy should never be described as deduplication.

What would work out fairly well for this use case is to group files by similarity, and compress them with an algorithm which can look at all 'editions' of a text.

This should mean that storing a PDF with a (perhaps badly, perhaps brilliantly) type-edited version next to it would 'weigh' about as much as the original PDF plus a patch.

Re:LibGen's Bloat Problem by duskwuff on Sunday August 21, 2022 @05:08PM (#32544461)
> IMHO a process which is lossy should never be described as deduplication.

Depends. There are going to be some cases where files aren't literally duplicates, but the duplicates don't add any value -- for example, MOBI conversions of EPUB files, or multiple versions of an EPUB with different publisher-inserted content (like adding a preview of a sequel, or updating an author's bibliography).

Re:LibGen's Bloat Problem by samatman on Sunday August 21, 2022 @06:56PM (#32545330)
Splitting those into two cases: I think getting rid of format conversions (which can, after all, be performed again) is worthwhile, but isn't deduplication, that's more like pruning.

Multiple versions of an EPUB with slightly different content is exactly the case where a compression algorithm with an attention span, and some metadata to work with can, get the multiple copies down enough in size that there's no point in disposing of the unique parts.

Re:LibGen's Bloat Problem by ajsnigrutin on Sunday August 21, 2022 @11:42AM (#32541253)
Plus there are a lot of books, where one version is a high quality scan, but no OCR, and the other is OCRed scan (with a bunch of errors, but searching works 80% of the time) and horrible scan quality.

Also, some books included appendices, that are scanned in some versions but not in others, plus large posters, that are shrunk to a4 size in one version, split onto multiple a4 pages in another, and one huge page in a third version.

Then there are zips of books, containing 1 pdf + eg. example code, libraries, etc (eg progrmaming books).

Re:LibGen's Bloat Problem by CamperBob2 on Sunday August 21, 2022 @03:23PM (#32543518)
Have to be careful there. A jihad against duplication means that poor-quality scans will drive out good ones, or prevent them from ever being created. Especially if you're misguided enough to optimize for minimum file size.

I agree with samatman's position below: as long as the format is the slightest bit lossy -- and it always will be -- aggressive deduplication has more downsides than upsides.

Re:LibGen's Bloat Problem by exmadscientist on Sunday August 21, 2022 @06:37PM (#32545204)
Deduplication doesn't have to mean removal. It might be just tagging. It would be very nice to be able to fetch the "best filesize" version of the entire collection, then pull down the "best quality" editions of only a few things I'm particularly interested in.
Re:LibGen's Bloat Problem by willnonya on Sunday August 21, 2022 @03:56PM (#32543824)
While intended to agree the duplicates need to be easily identifiable and preferably filterable by quality for bulk downloads.
Re:LibGen's Bloat Problem by signaru on Sunday August 21, 2022 @04:25PM (#32544040)
Probably only safe in cases where the files in question are exactly the same binaries (if binary diffing can be automated somehow).