Read your epub books!
Supports epub with images. images open in separate yad window.
Show/hide cover image.
edit: tested on fossapup fossadog and fatdog
if you want text in books to be read out loud then install espeak. Make sure you select the correct copy command in preferences ... xclip or xsel etc.
Code: Select all
#!/bin/sh
# by stemsee
# with code from Mochimopel's MMView
[[ "`whoami`" != "root" ]] && exec sudo -E -S ${0} "$@"
export Provided="$1"
[[ -z `busybox which yad` ]] && xmessage -center "Without
yad - this app cannot function
GPL V3.0" -fore black -back green -timeout 4
export OUTPUT_CHARSET=UTF-8
export version=0.4
export camino="$HOME/.config/ePub"
if [ ! -z `busybox which xsel` ]; then
export CLIP="xsel -o -p"
elif [ ! -z `busybox which xclip` ]; then
export CLIP="xclip -o -p"
elif [ ! -z `busybox which clipit` ]; then
export CLIP="clipit -p"
fi
for i in icons geometry notes
do
[[ ! -d "$camino"/"$i" ]] && mkdir -p "$camino"/"$i"
done
export track=/tmp/ePub
[[ ! -d "$track" ]] && mkdir -p "$track"
export TONGUE="afrikaans\naragonese\nbulgarian\nbosnian\ncatalan\nczech\nwelsh\ndanish\ngerman\ngreek\ndefault\nenglish\nen-scottish\nenglish-north\
\nenglish_rp\nenglish_wmids\nenglish-us\nen-westindies\nesperanto\nspanish\nspanish-latin-am\nestonian\npersian\npersian-pinglish\nfinnish\nfrench-Belgium\
\nfrench\nirish-gaeilge\ngreek-ancient\nhindi\ncroatian\nhungarian\narmenian\narmenian-west\nindonesian\nicelandic\nitalian\nlojban\ngeorgian\nkannada\
\nkurdish\nlatin\nlingua_franca_nova\nlithuanian\nlatvian\nmacedonian\nmalayala\nmalay\nnepali\ndutch\nnorwegian\npunjabi\npolish\nbrazil\nportugal\nromanian\
\nrussian\nslovak\nalbanian\nserbian\nswedish\nswahili-test\ntamil\nturkish\nvietnam\nvietnam_hue\nvietnam_sgn\nChinese\ncantonese\n"
function sayonara { # geometry recorder Mocchimopel
[[ ! -f "$track"/geom ]] && exit
yad --text="$WINDOWTITLE:Geometry-Recorder" --window-icon="$w/2P.svg" \
--geometry=200x10+100-100 --no-focus --no-buttons --undecorated \
--on-top --form --skip-taskbar --field="MoreTime:FBTN" "bash -c sayonara" \
--timeout-indicator=top --timeout=$1
nought=`xwininfo -stats -name "$WINDOWTITLE" | grep "$WINDOWTITLE"`
XWININFO=`xwininfo -stats -name "$WINDOWTITLE"`
if [[ ! -z "$nought" ]]; then
ARRAY=(${XWININFO#* X: })
AX=${ARRAY[0]}
AY=${ARRAY[4]}
RX=${ARRAY[8]}
RY=${ARRAY[12]}
W=${ARRAY[14]}
H=${ARRAY[16]}
X=$((AX-RX))
Y=$((AY-RY))
echo "$W"x"$H"+"$X"+"$Y" > "$camino"/geometry/"$WINDOWTITLE"
else
exit
fi
}
export -f sayonara
function geometryfn (){
nought=`xwininfo -stats -name "$1" | grep "$1"`
XWININFO=`xwininfo -stats -name "$1"`
if [[ ! -z "$nought" ]]; then
ARRAY=(${XWININFO#* X: })
AX=${ARRAY[0]}
AY=${ARRAY[4]}
RX=${ARRAY[8]}
RY=${ARRAY[12]}
W=${ARRAY[14]}
H=${ARRAY[16]}
X=$((AX-RX))
Y=$((AY-RY))
echo -e "${W}x${H}+${X}+${Y}\n`cat $track/font`|`cat $track/fore`|`cat $track/back`|$book|`cat $track/$2/chapter`|`$CLIP`" > "$camino"/geometry/"$1"
fi
}
export -f geometryfn
function preferences (){
export ENGINE="$(cat "$camino"/prefs | cut -f1 -d'|')"
export FILEMAN="$(cat "$HOME"/.config/twopee/prefs | cut -f2 -d'|')"
export TL="$(cat "$camino"/prefs | cut -f2 -d'|')"
export FONT="$(cat "$camino"/prefs | cut -f3 -d'|')"
export FORE="$(cat "$camino"/prefs | cut -f4 -d'|')"
export BACK="$(cat "$camino"/prefs | cut -f5 -d'|')"
export URL="$(cat "$camino"/prefs | cut -f6 -d'|')"
export CLIP="$(cat "$camino"/prefs | cut -f7 -d'|')"
export WRAP="$(cat "$camino"/prefs | cut -f8 -d'|')"
export BTDEV="$(cat "$camino"/prefs | cut -f9 -d'|')"
export SNDCRD="$(cat "$camino"/prefs | cut -f10 -d'|' | tr ',' ';')"
export EDIR="$(cat "$camino"/prefs | cut -f11 -d'|')"
export FILEMAN="$(cat "$camino"/prefs | cut -f12 -d'|')"
export GEOM="$(cat "$camino"/prefs | cut -f13 -d'|')"
[[ "$GEOM" == TRUE ]] && touch "$track"/geom || rm -f "$track"/geom
export WINDOWTITLE="Set-Preferences"
sayonara 8 &
export btees=$(bt-device -l | tr '\n' ',')
yad --title="$WINDOWTITLE" --window-icon="$camino/icons/2P.svg" \
--fontname="$FONT" --center --form --item-separator="," --columns=2 \
--field="Translate Engine:CBE" "$ENGINE,google,bing,yandex" \
--field="Translate to Language:CBE" "$TL,en,es,de,zh,fr,ja,pt,it" --field="Font:FN" "$FONT" \
--field="Text-Color:CLR" "$FORE" --field="Background-Color:CLR" "$BACK" \
--field="URL-color:CLR" "$URL" \
--field="Copy Command:CBE" "$CLIP,clipit -p,xsel -o -p,xclip -o -p" \
--field="Selectables Text-Wrap:NUM" "$WRAP" --field="BT Device:CBE" "$BTDEV,$btees" \
--field="Sound Card:CBE" "$SNDCRD,$(aplay -L | grep CARD= | tr ',' ';' | tr '\n' ',')" \
--field="eBooks:DIR" "$EDIR" --field="Filemanager:CBE" "$FILEMAN,pcmanfm" --field="Geometry Recorder:CHK" "$GEOM" > "$track"/prefs
[ $? -eq 1 ] && exit
export ENGINE="$(cat "$track"/prefs | cut -f1 -d'|')"
export TL="$(cat "$track"/prefs | cut -f2 -d'|')"
export FONT="$(cat "$track"/prefs | cut -f3 -d'|')"
export FORE="$(cat "$track"/prefs | cut -f4 -d'|')"
export BACK="$(cat "$track"/prefs | cut -f5 -d'|')"
export URL="$(cat "$track"/prefs | cut -f6 -d'|')"
export CLIP="$(cat "$track"/prefs | cut -f7 -d'|')"
export WRAP="$(cat "$track"/prefs | cut -f8 -d'|')"
export BTDEV="$(cat "$track"/prefs | cut -f9 -d'|')"
export SNDCRD="$(cat "$track"/prefs | cut -f10 -d'|' | tr ';' ',')"
export EDIR="$(cat "$track"/prefs | cut -f11 -d'|')"
export FILEMAN="$(cat "$camino"/prefs | cut -f12 -d'|')"
export GEOM="$(cat "$track"/prefs | cut -f13 -d'|')" && [ "$GEOM" == 'TRUE' ] && touch "$track"/geom || rm -f "$track"/geom
echo "$FONT" > "$track"/font
echo "$FILEMAN" > "$track"/fileman
echo "$URL" > "$track"/url
echo "$FORE" > "$track"/fore
echo "$BACK" > "$track"/back
echo "$HELP" > "$track"/help
echo "$ENGINE" > "$track"/engine
echo "$TL" > "$track"/lang
echo "$CLIP" > "$track"/clip
echo "$WRAP" > "$track"/wrap
echo "$BTDEV" > "$track"/btdev
echo "sndcrd=$SNDCRD" > "$track"/sndcard
echo "EDIR=$EDIR" > "$track"/epubdir
cat "$track"/prefs > "$camino"/prefs
}
export -f preferences
function movefn (){ # rename epub book
book=$(echo "$1" | cut -f3 -d'>' | cut -f1 -d'<')
name=$(echo "$book" | rev | cut -f1 -d'/' | rev)
newname=$($CLIP)
T_TEXT="$name\n$newname\n$book"
export A_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
printf apay
if [[ ! -z "$newname" ]]; then
rename "$name" "$newname".epub "$book"
fi
}
export -f movefn
function eSpeakfn (){ # speak selected text
touch "$track"/{ES,HB}
function spkcase (){
case "$1" in
Afrikaans|afrikaans)lnga=af;; # available accents, download packages for additional languages
Aragonese|aragonese)lnga=an;;
Bulgarian|bulgarian)lnga=bg;;
Bosnian|bosnian)lnga=bs;;
Catalan|catalan)lnga=ca;;
Czech|czech)lnga=cs;;
Welsh|welsh)lnga=cy;;
Danish|danish)lnga=da;;
German|german)lnga=de;;
Greek|greek)lnga=el;;
English|default)lnga=en;;
english)lnga=en-gb;;
Scottish|en-scottish)lnga=en-sc;;
Northern|english-north)lnga=en-uk-north;;
English-UK|english_rp)lnga=en-uk-rp;;
Midlands|english_wmids)lnga=en-uk-wmids;;
English-US|english-us)lnga=en-us;;
WestIndian|en-westindies)lnga=en-wi;;
Esperanto|esperanto)lnga=eo;;
Spanish|spanish)lnga=es;;
Spanish-la|spanish-latin-am)lnga=es-la;;
Estonian|estonian)lnga=et;;
Farsi|Persian|persian)lnga=fa;;
Pinglish|persian-pinglish)lnga=fa-pin;;
Finnish|finnish)lnga=fi;;
Frencg-blg|french-Belgium)lnga=fr-be;;
French|french)lnga=fr-fr;;
Irish|Gaelic|irish-gaeilge)lnga=ga;;
Greek-trad|greek-ancient)lnga=grc;;
Hindi|hindi)lnga=hi;;
Croatian|croatian)lnga=hr;;
Hungariann|hungarian)lnga=hu;;
Armenian|armenian)lnga=hy;;
Armenian-w|armenian-west)lnga=hy-west;;
Indonesian|indonesian)lnga=id;;
Icelandic|icelandic)lnga=is;;
Italian|italian)lnga=it;;
Lojban|lojban)lnga=jbo;;
Georgian|georgian)lnga=ka;;
Kannada|kannada)lnga=kn;;
Kurdish|kurdish)lnga=ku;;
Latin|latin)lnga=la;;
Lingua-Franca-Nova|lingua_franca_nova)lnga=lfn;;
Lithuanian|lithuanian)lnga=lt;;
Latvian|latvian)lnga=lv;;
Macedonian|macedonian)lnga=mk;;
Malayalam|malayalam)lnga=ml;;
Malay|malay)lnga=ms;;
Nepalese|nepali)lnga=ne;;
Dutch|dutch)lnga=nl;;
Norwegian|norwegian)lnga=no;;
Punjabi|punjabi)lnga=pa;;
Polish|polish)lnga=pl;;
Brazillian|brazil)lnga=pt-br;;
Portuguese|portugal)lnga=pt-pt;;
Romanian|romanian)lnga=ro;;
Russian|russian)lnga=ru;;
Slovakian|slovak)lnga=sk;;
Albanian|albanian)lnga=sq;;
Serbian|serbian)lnga=sr;;
Swedish|swedish)lnga=sv;;
Swahili|swahili-test)lnga=sw;;
Tamil|tamil)lnga=ta;;
Turkish|turkish)lnga=tr;;
Vietnamese|vietnam)lnga=vi;;
Vietnamese-hue|vietnam_hue)lnga=vi-hue;;
Vietnamese-sgn|vietnam_sgn)lnga=vi-sgn;;
Chinese*Simple*|Pudonghua|Mandarin|chinese|Chinese)lnga=zh;;
Chinese*Trad*|Cantonese|cantonese)lnga=zh-yue;;
esac
export lnga
}
export -f spkcase
function spkflt (){ # as above but floating phonetics viewer
#export DIAL=$(echo $1 | cut -f3 -d'>' | cut -f1 -d'<')
DIAL="$TL"
spkcase "$TL"
export WINDOWTITLE="eSpeak-$DIAL-Phonetics"
sayonara 4 &
mkfifo "$track"/espeak
time=$(date +%Y%d%h%a%H%M | tr -d ' ')
[ -z "$lnga" ] && lnga=en
espeak $opt -s 160 -p 50 -v "$lnga" "$($CLIP)" --ipa --phonout="$track"/espeak &
cat "$track"/espeak | yad --window-icon="$w/2P.svg" --title="$WINDOWTITLE" \
--geometry="$(cat $camino/geometry/$WINDOWTITLE | head -1)" --wrap --listen --text-info --editable \
--fontname="$FONT" --back="black" --fore="white" --show-uri --uri-color="light blue" > "$camino"/notes/$DIAL-$time &
[[ -z $(cat "$camino"/notes/$DIAL-$time) ]] && rm -f "$camino"/notes/$DIAL-$time
}
export -f spkflt
case "$1" in
float) ( export WINDOWTITLE="Target-Voice"
sayonara 4 &
echo -e "$TONGUE" | while read line; do
echo -e "<?xml version=\"1.1\" encoding=\"UTF-8\"?>
<svg height=\"24\" width=\"32\">
<text x=\"0\" y=\"18\" style=\"fill:$(hexdump -n 3 -v -e '"#" 3/1 "%02X" "\n"' /dev/urandom);\">$cnt</text>
</svg>" > "$camino/icons/${cnt}.svg"
printf "%s\n%s\n" "<span font='$FONT'> <span color='$(hexdump -n 3 -v -e '"#" 3/1 "%02X" "\n"' /dev/urandom)'>$line</span></span>" "$camino/icons/${cnt}.svg" ; export cnt=$((cnt + 1)); done; export cnt=1 ) | yad --title="Target-Voice" --geometry="$(cat $camino/geometry/Target-Voice)" --on-top --text="Double click item\n prints phoneme\nwith speech" --list --column="Layouts:TXT" --column="TAG:IMG" --dclick-action="bash -c \"spkflt "%s" \"" --select-action="bash -c \"export opt='-q'; spkflt "%s" \"" --button="Stop eSpeak:bash -c 'killall espeak'" &
sleep 1
;;
"") echo -e '\f' > "$track"/yap
echo -e "$TONGUE" | while read line; do
svgnum "$line"; export cnt=$((cnt + 1)); export cnt=$((cnt + 1)); done; export cnt=1
sleep 1
echo "$1" | while read line
do
line=$(echo $line | cut -f3 -d'>' | cut -f1 -d'<')
[[ ! -f "$track"/ES ]] && break
[[ -z "$line" ]] && line="en-uk-north"
spkcase "$line"
[[ ! -z `busybox which pulseaudio` ]] && sudo pulseaudio --start
export run_acmd='@bash -c "killall espeak"'
echo -e '' > "$track"/pay
echo "$run_acmd" > "$track"/pay
espeak -s 160 -p 50 -v "$lnga" "$($CLIP)" --ipa --phonout=$track/espeak
cat "$track"/espeak | while read line; do printf "%s" "${line}\n" | sed 's/\\n|$//'; done | sed "s/^/|$lnga|/" | awk '{fflush();print;fflush()}' > "$track"/pay
export run_acmd='@bash -c "savefn %1 %3 > /dev/null 2>&1 &"'
[[ -z "$A_TEXT" && -z "$B_TEXT" ]] && printfn dpay
done &
;;
esac
pidcntrl
}
export -f eSpeakfn
function view_htm2txt2 () { # MochiMoppel
busybox tr '\r\n' '\x01' | sed -r ' # change Unix/Win/Mac line endings into hex01 markers, i.e put whole file content on a single line, then pipe to sed
s/^.*<\/head>//Ig # delete document declarations and the <head> section
s/<style[^<]*<\/style>//Ig # delete <style> sections
s/<script/\x0&/Ig # add NULL markers before <script>
s/\x0<script[^\x0]*<\/script>//Ig # delete <script> sections (unlike <style> sections <script> sections may contain < characters, making it difficult to match the content, hence the unlikely NULL character)
s/<pre>/\n&/Ig # put <pre> on separate line
s/<\/pre>/&\n/Ig' | sed -r ' # following /<pre>/! condition works only with fresh pipe (line structure changed!)
/<pre>/! s/\x01//Ig # delete all lineend markers except those between <pre> tags
s/ |\t/ /g # replace   and tabs with normal space.
s/ +/ /g # reduce consecutive spaces (bad habit of NYT) to 1 space
s/>[ \x01]+</></g # delete all spaces or newlines between tags (if they are the only characters that separate the tags)
s/<metadata.*<\/metadata>// # delete <metadata> section (Abiword)
s/<d[ >][^<]*<\/d>//g # delete <d> sections (Abiword. <data> may contain multiple <d>, so greedy match will delete until last </d>. Good! Deleting whole <data> section instead might conflict with HTML5 <data>)
s/<div|<p[ >]/\x01\x01&/Ig # precede <div> and <p> with blank line (does not match <pre>,<progress>,<param>,<picture>)
s/<h[1-6]/\x01\x01● & /Ig # precede <h> with blank line and bullet
s/<dt/\x01\x01◆ &/Ig # precede <dt> (Notecase likes them) with lineend markers and bullet
s/<li/\x01• &/Ig # put <li> on new line and add bullet (unfortunately not possible to determine if list should be vertical or horizontal)
s/<\/h[1-9]|<dd|<tr|<br/\x01</Ig # precede </h <dd <tr <br with lineend marker, i.e. put them always on a new line
s/<[^>]*>|-->//g # delete all tags and --> (a leftover in Gtkdialog references)
s/&[lr]?d?quot?;/"/g # convert “ ” "
s/</</g # convert <
s/>/>/g # convert >
s/&/\&/g # convert &
s/^[ \x01]+// # delete first line if blank
s/\x01 +/\x01/g # delete all spaces at line start
s/[•◆●] *\x01//g # delete lines with orphaned bullets
s/\x01\x01\x01+/\x01\x01/g # reduce consecutive blank lines to 1 line
s/\x01/\n/g # change lineend markers back into newlines'
}
export -f view_htm2txt2
function svgnum (){
shopt -s nocasematch
case "$1" in
*) [[ "$2" != float ]] && printf "%s\n%s\n%s\n" "<span font='$FONT'> <span color='$(hexdump -n 3 -v -e '"#" 3/1 "%02X" "\n"' /dev/urandom)'>$1</span></span>" "$x" "$cnt.svg" > "$track"/yap
[[ "$2" == float ]] && printf "%s\n%s\n" "<span font='$FONT'> <span color='$(hexdump -n 3 -v -e '"#" 3/1 "%02X" "\n"' /dev/urandom)'>$1</span></span>" "$cnt.svg"
;;
esac
}
export -f svgnum
function rmfn (){
rmbook=$(echo "$1" | cut -f3 -d'>' | cut -f1 -d'<')
[ -f "$rmbook" ] && rm -f "$rmbook"
refreshfn
}
export -f rmfn
function viewepubfn (){ # final part that displays epub book content
rm -f $track/YR
export book=$(echo "$book" | cut -f3 -d'>' | cut -f1 -d'<')
export TITLE=$(echo "$book" | rev | cut -f1 -d'/' | rev)
[ -f $camino/geometry/$WINDOWTITLE ] && cat $camino/geometry/$WINDOWTITLE | tail -1 | cut -d'|' -f6 > $track/$TITLE/bookmark
echo "$1" > "$track"/"$TITLE"/chapter
case "$1" in
*[0-9].htm.*html|*.xhtml|*.txt.*html) unzip -p "$book" "$1" | view_htm2txt2 | sed 's/\//g' > $track/htmtxt
T_TEXT=$(cat $track/$TITLE/chapter;cat $track/$TITLE/bookmark;cat $track/htmtxt)
A_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
B_TEXT=$(while read -r line; do printf "%s" "$line\n"; done <<< "$T_TEXT")
if [ -f $track/list ]; then
[[ ! -f $track/float ]] && echo "$T_TEXT" | while read line; do printf "%s\n%s\n" "$line" "$track/$TITLE/OEBPS/cover.png" > $track/yap; export cnt=$((cnt + 1)); done; export cnt=1
export WINDOWTITLE="Epub-$TITLE"
#sayonara 4 &
export time=$(date +%Y%d%h%a%H%M | tr -d ' ')
[[ -f $track/float ]] && echo -e '\f' >> $track/bookview-$num && echo "$T_TEXT" >>$track/bookview-$num
#[[ -z $(cat "$camino"/notes/float-$time) ]] && rm -f "$camino"/notes/float-$time
elif [ ! -f $track/list ]; then
[[ -f $track/bottom ]] && printfn bpay || printfn apay
fi;;
*@{*|*.jpg) unzip -p "$book" "$1" >/tmp/pic
yad --title="$1" --window-icon="$track/$TITLE/OEBPS/cover.png" --no-buttons --image /tmp/pic &;;
esac
}
export -f viewepubfn
function scratchpadfn (){ # notepad, dictionary lookup, translation, universal save selected text
mkfifo "$track"/dicpipe
exec 4<> "$track"/dicpipe
function transdic (){ # dictionary or translate
DATA="`$CLIP`"
OK=$(echo $DATA | wc -w)
TL=$(echo $DATA | rev | cut -f1 -d' ' | rev)
LANG=$(echo $DATA | rev | cut -f2-$$ -d' ' | rev)
OPTIONS="-play -player 'ffplay -autoexit -vf scale=240:-1 -noborder -i '"
if [[ "$TL" == "$LANG" ]]; then
export TL=$(cat "$track"/lang)
fi
[ -z "$TL" ] && export TL=$(cat "$track"/lang)
if [[ "$OK" == 1 ]]; then
trans -show-languages=y -show-original-phonetics=y -show-translation-phonetics=y "$LANG" -e "$ENGINE" -d -tl "$TL" | tr '' '/' | tr -d '/[1' | tr -d '/[22' | tr -d '/[24' | tr -d '' | tr -d '/[4' | sed -e 's/m, m/,/g' -e 's/mm/"/g' -e 's/- m/- /g' | while read line; do sed -e 's/^m//g' -e 's/$m//g' ; done > "$track"/dicpipe
elif [[ "$OK" -gt 1 ]]; then
trans -show-languages=y -show-original-phonetics=y -show-original-dictionary=y "$LANG" -e "$ENGINE" -tl "$TL" -play -player 'ffplay -noborder -nodisp -autoexit -i ' | tr '' '/' | tr -d '/[1' | tr -d '/[22' | tr -d '/[24' | tr -d '' | tr -d '/[4' | sed -e 's/m, m/,/g' -e 's/mm/"/g' -e 's/- m/- /g' | while read line; do sed -e 's/^[m]//g' -e 's/$[m]//g' ; done > "$track"/dicpipe
fi
}
export -f transdic
function scratcheval (){
( eval `$CLIP` > "$track"/dicpipe ) >/dev/null 2>&1 &
}
export -f scratcheval
export WINDOWTITLE="Scratchpad-Dictionary"
sayonara 4 &
yad --title="Scratchpad-Dictionary" --geometry="$(cat $camino/geometry/Scratchpad-Dictionary)" \
--editable --on-top --wrap --formatted --escape-ok --text-info --show-uri --tail --text="target language: af sq am ar hy eu be bn bs ny zh-CN zh-TW \nda nl bg yue ceb en eo et fj he hi hmn mww hu gu tl fi fr fy gl \nel ka de is id ga it ja jv kn ml mi lt lb mn my mt ne no fa pl pa \nro ru sm gd st cy xh sv tr th sl sk sw es lo ko co hr cs pt " \
--fontname="$FONT" --margins=8 --uri-color=blue --dialog-sep --fore=black --back=yellow --selectable-labels \
--buttons-layout=spread --button="Dict.Trans.!gtk-refresh!Select one word + language code for dictionary, more than two words + code for translation:bash -c 'transdic'" \
--button="Code exec!gtk-refresh!type some code and select with cursor then click this button:bash -c 'scratcheval'" \
--button="Print!gtk-refresh!print pdf or hardcopy:bash -c \"$CLIP > /tmp/clip; yad --print --type=text --filename=/tmp/clip --name=extract \"" \
--button="Save!gtk-refresh!Selected text from anywhere gets saved in notes:bash -c \"$CLIP >> $camino/notes/epub-$(date +%Y%d%h%a%H%M | tr -d' ') \"" --listen <& 4
}
export -f scratchpadfn
function menu_action (){
# figure out what was selected
case "$1" in
print)
$CLIP > /tmp/print
sleep 1
yad --print --filename=/tmp/print
kill $MENU_PID;;
noimage)
[[ ! -f "$track"/noimage ]] && touch "$track"/noimage || rm -f "$track"/noimage
kill $MENU_PID
bash -c \"geometryfn $WINDOWTITLE $TITLE;kill `cat $track/$num`;epubdo $book;;
lookup)
scratchpadfn &
transdic
kill $MENU_PID;;
esac
}; export -f menu_action
function menu (){
yad --list --width=200 --height=120 --mouse \
--column "action" --no-headers "" "print" "noimage" "lookup" \
--on-top --no-buttons --undecorated \
--select-action="bash -c \"menu_action "%s" \"" &
export MENU_PID=$!
}; export -f menu
function epubdo (){ # decompress epub file
touch $track/{float,list}
if [ -z "$CLIP" ]; then
if [[ ! -z `busybox which xsel` ]]; then
export CLIP="xsel -o -p"
elif [[ ! -z `busybox which xclip` ]]; then
export CLIP="xclip -o -p"
elif [[ ! -z `busybox which clipit` ]]; then
export CLIP="clipit -p"
fi
fi
export num=`pgrep -n yad`
mkfifo -m 755 "$track"/bookview-$num
exec 3<> "$track"/bookview-$num
export book="$1"
echo "$book" | while read line
do
line=$(echo "$line" | cut -f3 -d'>' | cut -f1 -d'<')
export line
export TITLE=$(echo "$line" | rev | cut -f1 -d'/' | rev)
[[ ! -f $track/EP ]]||[[ ! -f $track/MF ]] && break
unzip "$line" *cover* -d "$track"/"$TITLE"/
export XDIALOG_ITEMS=$(unzip -l $line *.*html | grep -v -e '.jpg' -e 'wrap' | sort -k3 | sed -nr 's/[-0-9: ]*(.*\/)(.*\.*html?$)/\1\2\n\2/p')
export XDIALOG_PICS=$(unzip -l $line *.*jpg | grep -v -e 'wrap' | sort -k3 | sed -nr 's/[-0-9: ]*(.*\/)(.*\.*jpg?$)/\1\2\n\2/p')
#cnt=1
#while read line
#do
#unzip -p "$line" "$i" | yad --plug=$$ --tabnum=$cnt --picture &
#cnt=$((cnt + 1))
#export cnt #for function tab number
#done <<< `echo "$XDIALOG_PICS"`
#rm -f /tmp/epubs
#for i in $(seq 1 1 $cnt)
#do
#echo " --tab=$i" >> /tmp/epubs
#done
#cat /tmp/epubs | tr '\n' ' ' > /tmp/epubtabs
##function tab content
#export these=`cat /tmp/epubtabs`
#yad --title=PICS --on-top --notebook --key=$$ --tab-pos=bottom $these &
echo -e "$XDIALOG_ITEMS\n$XDIALOG_PICS" >/tmp/line
ls "$track/$TITLE"/OEBPS/* | grep -e '.png' -e '.bmp' -e '.jpg' | while read this
do
ln -s "$this" "$track"/"$TITLE"/OEBPS/cover.png
done
# retrieve saved settings
export WINDOWTITLE="ebook-$TITLE"
if [ -f $camino/geometry/$WINDOWTITLE ]; then
cat $camino/geometry/$WINDOWTITLE | tail -1 | cut -d'|' -f1 > $track/font
cat $camino/geometry/$WINDOWTITLE | tail -1 | cut -d'|' -f2 > $track/fore
cat $camino/geometry/$WINDOWTITLE | tail -1 | cut -d'|' -f3 > $track/back
fi
( echo -e "$XDIALOG_ITEMS\n$XDIALOG_PICS" ) | yad --plug=$num --tabnum=1 --list --width=400 --item-seperator=' ' \
--select-action="bash -c \"viewepubfn "%s" \"" --dclick-action="bash -c \"menu $TITLE \"" --tooltip-column=1 \
--search-regex --search-column=1 --fontname="$FONT" \
--column="EPUB $line" --column=waste --hide-column=2 &
yad --plug=$num --tabnum=2 \
--fontname="$(cat $track/font)" \
--text-info --listen --editable --back="$(cat $track/back)" --wrap \
--fore="$(cat $track/fore)" --show-uri --search-regex \
--uri-color="$(cat $track/url)" > "$camino"/notes/ebook-extract-$time <& 3 &
export TEXT="select text first then press this button"
[ ! -z `busybox which espeak` ] && export option="--button=eSpeak!/usr/share/mini-icons/audio-volume-high.png!$TEXT:bash -c eSpeakfn" || export option=""
[ ! -f "$track"/noimage ] && export noitpo="--image=$track/$TITLE/OEBPS/cover.png" || export noitpo=""
yad --title="$WINDOWTITLE" --key=$num \
--geometry="$(cat $camino/geometry/$WINDOWTITLE | head -1)" ---columns=2 --height=800 --width=800 --paned --window-icon="$track/$TITLE/OEBPS/cover.png" \
--splitter="400" --orient=hor --tab=pages --tab=text \
"$option" "$noitpo" \
--button="Font!gtk-font!set font style and size:bash -c 'yad --font > $track/font'" \
--button="Text Color!/usr/share/mini-icons/mini.rainbow.xpm!choose text colour:bash -c 'yad --color > $track/fore'" \
--button="Back Color!/usr/share/mini-icons/mini.rainbow.xpm!choose background colour:bash -c 'yad --color > $track/back'" \
--button="Apply Changes!gtk-refresh!Re-open this book with font and colour changes. Saves window geometry and selected text:bash -c \"geometryfn $WINDOWTITLE $TITLE;kill `cat $track/$num`;epubdo $book \"" \
--button="Scratchpad!gtk-refresh!Dictionary-Translation-Print-Save:bash -c 'scratchpadfn'" &
echo "$!" > "$track/$num"
if [[ ! -z "`cat $camino/geometry/$WINDOWTITLE | tail -1 | cut -d'|' -f5`" ]]; then
viewepubfn "`cat $camino/geometry/$WINDOWTITLE | tail -1 | cut -d'|' -f5`"
fi
done
};export -f epubdo
function eBookfn (){ # create list of ebooks found in selected directory
# prepfn & wait $!
touch "$track"/{EP,HB,MF}
. "$track"/epubdir
if [[ ! -d "$EDIR" ]]; then
export WINDOWTITLE="Epub-Directory"
sayonara 8 &
export EDIR=$(yad --title="$WINDOWTITLE" --geometry="$(cat $camino/geometry/$WINDOWTITLE | head -1)" --window-icon="$w/2P.svg" --fontname="$FONT" --file --directory)
echo "EDIR=$EDIR" > "$track"/epubdir
fi
echo "$EDIR" | while read line
do
[[ ! -f "$track"/EP ]] && break
export media=$(find "$line" -type f -maxdepth 12)
export WINDOWTITLE="Epub-Library"
sayonara 4 &
function refreshfn (){
while read line
do
case $line in
*.epub) svgnum "$line" float
cnt=$((cnt + 1))
;;
esac
done <<< "$media"
}
export -f refreshfn
refreshfn
done | yad --window-icon="$w/2P.svg" --title="Epub-Library" \
--geometry="$(cat $camino/geometry/Epub-Library)" --column="Layouts:TXT" \
--column="TAG:IMG" --text="Give your ebook a human readable name.
Simply type and copy the new name, then
doubleclick the book in the list" --fontname="$FONT" --dclick-action="bash -c \"movefn "%s"; refreshfn \"" \
--select-action="bash -c \"epubdo "%s" \"" --button="Delete Book:bash -c \"rmfn "%s" \"" \
--button="Open Directory:bash -c '$FILEMAN $EDIR'" --button="Font:bash -c 'yad --font > $track/font'" \
--button="Col.A:bash -c 'yad --color > $track/fore'" --button="Col.B:bash -c 'yad --color > $track/back'" \
--list --search-column=1 &
export cnt=1
}
export -f eBookfn
if [[ ! -z "$Provided" ]]; then
timeout 2 preferences
touch "$track"/{EP,HB,MF}
epubdo "$Provided"
else
preferences
eBookfn
fi
rename to epub .... place in path /usr/sbin/epub .... in terminal change permissions of epub
Code: Select all
chmod 755 /usr/sbin/epub
After that you need to right click on an *.epub file/book and 'set run action' 'epub "$@"'