EPUB reader

Hi,

I would like to create an epub reader with Codea. I think for to use Cider libraries for UI.

For the algorithm, you have some reference or source code in Lua from which to start?

thanks

Hi,

I like to read epub files? is there any library? Help me!!!

thanks

it’s probable that nobody has done this with Codea

I would google for Lua code to do this

unfortunately I have not found anything. Could someone help me?

thanks

EPub’s are just zip files containing HTML content. What you’ll need to do is first work out how to extract the book (or part of it) into a table, rendering the text would be the easy bit.

In fact, my main problem is how to extract the files from the zip xhtml to insert them into a table and then manipulate them.

So…everything?

Hmm… Google found me a Lua module, LuaZip. I’m not sure if you can use this in Codea, though…

Example:

require("zip")

function viewZip(zipPath, zipFilename)
    local zfile, err = zip.open(zipPath .. zipFilename)
    if err then
        return err
    end
    local files = {}
    for file in zfile:files() do
        local currFile, err = zfile:open(file.filename)
        if err then
            return err
        end
        table.insert(files, file.filename, currFile:read("*a"))
    end
    zfile:close()
    return files
end

local zipFiles = viewZip(os.getenv("HOME") .. "Dropbox.spritepack/", "ExampleZip.zip")
for k, v in pairs(zipFiles) do
    print(k, v) -- k is the file path, v is the data
end

Hopefully that will work. I can’t test it because my dad took his iPad while he’s gone on a business trip.

I had also seen this but does not work with CODEA. It require zip library

@SkyTheCoder, @cc76 unfortunately you can’t use LuaZip without a C module added on the Xcode side of things, so you can’t use it in Codea, but you can upon exporting you project to Xcode. From the site: “LuaZip is a lightweight Lua extension library”…“LuaZip compilation depends on zziplib 0.13.49 and zlib 1.2.3.”.

The other ways are to use an online service to unzip with http.request or to implement the zip/deflate algorithm in pure lua which won’t be as efficient and very complicated… But not impossible :wink:

There’s also a further problem of available memory, I imagine e-books would potentially have lots of high quality imagery so some serious optimisation would be required to keep the memory usage down.

So in short you probably want a large portion of the reader in X-code (all the unzipping/streaming/preparation/optimisation of content) and then utilise Codea for its graphical abilities (displaying of the content) :slight_smile:

it seems incredible that with CODEA is possible to develop video games that require a lot of graphic resources and it is not possible simply to manipulate an epub format xml file compressed.
To sue an online service to unzip is really ridiculous today. I’d rather not use xcode for the moment I would be oriented to find a library to zip / unzip written in lua

Codea is a graphics program, not a file manager, and zip is not much use with images because they don’t compress.

@cc76 As @Ignatz said, Codea is tailored for graphics and games development, not tasks such as unzipping which are more prevalent on other platforms.

In the nicest possible way I also couldn’t disagree more, using an online service today is completely un-ridiculous, using services and components saves a lot of time and effort which would of otherwise been spent re-inventing the wheel, it would also be far more in-feasible just even a few years ago when there was more limitations and there wasn’t so many great “plug-and-play” solutions available.

If your not willing to peruse your requirements on a platform fit for your purpose such as X-code it is potentially a far more elegant solution to use an online service than using a library which will most likely be written for experimental / educational reasons on a platform that’s not designed for the task and cannot gain the efficiencies to make it a workable solution for all but very small files.

I’ve given you the information on how you could achieve it, it’s your choice how you put it into practice :slight_smile: but I will elaborate slightly on what a online service could be.

You could unzip files by say sending them from Codea to your Dropbox account or web server. On your computer/server you have a program which unzips the files into a folder of the same name when it receives them. From Codea you keep checking (with http.request) until the unzip has finished and then when it has (or when enough of it has) you can then get back the content and display it. You could try and find a service which does this for you or you could create it yourself :slight_smile:

do not agree! This means that with a local ePub file every time I need to read the contents of the network. If you do not have internet? I can not read it! It would be useless application.

I didn’t say you wouldn’t be able to cache the contents :wink:

Using Codea to write an ePub app is like using JavaScript or Excel to write animation apps - no program can do everything well, each one has to specialize.

Codea is not a text editor or file manager or ebook reader. It is a graphics animation program. It does that one thing very well. If you want an ePub reader, you need a different programming platform.

With due respect - why limit yourself?

When Codea first came out - no fonts. I made some. Compared to the fonts now built in, they were horrible, but they worked, and it was a fun stunt, and I like to think it helped push TLL to add them sooner rather than later. I also managed to get an image displayed long before we could do that. Pushing the envelope is fun.

I always object when someone says “Code is for…” whatever. Yes - TLL had graphics in mind when they made it - but it does a lot more. I personally have used is as a remote control and status display for webservers; I have read of other using it for mechanical control of industrial machines (cranes if I recall correctly).

The big obstacles here are no (de)compression libaries (so you’d have to roll your own), and no fast bit-manipulation (so you’d have to roll that) - meaning any implementation right now would likely be very (maybe unusably) slow. Adding either of those would make this much more doable - I know I’ve asked for both in my heinously long list of requests (I’d like to see TLL take many of the common lua libraries and include them - crypto, compression, plenty of good fun to be had).

Codea is for anything you can make it do. Including an EPub reader. Just be aware - as it stands today, that’s a pretty ambitious goal, and it’s unlikely it can be done with today’s libraries in a speedy manner.

I couldn’t agree more @Bortels Codea is for anything you can make it do and perhaps that’s not completely clear from my previous posts. I hope I haven’t come across as trying impose limits on myself (or anyone else) and Im sorry if it has :).

To be clear Im suggesting use Codea for what it’s best at currently and some ways you could implement an EPub reader in Codea. Whilst also suggesting for more desirable results, offload the things it’s currently not so good at to something that is, so you can focus on building a good ePub reader instead of a zip library and the tasks that come associated with that :slight_smile:

Why not use the built-in html viewer to view the epub? No need to reinvent that.

Have you a example to use built-in HTML view?