You are not logged in.

#1 2016-05-21 20:50:33

TheChickenMan
Member
From: United States
Registered: 2015-07-25
Posts: 354

Help with a nonfunctional thumbnailer script

I had been working on trying to create a thumbnailer to properly display when I get a ms-office type file. I found a script and series of files online in my research intended for use with ubuntu and edited that to create a package for arch. PKGBUILD posted below. The project can be found here and with some supporting files from the github page. I read through the gnome developers site about creating thumbnailers along with the minimal documentation provided by that ubuntu project and it seems to me that it should work with nautilus in arch as well. The package builds and installs fine but it doesn't seem to actually create the thumbnails. I watched that it was creating image files in tmp but I'm not really sure where to go next to debug this or if there is a better alternative.

PKGBUILD:

pkgname=ms-office-thumbnailer
pkgver=2016.05.04
pkgrel=1
pkgdesc="A group of scripts pulled from ubuntu to create thumbnails for ms office document files."
arch=('any')
url="http://bernaerts.dyndns.org/linux/76-gnome/325-gnome-shell-generate-msoffice-thumbnail-nautilus"
license=('GPL')
depends=('gvfs' 'imagemagick' 'perl-file-mimeinfo' 'unoconv' 'unzip')
_base_url="https://raw.githubusercontent.com/NicolasBernaerts/ubuntu-scripts/master"
source=("$_base_url/thumbnailer/msoffice/msoffice-thumbnailer"
	"$_base_url/thumbnailer/msoffice/msoffice.thumbnailer"
	"$_base_url/thumbnailer/msoffice/icons/msoffice-mask.png"
	"$_base_url/thumbnailer/msoffice/icons/msoffice-word.png"
	"$_base_url/thumbnailer/msoffice/icons/msoffice-excel.png"
	"$_base_url/thumbnailer/msoffice/icons/msoffice-powerpoint.png")
sha256sums=('0984dcb9c4bba8b2cfb20ab384d48c6c7d49feb14c73a6f9290013ba063bae29'
	    '19d164c1987c50d92a2bfccea953336bf244f546ac82cf21d0d785b0448f53e9'
	    '19527e745867b2d735b26be6cbcef2e4595b3d7f5cf11b35464fc5c885580627'
	    'b84765601d5b748716cb7de02f1501e05d651651011c41f7ba3fd79532208a31'
	    'c963692d6a6bbe5b28e27e1cc7705cfadf5e6631924643cd2237c826adeb3e6e'
	    '7104780d3f700fef739d0a42b242d544ffda3185592fdd74bc621a5f794b3230')
prepare () {
	cd $srcdir
		
	_o_install='ICONPATH="/usr/local/sbin/msoffice-thumbnailer-icons"'
	_install='ICONPATH="/usr/lib/ms-office-thumbnailer/icons"'
	sed -i 's|'$_o_install'|'$_install'|g' 'msoffice-thumbnailer'
	
	_o_exec='/usr/local/sbin/msoffice-thumbnailer'
	_exec='/usr/bin/ms-office-thumbnailer'
	sed -i 's|'$_o_exec'|'$_exec'|g' 'msoffice.thumbnailer'
}
package () {
	cd $srcdir
	
	_install='usr/lib/ms-office-thumbnailer/icons'
	install -Dm 644 msoffice-mask.png $pkgdir/$_install/msoffice-mask.png
	install -Dm 644 msoffice-word.png $pkgdir/$_install/msoffice-word.png
	install -Dm 644 msoffice-excel.png $pkgdir/$_install/msoffice-excel.png
	install -Dm 644 msoffice-powerpoint.png $pkgdir/$_install/msoffice-powerpoint.png
	
	install -Dm 644 msoffice.thumbnailer $pkgdir/usr/share/thumbnailers/ms-office.thumbnailer
	install -Dm 755 msoffice-thumbnailer $pkgdir/usr/bin/ms-office-thumbnailer
}

Script:

#!/bin/sh
# ---------------------------------------------------
# Thumbnailer for Ms Office documents
#
# Procedure :
#   http://bernaerts.dyndns.org/linux/76-gnome/325-gnome-shell-generate-msoffice-thumbnail-nautilus
# Depends on :
#   * unoconv
#   * gvfs-copy (gvfs-bin package)
#   * convert and composite (imagemagick package)
# Parameters :
#   $1 - URI of office file
#   $2 - full path of generated thumbnail
#   $3 - height of thumbnail in pixels
# Revision history :
# 11/11/2014, V1.0 - Creation by N. Bernaerts
# 15/11/2014, V2.0 - Change to URI and GVFS to handle thumbnails on network shares
# 31/07/2015, V2.1 - More robust unoconv command line (thanks to Vaderqk)
# ---------------------------------------------------

# check tools availability
command -v gvfs-copy >/dev/null 2>&1 || exit 1
command -v unoconv >/dev/null 2>&1 || exit 1
command -v convert >/dev/null 2>&1 || exit 1
command -v composite >/dev/null 2>&1 || exit 1

# path where to get icons used for generation
ICONPATH="/usr/lib/ms-office-thumbnailer/icons"

# get parameters
FILE_URI=$1
FILE_THUMB=$2
HEIGHT=$3

# get filename extension
FILE_EXT=$(echo "$FILE_URI" | sed 's/^.*\.\(.*\)/\1/')

# generate temporary directory
TMP_DIR=$(mktemp -d)
TMP_BASEFILE="$TMP_DIR/file"

# copy file to temporary local directory
gvfs-copy "${FILE_URI}" "${TMP_BASEFILE}.${FILE_EXT}"

# get the file mime type (application/msword, ...)
MIMETYPE=$(mimetype -b "${TMP_BASEFILE}.${FILE_EXT}")

# determine icon type according to mime type
case $MIMETYPE in 
  "application/msword" | "application/vnd.ms-word" | \
  "application/vnd.openxmlformats-officedocument.wordprocessingml.document" )
    DOCTYPE="word"
    ;;
  "application/vnd.ms-excel" | \
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | \
  "application/vnd.openxmlformats-officedocument.spreadsheetml.template" )
    DOCTYPE="excel"
    ;;
  "application/vnd.ms-powerpoint" | \
  "application/vnd.openxmlformats-officedocument.presentationml.presentation" | \
  "application/vnd.openxmlformats-officedocument.presentationml.template" | \
  "application/vnd.openxmlformats-officedocument.presentationml.slideshow" )
    DOCTYPE="powerpoint"
    ;;
  * )
esac

# convert first document page to PDF
unoconv -e PageRange=1-1 -f pdf "${TMP_BASEFILE}.${FILE_EXT}"

# convert PDF to PNG
convert "${TMP_BASEFILE}.pdf" "${TMP_BASEFILE}.png"

# generate thumbnail according to document type
composite -gravity center \( -resize x244 "${TMP_BASEFILE}.png" \) ${ICONPATH}/msoffice-${DOCTYPE}.png ${ICONPATH}/msoffice-mask.png \( -resize x${HEIGHT} \) "$FILE_THUMB"

# remove temporary files
rm -R $TMP_DIR

Thumbnailer File:

[Thumbnailer Entry]
TryExec=/usr/bin/ms-office-thumbnailer
Exec=/usr/bin/ms-office-thumbnailer %u %o %s
MimeType=application/msword;application/vnd.ms-word;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.ms-excel;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.openxmlformats-officedocument.spreadsheetml.template;application/vnd.ms-powerpoint;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.openxmlformats-officedocument.presentationml.template;application/vnd.openxmlformats-officedocument.presentationml.slideshow;application/ms-office;

Last edited by TheChickenMan (2016-05-23 19:10:57)


If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet.
Niels Bohr

Offline

Board footer

Powered by FluxBB