#!/bin/bash
#h=`date +%l`
#m=`date +%M`
#Next 3 lines are temp for testing the script
h=$1
m=$2
a=$3
c=0 # used to flag if AM/PM toggled due to hour increment
#$filep="/home/rick/projects/radioPlaylist" # because i don't feel like typing it 100 times
echo "time: $h:$m$a" > /home/rick/playlist.log
echo "downloading web page to file..." >> /home/rick/playlist.log
#-----Get the page and save it to a file
/usr/bin/curl http://www.mediabase.com/whatsong/whatsong.asp?var_s=075069068074045070077 > /home/rick/projects/radioPlaylist/savedPage.html
echo "downloaded!" >> /home/rick/playlist.log
echo "Searching for artist name..." >> /home/rick/playlist.log
#-----Get the Artist-------
artist=`/bin/cat /home/rick/projects/radioPlaylist/savedPage.html | /bin/grep ">$h:$m $a" -A 1 | /usr/bin/tail -n1 | /bin/sed 's/
//' | /bin/sed 's/<\/td>/\n/' | /usr/bin/head -n1`
if [[ $artist = "" ]] #--If we didn't find an artist
then #--Then increment the minute
m=`/usr/bin/expr $m + 1`
if [[ $m = 60 ]] #--Obviously we can't check 2:60 oclock
then
h=`/usr/bin/expr $h + 1` #increment the hour and
m=00 # change the minute
if [[ $h = 12 ]] # might need to toggle AM PM
then
if [[ $a = "AM" ]]
then
a="PM"
else
a="AM"
fi
c=1
fi
fi
if [[ $h = 13 ]] # Now we also need to check for the hour being too high
then
h=1
fi
echo "time: $h:$m $a"
artist=`/bin/cat /home/rick/projects/radioPlaylist/savedPage.html | /bin/grep ">$h:$m $a" -A 1 | /usr/bin/tail -n1 | /bin/sed 's/ | //' | /bin/sed 's/<\/td>/\n/' | /usr/bin/head -n1`
if [[ $artist = "" ]] # if the artist still has not been found
then # then set the time back to normal
if [[ $c = 1 ]] # if we changed the am/pm setting
then # then reset it
a=$3
c=0
fi
h=$1
m=$2
fi
fi
while [[ $artist = "" ]] #--If we didn't find an artist
do # then continue to subtract a minute till we find one
m=`/usr/bin/expr $m - 1`
if [[ $m = -1 ]] #--Obviously we can't check 2:-1 oclock
then
h=`/usr/bin/expr $h - 1` #decrement the hour and
m=59 # change the minute
if [[ $h = 0 ]] # Need to change from 0:00 to 12:00
then
h=11
fi
if [[ $h = 11 ]] # this is where we might need to toggle AM/PM
then
if [[ $m = 59 ]]
then
if [[ $a = "AM" ]]
then
a="PM"
else
a="AM"
fi
fi
fi
fi
if [[ $h = 13 ]] # Now we also need to check for the hour being too high
then
h=1
fi
if [[ $m -lt 10 ]] # the earlier correction stuff makes anything<0 look like: 12:1 instead of 12:01. We have to add that zero
then
m="0$m"
fi
echo "time: $h:$m $a"
artist=`/bin/cat /home/rick/projects/radioPlaylist/savedPage.html | /bin/grep ">$h:$m $a" -A 1 | /usr/bin/tail -n1 | /bin/sed 's/ | //' | /bin/sed 's/<\/td>/\n/' | /usr/bin/head -n1`
done
echo "Artist found!" >> /home/rick/playlist.log
echo "Searching for song title..." >> /home/rick/playlist.log
#-----Get the Song---------
song=`/bin/cat /home/rick/projects/radioPlaylist/savedPage.html | /bin/grep ">$h:$m $a" -A 1 | /usr/bin/tail -n1 | /bin/sed 's/D> | /\n/' | /usr/bin/tail -n1 | /bin/sed 's/<\/td>/\n/' | /usr/bin/head -n1`
echo "Song title found!" >> /home/rick/playlist.log
echo "Saving song information to file..." >> /home/rick/playlist.log
#------Save the artist and song------
date=`/bin/date +%m-%d-%Y` # det todays date so we can start a list for all songs found today
echo "$artist - $song" >> /media/radioLists/$date # save song in file
echo "Song info saved!" >> /home/rick/playlist.log
|