Anna's Blog

Anna’s Update: fully open source archive, ElasticSearch, 300GB+ of book covers

annas-blog.org, 2022-12-09

With Z-Library going down and its (alleged) founders getting arrested, we’ve been working around the clock to provide a good alternative with Anna’s Archive (we won’t link it here, but you can Google it). Here are some of the things we achieved recently.

Anna’s Archive is fully open source

We believe that information should be free, and our own code is no exception. We have released all of our code on our privately hosted Gitlab instance: Anna’s Software. We also use the issue tracker to organize our work. If you want to engage with our development, this is a great place to start.

To give you a taste of the things we are working on, take our recent work on client-side performance improvements. Since we haven’t implemented pagination yet, we would often return very long search pages, with 100-200 results. We didn’t want to cut off the search results too soon, but this did mean that it would slow down some devices. For this, we implemented a little trick: we wrapped most search results in HTML comments (<!-- -->), and then wrote a little Javascript that would detect when a result should become visible, at which moment we would unwrap the comment:

var lastAnimationFrame = undefined;
var topByElement = {};
function render() {
  window.cancelAnimationFrame(lastAnimationFrame);
  lastAnimationFrame = window.requestAnimationFrame(() => {
    var bottomEdge = window.scrollY + window.innerHeight * 3; // Load 3 pages worth
    for (element of document.querySelectorAll('.js-scroll-hidden')) {
      if (!topByElement[element.id]) {
        topByElement[element.id] = element.getBoundingClientRect().top + window.scrollY;
      }
      if (topByElement[element.id] <= bottomEdge) {
        element.classList.remove("js-scroll-hidden");
        element.innerHTML = element.innerHTML.replace('<' + '!--', '').replace('-' + '->', '')
      }
    }
  });
}
document.addEventListener('DOMContentLoaded', () => {
  document.addEventListener('scroll', () => {
    render();
  });
  render();
});

DOM "virtualization" implemented in 23 lines, no need for fancy libraries! This is the sort of quick pragmatic code that you end up with when you have limited time, and real problems that need to be solved. It has been reported that our search now works well on slow devices!

Another big effort was to automate building the database. When we launched, we just haphazardly pulled different sources together. Now we want to keep them updated, so we wrote a bunch of scripts to download new metadata from the two Library Genesis forks, and integrates them. The goal is to not just make this useful for our archive, but to make things easy for anyone who wants to play around with shadow library metadata. The goal would be a Jupyter notebook that has all sorts of interesting metadata available, so we can do more research like figuring out what percentage of ISBNs are preserved forever.

Finally, we revamped our donation system. You can now use a credit card to directly deposit money into our crypto wallets, without really needing to know anything about cryptocurrencies. We’ll keep monitoring how well this works in practice, but this is a big deal.

Switch to ElasticSearch

One of our tickets was a grab-bag of issues with our search system. We used MySQL full-text search, since we had all our data in MySQL anyway. But it had its limits:

After talking to a bunch of experts, we settled on ElasticSearch. It hasn’t been perfect (their default “did you mean” suggestions and autocomplete features suck), but overall it’s been a lot better than MySQL for search. We’re still not too keen on using it for any mission-critical data (though they’ve made a lot of progress), but overall we’re quite happy with the switch.

For now, we’ve implemented much faster search, better language support, better relevancy sorting, different sorting options, and filtering on language/book type/file type. If you’re curious how it works, have a look. It’s fairly accessible, though it could use some more comments…

300GB+ of book covers released

Finally, we’re happy to announce a small release. In collaboration with the folks who operate the Libgen.rs fork, we’re sharing all their book covers through torrents and IPFS. This will distribute the load of viewing the covers among more machines, and will preserve them better. In many (but not all) cases, the book covers are included in the files themselves, so this is kind of “derived data”. But having it in IPFS is still very useful for daily operation of both Anna’s Archive and the various Library Genesis forks.

As usual, you can find this release at the Pirate Library Mirror. We won’t link to it here, but you can easily find it.

Hopefully we can relax our pace a little, now that we have a decent alternative to Z-Library. This workload is not particularly sustainable. If you are interested in helping out with programming, server operations, or preservation work, definitely reach out to us. There is still a lot of work to be done. Thanks for your interest and support.

- Anna and the Pirate Library Mirror team (Twitter, Reddit)