Kobo - helper scripts Source

1---
2title: 'Kobo - helper scripts'
3date: '2010-05-29'
4published_at: '2010-05-29T16:51:00.007+10:00'
5tags: ['books', 'ebook', 'gadgets', 'kobo']
6author: 'Gavin Jackson'
7excerpt: 'Here are a couple of scripts that might help you out if you are a Kobo user trying to load third party eBooks. Script 1: strip out all style data (this fixes up the margins and any font issues that yo...'
8updated_at: '2010-05-29T17:21:15.478+10:00'
9legacy_url: 'http://www.gavinj.net/2010/05/kobo-helper-scripts.html'
10---
11
12Here are a couple of scripts that might help you out if you are a Kobo user trying to load third party eBooks. Script 1: strip out all style data (this fixes up the margins and any font issues that you may be experiencing).
13
14Simply put the epub files you want to convert in the same directory as the script (tested on Mac OS 10.5 - but should work on all Unix variants).
15
16```
17#!/bin/bash
18mkdir _unpack
19#iterate over each epub in this folder
20find . -name '*.epub' -depth 1|while read epub
21do
22unzip "${epub}" -d ./_unpack
23cd ./_unpack/OEBPS
24for xhtml_file in `ls|grep xhtml`
25do
26awk '{gsub("", "");print}' "${xhtml_file}" > "${xhtml_file}.new"
27mv "${xhtml_file}.new" "${xhtml_file}"
28done
29cd ../
30echo `pwd`
31mv "../${epub}" "../${epub}.old"
32zip -r "../${epub}" *
33cd ../
34rm -rf _unpack
35done
36```
37
38Script 2: strip out all style data and load a jpg image for the book cover (note that both book and jpeg must be in a sub directory for this to work).
39
40```
41#!/bin/bash
42find . -type d -depth 1|while read dir
43do
44cd "${dir}"
45mkdir _unpack
46#iterate over each epub in this folder
47find . -name '*.epub' -depth 1|while read epub
48do
49unzip "${epub}" -d ./_unpack
50
51cd ./_unpack/OEBPS
52for xhtml_file in `ls|grep xhtml`
53do
54awk '{gsub("", "");print}' "${xhtml_file}" > "${xhtml_file}.new"
55mv "${xhtml_file}.new" "${xhtml_file}"
56done
57cp ../../../title.xhtml ./
58cp ../../*.jpg ./cover.jpg
59cd ../
60echo `pwd`
61mv "../${epub}" "../${epub}.old"
62zip -r "../${epub}" *
63cd ../
64rm -rf _unpack
65done
66cd ..
67done
68```
69
70The working directory must have the following title.xhtml file in it:
71
72![](cover.jpg)
73
74```
75
76```
77
78
79