Skip to content

Instantly share code, notes, and snippets.

@luxigo
Last active August 7, 2016 09:10
Show Gist options
  • Save luxigo/9cc9c62037d33d822abb10d498d98e45 to your computer and use it in GitHub Desktop.
Save luxigo/9cc9c62037d33d822abb10d498d98e45 to your computer and use it in GitHub Desktop.
Play rar archives and directories with mplayer/gmplayer
#!/bin/bash
# gmplayer.sh - Builds and play a playlist based on the command line arguments
#
# * Command line arguments may include rar files or directory names.
#
# * Other mplayer options are preserved unless there is a file or directory
# matching the literal value.
#
# * To overcome this, command line parameters are not parsed anymore after "--"
# is encountered, and ignored after parameters listed in SKIP_PARAM below.
#
# * Symbolic links to directories are ignored to avoid recursion.
#
# INSTALLATION: Copy this script in ~/bin/gmplayer or /usr/local/bin/gmplayer
# LICENCE: DWTFYWWT
MPLAYER=/usr/bin/gmplayer
SKIP_PARAM="-playlist -sub -audiofile -enqueue -loop"
ARGS=()
MOUNTPOINTS=()
PLAYLIST=$(mktemp --tmpdir=/tmp playlist.XXXXXXXX) || exit
addFiles() {
while read f ; do
MIME=$(file -bi "$f")
if [[ $MIME =~ "audio" || $MIME =~ "video" ]] ; then
[ "${f:0:1}" != '/' ] && echo -n $PWD/ >> $PLAYLIST
echo "$f" >> $PLAYLIST
else
if [ -d "$f" ] ; then
# skip symbolic links for directories to avoid recursion
[ -L "$f" ] || addFiles <<< "$(find "$f" -type f)"
else
if [[ $MIME =~ application/x-rar ]] ; then
addRAR "$f"
fi
fi
fi
done
}
addRAR() {
MOUNTPOINT=$(mktemp -d --tmpdir=/tmp rar2fs.XXXXXXXX) || _exit
if rar2fs "${!#}" $MOUNTPOINT ; then
addFiles <<< "$(find $MOUNTPOINT -type f)"
MOUNTPOINTS+=($MOUNTPOINT)
else
rmdir $MOUNTPOINT
fi
}
_exit() {
RET=$?
for MOUNTPOINT in ${MOUNTPOINTS[@]} ; do
fusermount -u $MOUNTPOINT
rmdir $MOUNTPOINT
done
[ -f "$PLAYLIST" ] && rm $PLAYLIST
exit $RET
}
trap "_exit" SIGINT SIGKILL SIGTERM SIGHUP SIGQUIT
while [ $# -gt 0 ] ; do
if [ -n "$DONTPARSEANYMORE" ] ; then
ARGS+=("$1")
else
if [ "$1" == '--' ] ; then
DONTPARSEANYMORE=true
else
if [ -f "$1" -o -d "$1" ] ; then
addFiles <<< "$1"
else
ARGS+=("$1")
for OPT in $SKIP_PARAM ; do
if [ "$1" == "$OPT" ] ; then
shift
ARGS+=("$1")
break
fi
done
fi
fi
fi
shift
done
if [ -s "$PLAYLIST" ] ; then
$MPLAYER "${ARGS[@]}" -playlist $PLAYLIST
else
$MPLAYER "${ARGS[@]}"
fi
_exit
#!/bin/bash
# Tested on debian stretch
set -e
# you may need to specify the latest unrar version here
UNRAR_VERSION=5.3.11
echo === clone rar2fs
git clone https://github.com/hasse69/rar2fs
pushd .
cd rar2fs
echo === get unrar source
wget -c http://www.rarlab.com/rar/unrarsrc-$UNRAR_VERSION.tar.gz -O - | tar zxv
cd unrar
echo === build unrar
make
# create the unrar package and install it
# alternatively you can just run:
# sudo make install
echo === installing unrar package using checkinstall
sudo checkinstall -y --pkgversion $UNRAR_VERSION
echo === build libunrar
make lib
echo === installing libunrar using checkinstall
sudo checkinstall -y --pkgname libunrar --pkgversion $UNRAR_VERSION make install-lib
echo === configure rar2fs
popd
libtoolize --force
aclocal
autoheader
automake --force-missing --add-missing
autoconf
./configure --with-unrar=unrar --with-libunrar=unrar
echo === build rar2fs
make
echo === install rar2fs using checkinstall
sudo checkinstall -y --pkgversion $(date +%Y%m%d) --pkgname rar2fs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment