#!/bin/sh # This is a small script to open a book from your calibre library # Using dmenu. USERNAME="yigitcolakoglu" PASSWORD="$(pass show Server/calibre.yigitcolakoglu.com/yigitcolakoglu)" HOST="https://calibre.fr1nge.xyz" function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } rawurlencode() { local string="${1}" local strlen=${#string} local encoded="" local pos c o for (( pos=0 ; pos\(.*\)<\/title>/\1|/;N;s/\(.*\)<\/name>/\1|/;N;s/href="\(.*\)"/\1/;s/\n/ /g' | \ column -s '|' -t -T 1 -c 200| dmenu -i -p "Please select the book" -l 5) [ -z "$book" ] && exit name=$(echo "$book" | sed 's/\s\{2,\}/\n/g' | head -n 1) author=$(echo "$book" | sed 's/\s\{2,\}/\n/g' | head -n 2 | tail -n 1) path=$(echo "$book" | sed 's/\s\{2,\}/\n/g' | tail -n 1) mkdir -p "$XDG_RUNTIME_DIR/books" notify-send -a " Downloading" "$(printf "%s\n%s" "$name" "$author")" wget -nc -P "$XDG_RUNTIME_DIR/books" -q --content-disposition \ --user "$USERNAME" --password "$PASSWORD" "$HOST$path" out=$(curl -s --head -u "$USERNAME:$PASSWORD" "$HOST$path" | \ grep "Content-Disposition" |\ sed -E 's/Content-Disposition:.*filename=([^;]*);.*/\1/g') filename="$XDG_RUNTIME_DIR/books/$(urldecode $out)" fi xdg-open "$filename"