wustho / epy

CLI Ebook (epub2, epub3, fb2, mobi) Reader
GNU General Public License v3.0
928 stars 52 forks source link

[Feature Request] Importing book lists to epy history database #86

Open tkapias opened 1 year ago

tkapias commented 1 year ago

First of all, thank you for this program! I mostly use Calibre to manage my epub/pdf, but I want to use EPY more often for its smoothness. Besides, I will try to propose an implementation of ueberzug++ for images.

The only thing I see missing is the ability to browse the books available in my calibre collection. Calibre arranges books in folders by author, so finding a book by its PATH is sometimes complicated.

The easiest way to do it would be to:

I'm have manually edited the states.db database and I have an external alias with fzf to select a book, but an implementation would be nice.

wustho commented 1 year ago

Hey there, somehow I just read this, yeah I was working on inline image view in terminal, even tried ueberzug, but the issue is more of terminal capability and there is so many terminal that it will be difficult to maintain.

Maybe you can check out new release baca: https://github.com/wustho/baca I made it from epy with modern framework. It has fuzzy mathcing feature to read from history.

tkapias commented 1 year ago

Thanks @wustho, baca's usage of textual is interesting and I will follow the project. But, currently, even if it's a project in initial stage and compared to epy, it's awfully slow. I want my cli usage to be snappy above all features.


Here is the bash function that I use to select books from my Calibre library and open them with epy:

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# epycalibrary - Select a book in your calibre library and open it in epy
epylibre() {
  Help() {
    cat <<- HEREDOC 1>&2

    Calibre Book Selector for "epy" (epub terminal reader).

    Usage: epylibre "<calibre/folder/path>"

    - The path is optional if you have defined it
      in an env variable named 'CALIBRELIBRARY'.

    HEREDOC
  }
  while getopts ":h" option; do
    case $option in
       h) Help; return 0 ;;
      \?) echo -e "Unknown option: -$OPTARG \n"       >&2; Help; return 1;;
      : ) echo -e "Missing argument for -$OPTARG \n"  >&2; Help; return 1;;
      * ) echo -e "Unimplemented option: -$option \n" >&2; Help; return 1;;
    esac
  done

  array=( epy fzf )
  for cmd in "${array[@]}"; do
   if [[ -z $(command -v "$cmd") ]]; then
     echo "Requirements: at least $cmd could not be found:"
     return 1
   fi
  done

  if [[ -z $1 ]] && [[ -n $CALIBRELIBRARY ]]; then
    local _CALIBREPATH=$(realpath --canonicalize-existing "$CALIBRELIBRARY" 2> /dev/null)
  else
    local _CALIBREPATH=$(realpath --canonicalize-existing "$1" 2> /dev/null)
  fi

  if [[ -z $_CALIBREPATH ]]; then
    echo "Error: Calibre directory not found."
    Help
    return 1
  fi

  local _EPUB=$(find "$_CALIBREPATH" -type f -iname '*.epub' \
    | while read _FILE; do
      _REALFILE=$(realpath "$_FILE")
      readarray -t _METADATA < <(sed -En \
        -e '/dc:title/{s/^.+<dc:title>|<\/dc:title>$//gp}' \
        -e '/calibre:series/{s/^.+\scontent=\"|\"\/>//g;H}' \
        -e '/dc:creator/{s/^.+opf:role=//g;H}' \
        -e '${x;{s/<\/dc:creator>\n\"aut\">/, /g};{s/^\n|\"aut\">|<\/dc:creator>//g};p}' \
        "$(dirname "$_REALFILE")"/metadata.opf)
      if [[ -z ${_METADATA[2]} ]]; then
        _METADATA[2]="-"
        _METADATA[3]="-"
      fi
      echo "${_METADATA[2]}|${_METADATA[3]}|${_METADATA[1]}|${_METADATA[0]}|${_REALFILE}"
    done \
    | sort --field-separator '|' --key=3,3 --key=2,2n --key=1,1 --ignore-case --ignore-leading-blanks \
    | column --output-separator '   ' --separator '|' --table --table-columns 'Serie-------------->,Index,Author-------------->,Title,File' --table-columns-limit 5 --table-truncate 1,3 \
    | fzf --no-mouse --cycle --reverse --no-hscroll --header-lines=1 --prompt "Choose an EPUB book to read with epy > " \
    | awk -F '\t' '{print $NF}')
  if [[ -n $_EPUB ]]; then
    epy "$_EPUB"
  else
    return 1
  fi
}

image

tkapias commented 1 year ago

About the function that I use above:

At first it included a preview frame in fzf to display some metadata and the cover of the highlighted epub. I removed it because it does not leave enough space for the columns in the main frame.

It's enough for me but It's not directly portable to other systems, it would be nice if epy (or baca) could to this kind of library populating from a directory.