47 lines
1.2 KiB
Bash
Executable File
47 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
function timestamp() {
|
|
date +"%Y%m%d%H%M%S"
|
|
}
|
|
|
|
XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
|
|
|
|
mountpoint="$XDG_CACHE_HOME/btfs-$(timestamp)"
|
|
[ ! -d "$mountpoint" ] && mkdir "$mountpoint"
|
|
|
|
[ -z "$1" ] && printf "%s [magnet|*.torrent]\n" "$0" && exit 1
|
|
|
|
printf "Mounting %s to %s\n" "$1" "$mountpoint"
|
|
btfs "$1" "${mountpoint}"
|
|
btfs_status=$?
|
|
if [ $btfs_status != 0 ]; then
|
|
printf "Failed to mount torrent: %s\n" "$1"
|
|
exit $btfs_status
|
|
fi
|
|
while true; do
|
|
movie_dir_size=$(du -hs "$mountpoint"|awk '{print $1}')
|
|
printf "movie_dir_size: %s\n" "$movie_dir_size"
|
|
if [ "$movie_dir_size" != '4.0K' ] && [ "$movie_dir_size" != "0" ]; then
|
|
break;
|
|
else
|
|
sleep 5;
|
|
fi
|
|
done
|
|
|
|
printf "Locating the largest file...\n"
|
|
movie="$(find "$mountpoint" -type f -exec du -hs '{}' +|sort -rh|grep -vi sample|head -n1| \
|
|
awk '{$1=""; print $0}')"
|
|
movie=$(echo $movie|xargs)
|
|
[ -z "$movie" ] && printf "Could not locate the movie!\n" && exit 1
|
|
|
|
printf "Playing: %s\n" "$movie"
|
|
#smplayer -fullscreen "$movie" 1>/dev/null
|
|
mpv --fs --volume=100 "$movie" # 1>/dev/null
|
|
#vlc "$movie" 1>/dev/null
|
|
#kodi "$movie" 1>/dev/null
|
|
printf "Unmounting: %s\n" "$mountpoint"
|
|
fusermount -u "$mountpoint"
|
|
printf "Removing dir: %s\n" "$mountpoint"
|
|
rmdir "$mountpoint"
|
|
|