So there's this program out there called Calibre which, despite it's pretty terrible UI, is pretty much the gold standard for managing eBooks. Seriously, it's such a great program whose only fault is its terrible engineer UI.
One of the nice things that Calibre includes is a built-in web server that can serve books via OPDS. If you have an OPDS-compatible reader (I use Marvin), you can browse and download from your library directly on your device, basically creating your own private eBook cloud.
But, this presents a little bit of an issue. Namely, I don't want all of my books to be publicly available, while still providing a subset of my library for visitors to browse and use. But I still want to be able to access them myself from my "private reserve collection."
Fortunately, with a little bit of work, you can do that under Calibre.
Start by creating two (or more) virtual libraries within Calibre.
One thing to note, any library other than the initial one should have no spaces in the name.
Next, set up your first server using the GUI. To do this, go to Preferences menu, then Preferences (again). In the Preferences window, find "Sharing over the net" and open that preference pane.
Note the server port (default is 8081), because you'll need that in just a few minutes. Find the "Virtual Library to Apply" setting and select your first library. Then click "Start Server." Wait a few seconds, then click "Test Server." This should open a browser window and you should see a page that lets you navigate only your first library.
So far so good. On to the next step.
Multiple Servers and Libraries
Now it gets tricky (if you're not used to the shell, that is). Open a Terminal window and type:
cd /Applications/calibre.app/Contents/MacOS/ ls
You should see something that looks like:
calibre calibre-customize calibre-parallel calibre-smtp ebook-convert ebook-edit ebook-polish fetch-ebook-metadata lrfviewer markdown-calibre web2disk calibre-complete calibre-debug calibre-server calibredb ebook-device ebook-meta ebook-viewer lrf2lrs lrs2lrf qt-plugins
The one we want here is
calibre-server. Type the following command:
./calibre-server -p 8082 --virtual-library=Library2
Library2 is the name of the second virtual library you created above.
Note that I incremented the port number from the initial server above.
Open a browser to
http://localhost:8082 and you should see your second
library. You can do this for as many libraries as you like. Just be sure to
increment the port number for each additional server you run. Press Ctrl+C to
end the server.
Launching on Reboot
So now you have this server, but you don't want to keep a shell window open with it just to keep the server running, and you want it to start back up when you reboot.
Now, for the first library, I just have Mac OS X launching Calibre automatically, from the Login Items preferences in Users and Groups. I also use Calibre's monitoring of a folder, so I need the actual program itself to launch at boot, so that takes care of the first library. But what about the second?
Well, this is where Mac OS X's
launchd comes in.
Back in your terminal window, type:
com.username.calibre-server.plist file, replacing
your username. You can use
nano or any other editor of your choice. Put
the following in the file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.username.calibre-server</string> <key>ProgramArguments</key> <array> <string>/Applications/calibre.app/Contents/MacOS/calibre-server</string> <string>-p 8082</string> <string>--virtual-library=Library2</string> </array> <key>KeepAlive</key> <true/> <key>RunAtLoad</key> <true/> </dict> </plist>
Note that all we did here is recreate the command we ran above within the plist. Save that and exit your editor, then type:
launchctl load com.username.calibre-server.plist
And navigate to
http://localhost:8082 in your browser. If everything worked,
you should now see your second calibre library running. And this should load
automatically after you reboot.
Bonus Setup: Pretty URLs!
Because I like pretty URLs,
we're going to set up pretty URLs for this one too. Because
calibre.internal.domain is much nicer.
Mac OS X already has Apache installed, so no need to install it yourself. You just need to make a few quick changes.
Now, edit the
httpd.conf file using
nano or any other editor of your
choice. Be sure to use
sudo because these files are owned by root. Find and
uncomment the following lines:
# Find: #LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so # Change To: LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so # Find: #Include /private/etc/apache2/extra/httpd-vhosts.conf # Change To: Include /private/etc/apache2/extra/httpd-vhosts.conf
Close and save. Now go to:
Now, edit the
httpd-vhosts.conf file using
nano or any other editor of
your choice. Be sure to use
sudo because these files are owned by root. Add
the following vhost:
<VirtualHost *:80> ServerName calibre.internal.domain ProxyRequests Off ProxyPreserveHost On ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ <Proxy *> Order deny,allow Allow from all Require all granted </Proxy> </VirtualHost>
You'll recognize what we're doing here if you read my earlier article on pretty URLs. Basically, we're proxying requests to the actual server on the correct port.
You can optionally create a new vhost for each library you run. If you do create additional vhosts, be sure you're pointing each one at the correct ports. Once you're finished, type
sudo apachectl restart
And navigate to
calibre.internal.domain. If everything went okay, you should
now see your second library, without any of the