2009-12-06, 02:04
^^ thanks
Added in a translation function. To activate translations, a file should be put in the BashSExx working directory called "showtranslations" In that file you can put
"your showname = TVDB show name"
This should eliminate almost all translation errors. showtranslations allows 100% accuracy in show name translation especially when your cable company abbreviates "who wants to be a millionaire" to "millionaire" or does not use the official name, or when a series like battlestar gallactica is brought back. Again, showtranslations is only activated if you specify it to be activated by creating a file and adding the translations.
The heart of the program is complete. It maintains it's own local database and uses fuzzy logic to find show names.
The final touch is the ability to rename files
I was reading that you can move files around in different mythtv recording folders and myth will still recognize the file. Now I just need to come up with a way to change the name of the file in the database.
Added in a translation function. To activate translations, a file should be put in the BashSExx working directory called "showtranslations" In that file you can put
"your showname = TVDB show name"
Code:
Myth TV's recorded name = www.thetvdb.com's official name
Battlestar Galactica = Battlestar Galactica (1978)
Aqua Teen Hungerforce= Aqua Teen Hunger Force
Millionaire = Who Wants to be a Millionaire
Football = gay shit
This should eliminate almost all translation errors. showtranslations allows 100% accuracy in show name translation especially when your cable company abbreviates "who wants to be a millionaire" to "millionaire" or does not use the official name, or when a series like battlestar gallactica is brought back. Again, showtranslations is only activated if you specify it to be activated by creating a file and adding the translations.
The heart of the program is complete. It maintains it's own local database and uses fuzzy logic to find show names.
The final touch is the ability to rename files
Code:
#/bin/sh
#BashSExx by Adam Outler
#
#usage is as follows- BashSExx.sh -v "show name" "episode name"
# eg. BashSExx.sh "South Park" "Here Comes the Neighborhood"
#
#
#
#Log file will show information for troubleshooting. You can find the log file in the working folder
#Default: /home/$username/BashSExx
#If the API key does not work you can Register for a new API key on www.TheTvDb.com
#
#Dependencies: depends on "Curl" and "agrep"
#install curl with "apt-get install curl"
#install agrep with "apt-get install agrep"
#Settings:
#the following line contains the API key from www.TheTvDb.Com: get a new one http://thetvdb.com/?tab=apiregister
apikey="3B81A89C73E4EE95"
#The following line is the internet access timeout in seconds: Default timeout=50
timeout=50
#The following line is the BashSExx txt file Database folder: BashSExx=BashSExx "~/BashSExx"
BashSExx=~/BashSExx
####################################################
###########Do not modify below this line############
####################################################
echo "@@@@@@@@@@NEW SEARCH INITIATED AT `date`@@@@@@@@@@@@@">$BashSExx/output.log
#####DEFINE ENVIRONMENT AND VARIABLES#####
#make our home dir if it does not exist and go to it
if [ ! -d "$BashSExx" ]; then
mkdir $BashSExx
echo "creating home/BashSExx and log file">>$BashSExx/output.log
fi
#Set epn and shn from the input parameters
showname=$1
epn=$2
#check for show translations relating to the show in question
if [ -f $BashSExx/showtranslations ]; then
showtranslation=`grep "$showname = " "$BashSExx/showtranslations"|replace "$showname = " ""|replace "$Bashsexx/showtranslations" ""`
if [ "$showtranslation" != "$null" ];then
showname=$showtranslation
echo "USER TRANSLATION: $showname = $shownametranslation">>$BashSExx/output.log
fi
fi
#####SEARCH FOR SHOW NAME#####
echo "SEARCHING: www.TheTvDb.com SHOW NAME: $showname EPISODE: $epn">>$BashSExx/output.log
#download series info for show, parse into temporary text db- sid.txt shn.txt
tvdbshowname=`echo $showname|replace " " "%20"`
echo $tvdbshowname
curl -s -m"$timeout" www.thetvdb.com/api/GetSeries.php?seriesname=$tvdbshowname>$BashSExx/working.xml
cat $BashSExx/working.xml | grep "<seriesid>"|replace "<seriesid>" ""|replace "</seriesid>" "">$BashSExx/sid.txt
cat $BashSExx/working.xml | grep "<SeriesName>"|replace "<SeriesName>" ""|replace "</SeriesName>" "">$BashSExx/shn.txt
#use fuzzy logic to make the best match of the show name
serieslinenumber=`agrep -Byn "${showname:0:29}" $BashSExx/shn.txt|grep -m1 ^|sed 's/:.*//'`
#get the seriesid based on the showname
seriesid=`sed -n $serieslinenumber'p' $BashSExx/sid.txt`
newshowname=`sed -n $serieslinenumber'p' $BashSExx/shn.txt`
#Create folder for show if it does not exist
if [ ! -d "$BashSExx/$newshowname" ]; then
mkdir $BashSExx/"$newshowname"
echo "creating home BashSExx and log file">>BashSExx/output.log
fi
#debug line
echo "SEARCH FOUND:""$newshowname" "ID#:" $seriesid >>/$BashSExx/output.log
#check for valid entry in series id
if [ "$serieslinenumber" != "" ]; then
#add a 'p' after the line number for use with sed.
serieslinenumber=$serieslinenumber"p"
#fi
#create a folder/file "database" Strip XML tags. Series, Exx and Sxx are separated into different files
#if1 Series id is not blank so continue
#if [ "$seriesid" != "" ]; then
#remove XML tags
seriesid=`echo $seriesid|tr -d "<seriesid>"|tr -d "</seriesid>"`
###TODO this section will be skipped if our db is up to date
###need to save first xml to $BashSExx working dir for reference
### while I'm at it, split the db into a list of names and showids, then get correct name based on show id.
### a show id log generator would be nice.
###if last db update time is newer then our last update, then delete show and get new db
###get current tvdb time and save to $BashSExx/"$newshowname"/time
#download series info for show
curl -s -m"$timeout" http://www.thetvdb.com/api/$apikey/series/$seriesid/all/en.xml>$BashSExx/"$newshowname"/"$newshowname".xml
#create a folder/file "database" Strip XML tags. Series, Exx and Sxx are separated into different files
cat $BashSExx/"$newshowname"/"$newshowname".xml | grep "<EpisodeName>"|replace " <EpisodeName>" ""|replace "</EpisodeName>" "">$BashSExx/"$newshowname"/"$newshowname".Ename.txt
cat $BashSExx/"$newshowname"/"$newshowname".xml | grep "<SeasonNumber>"|replace "<SeasonNumber>" ""|replace "</SeasonNumber>" ""|replace " " "">$BashSExx/"$newshowname"/"$newshowname".S.txt
cat $BashSExx/"$newshowname"/"$newshowname".xml | grep "<EpisodeNumber>"|replace "<EpisodeNumber>" ""|replace "</EpisodeNumber>" ""|replace " " "">$BashSExx/"$newshowname"/"$newshowname".E.txt
if [ -f $BashSExx/"$newshowname"/"$newshowname".Ename.txt ]; then
echo "SHOW PARSED TO:$BashSExx/"$newshowname"/"
echo "LOCAL DATABASE UPDATED:$BashSExx/"$newshowname"/">>$BashSExx/output.log
elif [ != -f $BashSExx/"$newshowname"/"$newshowname".Ename.txt ]; then
echo "***** PERMISSION ERROR ******"
fi
#debug line
#grep use fuzzy logic to find the closest show name from the locally created database and return absolute episode number
absolouteEpisodeNumber=`agrep -Byn "${epn:0:29}" $BashSExx/"$newshowname"/"$newshowname".Ename.txt|grep -m1 ^|sed 's/:.*//'`
echo DEFINED ABSOLOUTE EPISODE NUMBER: $absolouteEpisodeNumber>>/$BashSExx/output.log
#if2: if line match is obtained, then continue
if [ "$absolouteEpisodeNumber" != "" ]; then
epn=`sed -n $absolouteEpisodeNumber'p' $BashSExx/"$newshowname"/"$newshowname".Ename.txt`
echo "Found Match: $epn $absolouteEpisodeNumber"
#gather series and episode names from files created earlier.
exx=`sed -n $absolouteEpisodeNumber'p' $BashSExx/"$newshowname"/"$newshowname".E.txt`
sxx=`sed -n $absolouteEpisodeNumber'p' $BashSExx/"$newshowname"/"$newshowname".S.txt`
# Single digit episode and show names are not allowed Ex and Sx replaced with Exx Sxx
if [ "$exx" -lt 10 ]; then
exx=`echo E0$exx`
elif [ "$exx" -gt 9 ]; then
exx=`echo E$exx`
fi
if [ "$sxx" -lt 10 ]; then
sxx=`echo S0$sxx`
elif [ "$sxx" -gt 9 ]; then
sxx=`echo S$sxx`
fi
#debug line
#if2 exit point
fi
#if1 exit point
elif [ "$seriesid" == "" ]; then
echo "series was not found the tvdb may be down try renaming $1">>$BashSExx/output.log
fi
#output format showname=showname sxx=seasonnumber exx=episodenumber epn=episodename
echo EPISODE INFORMATION: "$newshowname" - $sxx$exx "($epn)">> $BashSExx/output.log
echo $sxx$exx
I was reading that you can move files around in different mythtv recording folders and myth will still recognize the file. Now I just need to come up with a way to change the name of the file in the database.