MythTV XBMC renamer.
#31
^^ 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"
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.
Use mythicalLibrarian to make a library out of your MythTV files. Leave the recording to MythTV and use XBMC as your library.
Installation and Instructions:http://wiki.xbmc.org/index.php?title=MythicalLibrarian
Technical Support:http://forum.xbmc.org/showthread.php?tid=65644
[url=http://forum.xda-developers.com/showthread.php?tid=1081892][/url]
Reply
#32
This will be my final posting of this project in here. I will still answer any questions or issues which are brought up in here, but I will now move this project from alpha to beta/maintenance phase and starting a new thread tomorrow after I clean up the code. It is operating properly and can be run as a myth job

BashSExx "show name" "episode name" "original location" "foldername/filename"
it will move the file to the location which you desire and it will rename it showname - SxxExx (episode name).ext
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  "/home/$YourUsername/BashSExx"
BashSExx=~/BashSExx
#The following line is the folder which BashSExx will move the file.  NO trailing "/" eg. "~/videos"
movedir="/mnt/NAS/Video/shows"
#The following line tells BashSExx to use the
useshownameasfolder=enabled




##############################################################
################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
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
originalext=${3##*.}
originaldirname=`dirname "$3"`
#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


#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
#if fail over mode
    if [ -f "$BashSExx/$newshowname/$newshowname.xml" ]; then
        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
    fi
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 ******">>$BashSExx/output.log
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
#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#####
#output format  showname=show name sxx=season number exx=episode number epn=episode name
if [ "$exx" != "" ]; then
    if [ -d $movedir ]; then
        echo EPISODE INFORMATION: "$newshowname $epn = $sxx$exx">>$BashSExx/output.log
        echo "$movedir/$newshowname - $sxx$exx ($epn).$originalext"
        if [ "$useshownameasfolder" = "enabled" ]; then
            if [ -d "$movedir/$showname" ]; then
                echo "VERIFIED FOLDER: $movedir/$newshowname">>$BashSExx/output.log
            elif [ ! -d "$movedir/$newshowname" ]; then
                echo "CREATING: FOLDER $movedir/$newshowname">>$BashSExx/output.log
                mkdir "$movedir/$newshowname"
            fi        
            echo "RENAMING AND MOVING $3 TO DESTINATION: $movedir/$newshowname - $sxx$exx ($epn).$originalext">>$BashSExx/output.log
            mv "$3" "$movedir/$newshowname/$newshowname - $sxx$exx ($epn).$originalext"


echo "woot $originaldirname/$newshowname/$newshowname - $sxx$exx ($epn).$originalext"
        elif [ "$useshownameasfolder" = "disabled" ]; then
            echo "RENAMING AND MOVING $3 TO DESTINATION: $movedir/$newshowname - $sxx$exx ($epn).$originalext">>$BashSExx/output.log
            mv "$3" "$movedir/$newshowname - $sxx$exx ($epn)"."$originalext">>$BashSExx/output.log
            echo "$3" "$movedir/$newshowname - $sxx$exx ($epn)"."$originalext">>$BashSExx/output.log
        fi
    elif [ ! -d $movedir ]; then
        echo "OUTPUT FOLDER $movedir DOES NOT EXIST">>$BashSExx/output.log
    fi
elif [ "$exx" = "" ]; then
    echo "NO MATCH FOUND.  TROUBLESHOOTING: CHECK INTERNET CONNECTION, CHECK API KEY, CHECK FOLDER PERMISSIONS">>$BashSExx/output.log
    echo "CHECK www.TheTvDb.com  RUN BashSExx FROM COMMAND PROMPT. FOR MORE INFORMATION SEE WWW.HOSTURL.COM/MYSCRIPT.">>$BashSExx/output.log
fi
Use mythicalLibrarian to make a library out of your MythTV files. Leave the recording to MythTV and use XBMC as your library.
Installation and Instructions:http://wiki.xbmc.org/index.php?title=MythicalLibrarian
Technical Support:http://forum.xbmc.org/showthread.php?tid=65644
[url=http://forum.xda-developers.com/showthread.php?tid=1081892][/url]
Reply
#33
Development phase is over. Maintenace phase thread is here http://forum.xbmc.org/showthread.php?p=453344
Use mythicalLibrarian to make a library out of your MythTV files. Leave the recording to MythTV and use XBMC as your library.
Installation and Instructions:http://wiki.xbmc.org/index.php?title=MythicalLibrarian
Technical Support:http://forum.xbmc.org/showthread.php?tid=65644
[url=http://forum.xda-developers.com/showthread.php?tid=1081892][/url]
Reply
#34
heh... I was just looking at this thread again... If anyone was following this. mythicalLibrarian is out.. http://mythicallibrarian.googlecode.com/...lLibrarian

Also, I think this may be a contender for a longest bash script ever record.
Use mythicalLibrarian to make a library out of your MythTV files. Leave the recording to MythTV and use XBMC as your library.
Installation and Instructions:http://wiki.xbmc.org/index.php?title=MythicalLibrarian
Technical Support:http://forum.xbmc.org/showthread.php?tid=65644
[url=http://forum.xda-developers.com/showthread.php?tid=1081892][/url]
Reply

Logout Mark Read Team Forum Stats Members Help
MythTV XBMC renamer.0