Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tkapias opened this issue Feb 24, 2023 · 3 comments
Open

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

tkapias opened this issue Feb 24, 2023 · 3 comments

Comments

@tkapias
Copy link

tkapias commented Feb 24, 2023

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:

  • add all the books available recursively to the history
  • optionally: be able to open EPY directly on the history page
  • optionally: use fzf or fzf-tmux to display/sort/filter the history list in epy

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
Copy link
Owner

wustho commented Mar 27, 2023

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
Copy link
Author

tkapias commented Mar 30, 2023

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
Copy link
Author

tkapias commented Mar 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants