|
|
|
@ -27,11 +27,27 @@ |
|
|
|
|
# You can also regenerate it immediately before a run by using the -r switch |
|
|
|
|
# |
|
|
|
|
# Use -m to utilize ebook metadata instead of the file structure mentioned above. |
|
|
|
|
############################################################################## |
|
|
|
|
# |
|
|
|
|
# add in subject from exiftool (may need to add cpan install Activity::Zip (I think?) for tags |
|
|
|
|
# |
|
|
|
|
# |
|
|
|
|
# Why wasn't I using this??? |
|
|
|
|
# calibredb list -f authors,formats,cover,tags,series,series_index,title --separator § |
|
|
|
|
# id is first row, so can run multiple times to attach id to each of these. Or maybe feed into |
|
|
|
|
# memory dynamically for fzf? That's probably better, innit? |
|
|
|
|
# calibredb list -f authors,formats,cover,tags,series,series_index,title --separator § |
|
|
|
|
# # need check for multi-format |
|
|
|
|
# # preview window for cover and/or summary? |
|
|
|
|
#With Preview |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
# use both so can use whatever backend, even without calibre at all. |
|
|
|
|
############################################################################## |
|
|
|
|
|
|
|
|
|
SCRIPTDIR="$( cd "$(dirname "$0")" ; pwd -P )" |
|
|
|
|
# Books directory |
|
|
|
|
BOOKS_DIR="/home/steven/documents/Calibre Library/" |
|
|
|
|
BOOKS_DIR="${HOME}/documents/Calibre Library/" |
|
|
|
|
EXIFTOOL=$(which exiftool) |
|
|
|
|
FD_FIND=$(which fdfind) |
|
|
|
|
EPY=$(which epy) #https://github.com/wustho/epy |
|
|
|
@ -41,6 +57,8 @@ REGEN="false" |
|
|
|
|
CliOnly="true" |
|
|
|
|
CacheFile="$HOME/.cache/book_search_cache" |
|
|
|
|
CALIBRE_STRUCTURE="true" |
|
|
|
|
CALIBREDB="true" |
|
|
|
|
GUIOUTPUT="true" |
|
|
|
|
# So that I don't have to worry about the structure of the path too hard |
|
|
|
|
SLASHES=$(echo "$BOOKS_DIR" | grep -o '/' | wc -l) |
|
|
|
|
((SLASHES++)) |
|
|
|
@ -84,29 +102,51 @@ gen_list (){ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main() { |
|
|
|
|
|
|
|
|
|
if [ "$REGEN" != "false" ];then |
|
|
|
|
gen_list |
|
|
|
|
fi |
|
|
|
|
if [ ! -f $CacheFile ];then |
|
|
|
|
gen_list |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [ "$CliOnly" == "true" ];then |
|
|
|
|
SelectedBook=$(cat $CacheFile | fzf --no-hscroll -m --height 60% --border --ansi --no-bold --header "Which Book?" ) |
|
|
|
|
# using calibre db data |
|
|
|
|
if [ "$CALIBREDB" != "false" ];then |
|
|
|
|
if [ "$CliOnly" == "true" ];then |
|
|
|
|
SelectedBook=$(calibredb list -f title,authors | awk '/^[1-9]/' | fzf +x -e -i --no-hscroll -m --height 80% --border --ansi --no-bold --preview="$SCRIPTDIR/book_search_preview.sh {}"|awk '{print $1}') |
|
|
|
|
else |
|
|
|
|
#use ROFI, not zenity |
|
|
|
|
SelectedBook=$(calibredb list -f title,authors | awk '/^[1-9]/' | rofi -i -dmenu -p "Which Book?" -theme DarkBlue |awk '{print $1}') |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
NumFormats=$(calibredb list --search id:"${SelectedBook}" -f formats --for-machine 2>/dev/null | grep -c -e \"\/) |
|
|
|
|
echo "$NumFormats" |
|
|
|
|
if [ $NumFormats -gt 1 ];then |
|
|
|
|
echo "HI ${SelectedBook}" |
|
|
|
|
book=$(calibredb list --search id:"${SelectedBook}" -f formats --for-machine 2>/dev/null | grep -e \"\/ | sed 's/\"\,$/"/' | fzf | xargs) |
|
|
|
|
else |
|
|
|
|
book=$(calibredb list --search id:"${SelectedBook}" -f formats --for-machine 2>/dev/null | grep -e \"\/ | sed 's/\"\,$/"/' | xargs) |
|
|
|
|
fi |
|
|
|
|
type="${book##*.}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
#use ROFI, not zenity |
|
|
|
|
SelectedBook=$(cat $CacheFile | rofi -i -dmenu -p "Which Book?" -theme DarkBlue) |
|
|
|
|
fi |
|
|
|
|
if [ "$REGEN" != "false" ];then |
|
|
|
|
gen_list |
|
|
|
|
fi |
|
|
|
|
if [ ! -f $CacheFile ];then |
|
|
|
|
gen_list |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
#extra xargs to strip newlines and whitespace |
|
|
|
|
book=$( echo "$SelectedBook" | awk -F '|' '{print $4}' | xargs) |
|
|
|
|
type=$( echo "$SelectedBook" | awk -F '|' '{print $1}' | xargs) |
|
|
|
|
if [ "$CliOnly" == "true" ];then |
|
|
|
|
SelectedBook=$(cat $CacheFile | fzf --no-hscroll -m --height 60% --border --ansi --no-bold --header "Which Book?" ) |
|
|
|
|
else |
|
|
|
|
#use ROFI, not zenity |
|
|
|
|
SelectedBook=$(cat $CacheFile | rofi -i -dmenu -p "Which Book?" -theme DarkBlue) |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
#extra xargs to strip newlines and whitespace |
|
|
|
|
book=$( echo "$SelectedBook" | awk -F '|' '{print $4}' | xargs) |
|
|
|
|
type=$( echo "$SelectedBook" | awk -F '|' '{print $1}' | xargs) |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [ -n "$book" ]; then |
|
|
|
|
if [ "${GUIOutput}" == "true" ];then |
|
|
|
|
CliOnly="false" |
|
|
|
|
fi |
|
|
|
|
if [ "$CliOnly" == "false" ];then |
|
|
|
|
xdg-open "${book}" |
|
|
|
|
else |
|
|
|
@ -159,17 +199,25 @@ display_help(){ |
|
|
|
|
echo "# -r regenerate booklist (and run) " |
|
|
|
|
echo "# -e regenerate booklist (and exit) " |
|
|
|
|
echo "# -g use GUI (rofi) " |
|
|
|
|
echo "# -x use xdg-open for output (but fzf for selection) " |
|
|
|
|
echo "# -f do NOT use Calibre's database " |
|
|
|
|
echo "# -m Use ebook metadata, not file structure" |
|
|
|
|
echo "# FAIR WARNING: PDF METADATA IS OFTEN BORKED BEYOND RECOGNITION!" |
|
|
|
|
echo "###################################################################" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# sanity check |
|
|
|
|
if [ ! -f $(which calibredb) ];then |
|
|
|
|
CALIBREDB="false" |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# Read in variables |
|
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do |
|
|
|
|
option="$1" |
|
|
|
|
case $option in |
|
|
|
|
-f) CALIBREDB="false" |
|
|
|
|
shift ;; |
|
|
|
|
-m) CALIBRE_STRUCTURE="false" |
|
|
|
|
shift ;; |
|
|
|
|
-h) display_help |
|
|
|
@ -180,7 +228,10 @@ display_help(){ |
|
|
|
|
-e) gen_list |
|
|
|
|
exit |
|
|
|
|
shift ;; |
|
|
|
|
-x) GUIOutput="true" |
|
|
|
|
shift ;; |
|
|
|
|
-g) CliOnly="false" |
|
|
|
|
GUIOutput="false" |
|
|
|
|
shift ;; |
|
|
|
|
esac |
|
|
|
|
done |
|
|
|
|