by on Feb.14, 2011, under Linux, Scripts


# randomize website youtube videos created by Jamey Hopkins
# site then uses PHP to display the selected video on the site
# 20100427 jah - ->
#                conversion to 0 byte file use
#                cut out email
# 20100527 jah - create a .selected file for reference
# 20110214 jah - use /bin/bash since ubuntu uses dash for sh which is not compat. w/ FILE=($FILES)
# NOTE: use vid.1.yt2,, etc, to specify the same video more than once (increase odds)
#       move *.yt to * (or some other extension) to disable selection


cd /root/Scripts/

# match specific or all random
# use -- to handle files that start with -
[ "$1" != "" ] && FILES=`ls -- *$1*.yt 2>/dev/null` || FILES=`ls -- *.yt 2>/dev/null`

echo "Matching Files:"
echo "$FILES"

# perform random magic
NFILES=${#FILE[*]} #count
VID=`echo ${FILE[$((RANDOM%NFILES))]}`

echo "Picked -> $VID"

# send random youtube string to file
echo "$VID" | cut -f1 -d. > /var/www/
rm -- *selected >/dev/null 2>&1
cp -- $VID $VID.selected

No comments for this entry yet...

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

But Wait, There's More!

A few highly recommended friends...