Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/internetarchive/bookserver

Archive.org OPDS Bookserver - A standard for digital book distribution
https://github.com/internetarchive/bookserver

aldiko atom-feed books opds simplye

Last synced: about 2 months ago
JSON representation

Archive.org OPDS Bookserver - A standard for digital book distribution

Awesome Lists containing this project

README

        

Internet Archive Bookserver
===========================

This repository contains the ``bookserver`` package, which is useful for
working with OPDS catalog feeds. It also contains the source for the
http://bookserver.archive.org site.

To create a Catalog instance from scratch, you can use this code:

>>> from bookserver import catalog
>>> urn = 'urn:x-internet-archive:bookserver:catalog'
>>> c = catalog.Catalog(title='Internet Archive OPDS', urn=urn)

To create a link to a free PDF:

>>> l = catalog.Link(url = 'http://archive.org/download/itemid/itemid.pdf',
... type = 'application/pdf',
... rel = 'http://opds-spec.org/acquisition')

To create a link to an html shopping cart that sells drm-ed books:

>>> l2 = catalog.Link(url = 'http://archive.org/download/drmbook/shoppingcart',
... type = 'text/html',
... rel = 'http://opds-spec.org/acquisition/buying',
... price = '10.00',
... currencycode = 'USD',
... formats = ('application/pdf;drm=acs', 'application/epub+zip;drm=acs'))

To create an entry for a book:

>>> e = catalog.Entry({'urn' : 'x-internet-archive:item:itemid',
... 'title' : u'test item',
... 'updated' : '2009-01-01T00:00:00Z'}, links=[l])
>>> c.addEntry(e)

>>> e = catalog.Entry({'urn' : 'x-internet-archive:item:drmbook',
... 'title' : u'A book with DRM',
... 'updated' : '2009-01-01T00:00:00Z'}, links=[l2])
>>> c.addEntry(e)

The catalog.Navigation class can help with creating prev and next rel links,
although you can just pass these in as args to __init__

>>> start = 0
>>> numFound = 2
>>> numRows = 1
>>> urlBase = '/alpha/a/'
>>> n = catalog.Navigation.initWithBaseUrl(start, numRows, numFound, urlBase)
>>> c.addNavigation(n)

The catalog.OpenSearch class just holds OpenSearch Description Document for now:

>>> osDescription = 'http://bookserver.archive.org/opensearch.xml'
>>> o = catalog.OpenSearch(osDescription)
>>> c.addOpenSearch(o)

From our Catalog instance, we can now create an OPDS feed in Atom format:

>>> r = catalog.output.CatalogToAtom(c)
>>> str = r.toString()

Different version of lxml will print xmlns differently (use ellipsis in doctest):

>>> print str.rstrip() #doctest: +ELLIPSIS
Internet Archive OPDS
urn:x-internet-archive:bookserver:catalog
1970-01-01T00:00:00Z


Internet Archive
http://www.archive.org




test item
x-internet-archive:item:itemid
2009-01-01T00:00:00Z



A book with DRM
x-internet-archive:item:drmbook
2009-01-01T00:00:00Z

10.00
application/pdf;drm=acs
application/epub+zip;drm=acs