ciphermethod.com

20110214: yt2.sh

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


#!/bin/bash

# randomize website youtube videos created by Jamey Hopkins
# site then uses PHP to display the selected video on the site
# 20100427 jah - youtuberand.sh -> yt2.sh
#                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, vid.same.yt, etc, to specify the same video more than once (increase odds)
#       move *.yt to *.yt.off (or some other extension) to disable selection
#

echo

cd /root/Scripts/yt2.cm

# 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
FILE=($FILES)
NFILES=${#FILE[*]} #count
VID=`echo ${FILE[$((RANDOM%NFILES))]}`

echo
echo "Picked -> $VID"

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

echo
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...