there still are no eBooks and my zipper is stuck [Sun, 13 Oct 2013 15:14:32 +0000]
In this [http://blog.humaneguitarist.org/2013/03/07/on-the-brain-audio-ocrhocr-did-you-mean-and-there-are-no-ebooks/] previous post I had wondered about packaging "eBooks" (or is it "ebooks" or "e-books"?) in a password protected ZIP file.
The idea was that I'd have two main components:
1. an online server that managed user login/credentials, etc.
2. a custom web-browser that would be able to receive the ZIP password from the server upon user authentication and then read the ZIP contents into memory and push them out. This browser would disallow things like copy/pasting the content, printing, and accessing the content beyond a certain date, etc. depending upon permissions embedded in a permissions JSON file within the ZIP file.
The premise is that this could allow what are essentially web pages, i.e. applications, to be read with some sort of easy protection and without the necessary constraints (and benefits) that a standardized format like EPUB provides.
Anyway, I did some early tests using the PyQT/WebKit library for Python.
I wrapped a single-page HTML file in a password protected ZIP file and had the local instance of the browser open the file after reading the contents inside the ZIP file (but without actually unzipping the files).
I'm going to skip over HTML5 audio/video tags for now because I *think* they aren't working due to a bug with the WebKit for PyQt4. I haven't tried PyQT5 yet, by the way. At any rate, downloading videos is clearly out of the question. It may simply be better to restrict audio/video content to online content only. That's to say that the files are online, but still only accessible via the custom browser upon authentication. Hell, it may be better for ALL the content to be online only as that would make the whole ZIP file thing unnecessary.
But let me get back to the ZIP file.
I was wrong in thinking I only needed the two components mentioned above.
Then I realized I needed a third component, and intermediary between the ZIP file and the browser. And that's a local server that would proxy all the hyperlinks and include requests. It would then retrieve the file from the ZIP file and serve it back up with the appropriate HTTP header for the MIME type.
To do that I needed a Python web-framework, preferably lightweight and with easy-to-follow documentation.
After finding the documentation for CherryPy a little too involved, I stumbled upon Bottle [http://bottlepy.org/]. And I'm sure glad I did. This whole ZIP thing was a proof-of-concept so I doubt it'll go anywhere (I still like the idea of a custom browser accessing protected online content). But I definitely see myself using Bottle to make desktop applications that look/feel like web applications.
... the proxy thing is working but loading large images is a little slow, so there it is.
from bottle import *
#### return protected zipped file as read string. Currently hard-coded to open "zipped_p/test.zip".
zipped = zipfile.ZipFile('zipped_p/test.zip', 'r')
password = '123' #this is the password that would be handed-off via an online server.
content = zipped.open(z, 'r', password) #open the file content.
content = content.read()
#### proxying password protected zipped files.
# note: using 7-ZIP this doesn't seem to work with AES-256 but does work with ZipCrypto.
# quick/dirty handling of three basic MIME types.
if '.css' in filepath:
if '.js' in filepath:
if '.png' in filepath:
# have the p_retzip() function read the contents and then return the contents to the browser.
# launch server; after which you can go to http://localhost:8080/closed/index.html with regular browser or custom browser.