ipod nano notes size limit hack

I have bought an ipod nano with 8gb storage space recently. After playing some time with this fancy device I have discovered that each note kept on the ipod can not exceed 4k limit. To circumvent this limit one should divide his big note into pieces of 4k each. Furthermore, it is possible to place html links to point pages.

Below is a simple python script which reads stdin and creates ipod-compatible ebook which can be uploaded and read on your beloved device. Simply cat a big note to the script’s stdin and do not forget to define an ebook name. After successful completion of the script you will get a new directory in cwd containing all pages of your ipod ebook. Sample usage is like this:

cat /path/to/big/myebook | ./ipod_ebook.py myebook


#!/usr/local/bin/python2.5
import sys
import os

# 4k bytes in one page is allowed
ebook_page_bytes_count = 4000

if len(sys.argv) != 2:
  print "Usage: ", sys.argv[0], “ebook_name”
  sys.exit(-1)

try:
  os.mkdir(sys.argv[1])
except OSError:
  print sys.exc_value, “\nCould not create directory:”, sys.argv[1]
  sys.exit(-1)

j = 0
i = 0
ebook_page = open(sys.argv[1] + “/” + sys.argv[1] + str(j),”w”)
ebook_page.write(”<?xml encoding=\”utf-8\”?>\n”)

for line in sys.stdin:
  if i >= ebook_page_bytes_count:
    # Link to the next page at the bottom of the current page
    ebook_page.write(
    “\n<A HREF=\”" + sys.argv[1] + str(j + 1) + “\” NOPUSH>to page #”\
    + str(j+1) + “</A>”)
    ebook_page.close()
    j = j + 1
    i = 0
    ebook_page = open(sys.argv[1] + “/” + sys.argv[1] + str(j),”w”)
    # Ebook page header
    ebook_page.write(”<?xml encoding=\”utf-8\”?>\n”)
  ebook_page.write(line)
  i = i + len(line)

Tags: , , ,

Leave a Reply