I have this vlc script for automating VLC so that it plays a certain number of TV show episodes. Once you plug in the relevant path and create a list name for a text file where the absolute paths of all the media files get written, it plays a chosen number of files and then exits.
I've recently added a desktop to my PC lineup and now all my files are stored there. It's a Win7 box, and all the relevant directories are being shared. When the files were local, I had no problems at all. Now, I'm having a problem either with Samba, or with my file name structure which contains spaces and special characters. I'm not sure which is the cause of the problem.
On my Linux laptop, where this script is running, the shared folders are all permanently mounted in a mountpoint I created - /mnt/Shares/SubFolders
From the Linux laptop, I have full read/write access. I can execute the pertinent commands in this script manually from a terminal, and they complete successfully without any problems. When I try to run the script, though, it does create the list with the given name, but the file is empty, as though the folders were empty.
Here is the script:
Code:
#!/bin/bash
#
# Creates a list of all files in all Simpsons folders and then
# plays so many random episodes with VLC Media Player.
# Created by Uncertain
# Filenames and paths.
path1='/mnt/Shares/K/TV/Simpsons'
list='/home/zero/EpisodeLists/Simpsons'
# Check for the list. If it exists, fine.
# If it doesn't exist, create it.
if [ -f "$list" ]
then
echo "List found."
else
echo "Episodes list not found. Creating list arranged by season & episode..." && find "$path1" -name '*.avi' -o -name '*.mpg' -o -name '*.mp4' -o -type f -size +20M | sort > "$list" && cd ~ && echo "Done. List created"
fi
# Set the number of episodes to play. Episodes are
# roughly 20 mins, so three episodes to every hour.
repeat=4
cycles=0
while [ $cycles -ne $repeat ]
do
echo $cycles
cycles=$(( $cycles + 1 ))
# Read the list, select one random line.
Rand=`dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" "`
LowerBound=1
UpperBound=`cat $list | wc -l`
let "Range = $UpperBound - $LowerBound + 1"
let "RandomLine = $LowerBound + ($Rand % $Range)"
episode=`sed -n "$RandomLine{p;q;}" "$list"`
# open the random line in VLC
vlc -vvv --fullscreen "$episode" vlc://quit
# Close the episode count loop...
done
# ...and then...
exit
I assume it's a problem with the find|sort string, since it's creating an empty file list. I'm not sure what the problem would be, since I can copy & paste that command string into a terminal and it will execute without a problem. In fact, I can create the list manually like that, and the script will run without issue. When there's an empty list, though, VLC just opens & closes right away since there's no file being played.
Can anyone find the flaw?