Looking for help with a script to automate VLC

Hi,
New member here looking for help. This might not be a post for the 'VERY basics' section, so feel free to move it to somewhere more appropriate.

I've created a script that searches my computer for video files, creates a list of these files, and selects a number of random entries to play in VLC. After a recent catastrophic external HDD failure, everything I could recover has been moved to two computers on a LAN. Now, instead of just searching my ~/Videos folder for the files to index and play, I have to search the ~/Videos folder of a second computer as well, index those (appended to the same list, preferably), and include them in the random shuffle I've created.

I have SSH & SCP access on both machines (I recently learned how to implement passwordless-ssh using rsa & dsa keyfiles, specifically so these processes could be automated). I don't have Samba or NFS installed or working on either computer, but I'll install and configure them if need be. (Though I'd rather not install, configure, and enable NFS or Samba, edit fstab, and then auto-mount a remote folder at boot just to do this.) Just today, I've learned how to start VLC on the remote computer in network-streaming mode, and then start VLC on the local host in network-capture mode. All I'm having a hard time conceptualizing is how to implement the indexing process from a script on the local machine to list files on a remote machine.

Here's a copy of my script in its' current state. It's the first BASH scripting project I ever tackled, and 'borrowed' bits & pieces of it from various things I found via Google. I'm sure there's a better/smoother/cleaner way to do some of the things I did, but it works, and I'm happy with it. Right now, it's set to index all the episodes of The Simpsons that are in my hard drive, and then play several random episodes.

If anyone could point me in a direction or give me some pointers, I'd greatly appreciate it.

#!/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=/home/zero/Videos/
path2=/home/zero/Videos/Simpsons
list=/home/zero/Videos/Simpsons/episodes.txt
# Check for the list. If it's in ~/Videos, fine.
# If it doesn't exist, create it in ~/Videos.
if [ -f $list ]
 then
  echo "List found at $list"
   else
    echo "Episodes list not found. Creating list arranged by season & episode..." && cd $path1 && find ~/Videos/Simpsons -name '*.avi' -o -name '*.mpg' -o -name '*.mp4' -o -type f -size +20M | sort > $list && echo "Done. List created at: $list" 
fi
# Set the number of episodes to play. Episodes are 
# roughly 20 mins, so three episodes to every hour.
repeat=3
cycles=0
while  [ $cycles -ne $repeat ]
 do
  echo $cycles
  cycles=$(( $cycles + 1 ))
# Read the list, select one random line.
LowerBound=1
RandomMax=32767
UpperBound=$(cat $list | wc -l)
RandomLine=$(( $LowerBound + ($UpperBound * $RANDOM) / ($RandomMax + 1) ))
# Use sed to grab the random line.
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

NFS is your answer. With NFS you mount up a remote folder as if it were a local one. Then your script just has to give the find command a couple of folders to find your video files, rather than just the one, e.g.

find ~/Videos/Server1 ~/Videos/Server2 -name '*.avi' -o -name '*.mpg' -o -name '*.mp4' -o -type f -size +20M | etc...

By the way you don't need a cd before your find command because you're providing a full pathname to find. Context is only important if you're using a relative pathname.

I actually decided to go with NFS somewhere in the mix. After looking up what all goes into launching VLC in streaming mode, trying to do it remotely (after somehow determining whether I need to launch VLC remotely or locally) and then launching it locally to pick up a network stream and then blah blah blah.. Yes, NFS seemed the way to go for exactly the reason you describe. The remote videos folder is just another folder on my desktop, and gets indexed just the same.

I'm surprised you caught the 'cd' thing in the script. I'm even more surprised it never registered with me. It's a remnant from when I first started writing it and I was using 'locate' instead of 'find'.

I'm actually off now to post a thread somewhere about fine-tuning NFS transfer speeds. I'm having a bottleneck somewhere with NFS and SSH transfers, and playing these videos over an NFS tunnel can be a less than enjoyable experience.

Anyhoo, thanks for the advice. Cheers!