Refactor PDF handling, add rtorrent, man pages

This commit is contained in:
Arun Prakash Jana 2020-01-11 20:20:20 +05:30
parent 490359f853
commit 274c612076
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -41,8 +41,8 @@
# rar: list with unrar # rar: list with unrar
# 7-zip: list with 7z # 7-zip: list with 7z
# pdf: zathura (GUI), pdftotext, mutool, exiftool # pdf: zathura (GUI), pdftotext, mutool, exiftool
# m4a: mocplay (nnn plugin using MOC), mpv, mediainfo, exiftool # audio: mocplay (nnn plugin using MOC), mpv, mediainfo, exiftool
# torrent: transmission-show # torrent: rtorrent, transmission-show
# odt|ods|odp|sxw: odt2txt # odt|ods|odp|sxw: odt2txt
# htm|html|xhtml: w3m, lynx, elinks # htm|html|xhtml: w3m, lynx, elinks
# json: jq, python (json.tool module) # json: jq, python (json.tool module)
@ -52,6 +52,7 @@
# audio/*: mocplay (nnn plugin using MOC), mpv, mediainfo, exiftool # audio/*: mocplay (nnn plugin using MOC), mpv, mediainfo, exiftool
# application/pdf: zathura (GUI), pdftotext, mutool, exiftool # application/pdf: zathura (GUI), pdftotext, mutool, exiftool
# Other mimes: # Other mimes:
# text/troff: man -l
# text/* | */xml: vi # text/* | */xml: vi
# image/vnd.djvu): djvutxt, exiftool # image/vnd.djvu): djvutxt, exiftool
# #
@ -76,6 +77,23 @@ if ! [ -z "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')" ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi fi
handle_pdf() {
if [ $GUI -ne 0 ] && which zathura >/dev/null 2>&1; then
zathura "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which pdftotext >/dev/null 2>&1; then
## Preview as text conversion
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | less -R
exit 0
elif which mutool >/dev/null 2>&1; then
mutool draw -F txt -i -- "${FPATH}" 1-10
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | less -R
exit 0
fi
}
# handle this extension and exit # handle this extension and exit
handle_extension() { handle_extension() {
case "${ext}" in case "${ext}" in
@ -106,20 +124,7 @@ handle_extension() {
## PDF ## PDF
pdf) pdf)
if [ $GUI -ne 0 ] && which zathura >/dev/null 2>&1; then handle_pdf
zathura "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which pdftotext >/dev/null 2>&1; then
## Preview as text conversion
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | less -R
exit 0
elif which mutool >/dev/null 2>&1; then
mutool draw -F txt -i -- "${FPATH}" 1-10
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | less -R
exit 0
fi
exit 1;; exit 1;;
## Audio ## Audio
@ -141,7 +146,10 @@ handle_extension() {
## BitTorrent ## BitTorrent
torrent) torrent)
if which transmission-show >/dev/null 2>&1; then if which rtorrent >/dev/null 2>&1; then
rtorrent "${FPATH}"
exit 0
elif which transmission-show >/dev/null 2>&1; then
transmission-show -- "${FPATH}" transmission-show -- "${FPATH}"
exit 0 exit 0
fi fi
@ -273,20 +281,7 @@ handle_multimedia() {
## PDF ## PDF
application/pdf) application/pdf)
if [ $GUI -ne 0 ] && which zathura >/dev/null 2>&1; then handle_pdf
zathura "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which pdftotext >/dev/null 2>&1; then
## Preview as text conversion
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | less -R
exit 0
elif which mutool >/dev/null 2>&1; then
mutool draw -F txt -i -- "${FPATH}" 1-10 | less -R
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | less -R
exit 0
fi
exit 1;; exit 1;;
# pdftoppm -f 1 -l 1 \ # pdftoppm -f 1 -l 1 \