MythTV XBMC renamer development thread - outleradam - 2009-12-01 06:27
This development thread is obsolete please see this thread:
http://forum.xbmc.org/showthread.php?p=453344
This is something I've been working on tonight. I hope to have it operational soon. It will eventually rename episodes to Showname-SxxExx-(show title).XXX with only the showname and episode name from MythTv.
Usage: /user/home/Desktop/tv.sh "showname"
currently it will generate a file called "show name".txt which is the entire TVDB on the show and "show name".reduced.txt which contains only the pertinant information
Code:
#/bin/sh
#usage is as follows- tv.sh "show name" "episode name" eg. tv.sh "family guy"
apikey="3B81A89C73E4EE95"
#make series name friendly for URL usage
showname=`echo $1|replace " " "%20"`
#note the show for the log
echo "checking for show named" $1 "on TVDB.com" > output.log
echo "the episode name is" $2 >> output.log
#get seriesid from showname from TVDB
seriesid=`curl www.thetvdb.com/api/GetSeries.php?seriesname=$showname|grep "<seriesid>"`
#I was parsing the XML, i realized I didn't need to save the file.
#seriesid=`echo $seriesid|replace "> <" ">Ḃ<"`
#seriesid=`echo $seriesid|tr -s "Ḃ" "\n"|grep "<seriesid>"`
#remove XML tags
seriesid=`echo $seriesid|tr -d "<seriesid>"|tr -d "</seriesid>"`
echo "got series ID for $1 it is $seriesid" >>output.log
echo "now downloading show information for $1" >>output.log
#download series info for show
curl http://www.thetvdb.com/api/$apikey/series/$seriesid/all/en.xml > $showname.txt
cat $showname.txt|egrep "<EpisodeName>|<SeasonNumber>|<EpisodeNumber>">>$showname.reduced.txt
would anyone like to give me input? I'm learning bash
- outleradam - 2009-12-01 07:01
This version will output a file with showname Ex Sx
Code:
#/bin/sh
#usage is as follows- tv.sh "show name" "episode name" eg. tv.sh "family guy"
apikey="3B81A89C73E4EE95"
#make series name friendly for URL usage
showname=`echo $1|replace " " "%20"`
#note the show for the log
echo "checking for show named" $1 "on TVDB.com" > output.log
echo "the episode name is" $2 >> output.log
#get seriesid from showname from TVDB
seriesid=`curl www.thetvdb.com/api/GetSeries.php?seriesname=$showname|grep "<seriesid>"`
#I was parsing the XML, i realized I didn't need to save the file.
#seriesid=`echo $seriesid|replace "> <" ">Ḃ<"`
#seriesid=`echo $seriesid|tr -s "Ḃ" "\n"|grep "<seriesid>"`
#remove XML tags
seriesid=`echo $seriesid|tr -d "<seriesid>"|tr -d "</seriesid>"`
echo "got series ID for $1 it is $seriesid" >>output.log
echo "now downloading show information for $1" >>output.log
#download series info for show
#curl http://www.thetvdb.com/api/$apikey/series/$seriesid/all/en.xml > $showname.txt
#grab just the info we need
reduced=`cat $showname.txt|egrep "<EpisodeName>|<SeasonNumber>|<EpisodeNumber>"`
#remove HTML Tags
reduced=`echo $reduced|replace "</EpisodeNumber>" "" |replace "</SeasonNumber>" ""|replace "</EpisodeName>" ""`
reduced=`echo $reduced|replace "<EpisodeNumber>" "E"|replace "<SeasonNumber>" "S"|replace "<EpisodeName>" "Ḃ"`
echo $reduced
echo $reduced|tr -s " Ḃ" " \r" >$showname.reduced.txt
#tr Ḃ to enter
- outleradam - 2009-12-01 07:14
I could really use some help to rearrange the output from my program. It is currently generating a file like this:
snippet from output file family%20guy.reduced.txt
Code:
Season 4 DVD Extra - Outtakes E24 S0
Family Guy Presents: Seth and Alex's Almost Live Comedy Show E25 S0
Death has a Shadow E1 S1
I Never Met the Dead Man E2 S1
Chitty Chitty Death Bang E3 S1
Mind Over Murder E4 S1
A Hero Sits Next Door E5 S1
I need it to output 2 digits like: Sxx and Exx instead of Sx Ex
- outleradam - 2009-12-01 07:49
got double digits up and am now working on matching the showname to the Exx Sxx I don't know what I'm doing wrong on that..
Code:
#/bin/sh
#usage is as follows- tv.sh "show name" "episode name" eg. tv.sh "family guy"
apikey="3B81A89C73E4EE95"
#make series name friendly for URL usage
showname=`echo $1|replace " " "%20"`
#note the show for the log
echo "checking for show named" $1 "on TVDB.com" > output.log
echo "the episode name is" $2 >> output.log
#get seriesid from showname from TVDB
seriesid=`curl www.thetvdb.com/api/GetSeries.php?seriesname=$showname|grep "<seriesid>"`
#I was parsing the XML, i realized I didn't need to save the file.
#seriesid=`echo $seriesid|replace "> <" ">Ḃ<"`
#seriesid=`echo $seriesid|tr -s "Ḃ" "\n"|grep "<seriesid>"`
#remove XML tags
seriesid=`echo $seriesid|tr -d "<seriesid>"|tr -d "</seriesid>"`
echo "got series ID for $1 it is $seriesid" >>output.log
echo "now downloading show information for $1" >>output.log
#download series info for show
curl http://www.thetvdb.com/api/$apikey/series/$seriesid/all/en.xml > $showname.txt
#grab just the info we need
echo "removing useless info and creating new file">>output.txt
reduced=`cat $showname.txt|egrep "<EpisodeName>|<SeasonNumber>|<EpisodeNumber>"`
#remove XML Tags
echo "converting from XML">>output.txt
reduced=`echo $reduced|replace "</EpisodeNumber>" "" |replace "</SeasonNumber>" ""|replace "</EpisodeName>" "-"`
#remove tags, replace with S and E, Ḃ is a special charactor as a placeholder to change to a breakreturn at a later time.
reduced=`echo $reduced|replace "<EpisodeNumber>" "E"|replace "<SeasonNumber>" "S"|replace "<EpisodeName>" "Ḃ"`
#remove single digit Sxx Exx
echo "creating double digit numbers">>output.txt
reduced=`echo $reduced|replace "S0 " "S00"|replace "S1 " "S01"|replace "S2 " "S02"|replace "S3 " "S03"|replace "S4 " "S04"|replace "S5 " "S05"|replace "S6 " "S06"|replace "S7 " "S07"|replace "S8 " "S08"|replace "S9 " "S09"|replace "E0 " "E00 "|replace "E1 " "E01 "|replace "E2 " "E02 "|replace "E3 " "E03 "|replace "E4 " "E04 "|replace "E5 " "E05 "|replace "E6 " "E06 "|replace "E7 " "E07 "|replace "E8 " "E08 "|replace "E9 " "E09 "`
#output the reduced file as "showname - Exx Sxx"
echo $reduced|tr -s " Ḃ" " \r" >$showname.reduced.txt
#to do: get $2 input and grep through the file for the new file name
#replace file name with new file name
echo $showname
#namefile=`grep "$2" $showname.reduced.txt`
#echo $namefile
to do:
make it thetvdb friendly
get output from file
write XBMC regex ohgod i hope xexe will help me.
... future: add alternate lookup by date and other search engines.
- theophile - 2009-12-01 21:12
I've put together a script that takes as its argument the show name and episode name, then it queries the MythTV database for the stored file name, runs a custom command on that file (usually commercial cutting and transcoding), then places the output file in my XBMC TV shows directory and a supdirectory based on the show name, and names the output file "Show.SxxExx.Episode.mkv". It queries TVDB based on the episode's original airdate to determine the season and episode numbers.
You can check it out here:
http://monopedilos.com/dokuwiki/doku.php?id=hdpvrcutter.pl
- outleradam - 2009-12-02 07:11
MWhy didn't you post that with better directions earlier? I went looking for instructions all over and I could not figure out how to use that. I programmed my own because your instructions are so vauge. What package are those dependencies in? I still can't figure out how to use that program.
Here's my script. It does not have handling yet. It works though. Just need to bypass things on errors.
Code:
#/bin/sh
#usage is as follows- tv.sh "show name" "episode name" eg. tv.sh "South Park" "Here Comes the Neighborhood"
#This file depends on Curl install curl with "apt-get install curl"
apikey="3B81A89C73E4EE95"
#make series name friendly for URL usage
showname=`echo $1|replace " " "%20"`
#note the show for the log
echo "checking for show named" $1 "on TVDB.com" >> output.log
echo "the episode name is" $2 >> output.log
#get seriesid from showname from TVDB
seriesid=`curl -s www.thetvdb.com/api/GetSeries.php?seriesname=$showname|grep "<seriesid>"`
#remove XML tags
seriesid=`echo $seriesid|tr -d "<seriesid>"|tr -d "</seriesid>"`
#####TODO if $seriesid = "" then exit 0 fi
echo "got series ID for $1 it is $seriesid">>output.log
echo "now downloading show information for $seriesid">>output.log
###TODO this section will be skipped if our db is up to date
#download series info for show
echo creating $showname/$showname.txt>>output.log
curl -s http://www.thetvdb.com/api/$apikey/series/$seriesid/all/en.xml > $showname/$showname.txt
#make a episode name file
cat $showname/$showname.txt | grep "<EpisodeName>"|replace "<EpisodeName>" ""|replace "</EpisodeName>" "">$showname/$showname.Ename.txt
#make a season number file
cat $showname/$showname.txt | grep "<SeasonNumber>"|replace "<SeasonNumber>" ""|replace "</SeasonNumber>" "">|replace " " "">$showname/$showname.S.txt
#make a episode number file
cat $showname/$showname.txt | grep "<EpisodeNumber>"|replace "<EpisodeNumber>" ""|replace "</EpisodeNumber>" ""|replace " " "">$showname/$showname.E.txt
#find the $2 userinput in the episode name file, output only the line number
linenumber=`grep -nm 1 "$2" $showname/$showname.Ename.txt| sed 's/:.*//'`
#add a p for use with sed
linenumber=$linenumber"p"
#gather series and episode names from files created earlier and define epn/shn while we're at it.
exx=`sed -n $linenumber $showname/$showname.E.txt`
sxx=`sed -n $linenumber $showname/$showname.S.txt`
epn=$2
shn=$1
# make names Exx and Sxx not just Ex Sx
if [ "$exx" -lt 10 ]
then exx=`echo E0$exx`
elif [ $exx > 9 ]
then exx=`echo E$exx`
fi
if [ "$sxx" -lt 10 ]
then sxx=`echo S0$sxx`
elif [ $sxx > 9 ]
then exx=`echo S$sxx`
fi
#output format shn=showname sxx=seasonnumber exx=episodenumber epn=episodename
echo got episode information: $shn - $sxx$exx "($epn)" >> output.log
echo $shn - $sxx$exx "($epn)"
It works with curl. All that's left is error handling and making it a plugin for the official tvrenamer script included with myth.
- theophile - 2009-12-02 22:43
outleradam Wrote:MWhy didn't you post that with better directions earlier? I went looking for instructions all over and I could not figure out how to use that. I programmed my own because your instructions are so vauge. What package are those dependencies in? I still can't figure out how to use that program.
I provided much more detailed instructions than 9 out of 10 bash/perl/pythin scripts on the net. As for packages, I don't know what distro you are using and chances are that if you don't know how to find and install software on your own distro, you're probably not going to be able to use it anyway. So all that to say, you're welcome and best of luck.
- outleradam - 2009-12-03 02:11
theophile Wrote:I provided much more detailed instructions than 9 out of 10 bash/perl/pythin scripts on the net.
No, most scripts list dependencies as you can install them. You should just put in full directions for a person to use your software. You should also list information about the OS required to install it otherwise people like me, last week, come along and look at it like WTF? Me after 4 hours screwing with it: "This guy admitted not knowing how to program.. why did I waste my time working with this script if I knew it was not going to work in the first place." Your program did do something. I just can't tell what it was. I gave it the information, and it rearranged my files. Your program moved my files around, but did not get the information.
Quote:As for packages, I don't know what distro you are using
Ubuntu 9.11
Quote:and chances are that if you don't know how to find and install software on your own distro
Sure I do... full installation instructions are to follow...
Bash installation $>
1. type sudo apt-get install curl (run through the installation)
2. copy the program to any folder of your choosing and which your myth user name has rights to read and write to files, this is because BashSxxExx will maintain it's own text-file database for quick reference.
3. ****Implementation into mythrename is not complete yet.***
Quote: you're probably not going to be able to use it anyway. So all that to say, you're welcome and best of luck.
Why am I not going to be able to use it? Thank you.
For those of you watching or waiting for this project, The above will output a name, but only if it is absolutely correct. My latest work now has that corrected, however if you type 'the' as the showname it will recognize all shows that come up with 'the'. so my todo list before this is "ready" is the following.
I'm going to have it go through and download every XML for the returned SID returned by theTvDb until it obtains an exact match.
I'm currently working on a database maintenance routine which will avoid excessive downloading unless theTvDb has updated that particular show
Also in the works soon to come: a separate text file which will look for specific names from your tvguide and rename them for theTvDb: IE. Aqua Teen Hungerforce = Aqua Teen Hunger Force.
The official name for this project is BashSExx
- outleradam - 2009-12-03 03:08
sigh, i've been troubleshooting my program because it was not working and then I realized that theTvDb.com is down right now. That is note worthy as a log note on a failure.
got some work done in the right direction, however, thetvdb is down right now so there's alot of errors
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"
#
#
#
#
#
#If the API key does not work you can Register for a new API key on www.TheTvDb.com
#
#Dependencies:file depends on "Curl" install curl with "apt-get install curl"
apikey="3B81A89C73E4EE95"
timeout=4
################Do not modify below this line########################
#Set epn and shn from the input parameters
if [ "$1" = -v ]
then epn=$2 |option=1 echo "-v $epn $shn"|shn=$3
elif [ "$1" = -m ]
then epn=$2|option = 2|echo "-m $epn $shn"|shn=$3
fi
if [ "$1" != -v ]
then epn=$3|shn=$2|echo no options|echo $ep $shn
fi
#todo reference BashSExx.config file for name changes
#epn = cat grep
#change series name to one which is friendly for URL usage
showname=`echo $shn|replace " " "%20"`
#note the show for the log
echo "checking for show named" $shn "on TVDB.com the episode name is" $3 >> output.log
#send show name and get series id from TVDB
seriesid=`curl -s -m$timeout www.thetvdb.com/api/GetSeries.php?seriesname=$showname|grep -m 1 "<seriesid>"`
#if1 jump to near end of program if no series id obtained
if [ "$seriesid" != "" ]; then
#debug line
echo "series id is not blank"
#remove XML tags
seriesid=`echo $seriesid|tr -d "<seriesid>"|tr -d "</seriesid>"`
echo "got series ID for $2 now downloading show information">>output.log
###TODO this section will be skipped if our db is up to date
#download series info for show
echo creating $showname/$showname.txt>>output.log
curl -s -m$timeout http://www.thetvdb.com/api/$apikey/series/$seriesid/all/en.xml > $showname/$showname.txt
#create a folder/file "database" Strip XML tags. Series, Exx and Sxx are separated into different files
cat $showname/$showname.txt | grep "<EpisodeName>"|replace "<EpisodeName>" ""|replace "</EpisodeName>" "">$showname/$showname.Ename.txt
cat $showname/$showname.txt | grep "<SeasonNumber>"|replace "<SeasonNumber>" ""|replace "</SeasonNumber>" "">|replace " " "">$showname/
cat $showname/$showname.txt | grep "<EpisodeNumber>"|replace "<EpisodeNumber>" ""|replace "</EpisodeNumber>" ""|replace " " "">$showname/$showname.E.txt
#debug line
echo "show parsed"
#grep the episode name in the episode name list, output only the line number
linenumber=`grep -nm 1 "$epn" $showname/$showname.Ename.txt| sed 's/:.*//'`
#if2 exit if no line match
if [ $linenumber != "" ]; then
#add a 'p' after the line number for use with sed.
linenumber=$linenumber"p"
#gather series and episode names from files created earlier.
exx=`sed -n $linenumber $showname/$showname.E.txt`
sxx=`sed -n $linenumber $showname/$showname.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 > 9 ]
then exx=`echo E$exx`
fi
if [ "$sxx" -lt 10 ]
then sxx=`echo S0$sxx`
elif [ $sxx > 9 ]
then exx=`echo S$sxx`
fi
#debug line
echo "finished processing"
#if2 exit point
fi
#debug line
echo endif2
#if1 exit point
elif [ "$seriesid" = "" ]
then echo "series was not found the tvdb may be down" >> output.log
fi
#debug line
echo endif1
#output format shn=showname sxx=seasonnumber exx=episodenumber epn=episodename
echo got episode information: $shn - $sxx$exx "($epn)" >> output.log
#output name -v = verbose, -m = myth mode
if [ "$1" = "-v" ]
then echo $shn - $sxx$exx "($epn)"|replace "%20" " "
elif [ "$1" = "-m" ]
then echo $sxx$exx
else echo $sxx$exx
fi
- theophile - 2009-12-03 06:28
outleradam Wrote:No, most scripts list dependencies as you can install them. You should just put in full directions for a person to use your software. You should also list information about the OS required to install it otherwise people like me, last week, come along and look at it like WTF? Me after 4 hours screwing with it: "This guy admitted not knowing how to program.. why did I waste my time working with this script if I knew it was not going to work in the first place." Your program did do something. I just can't tell what it was. I gave it the information, and it rearranged my files. Your program moved my files around, but did not get the information.
It's a perl script. There are two ways to tell. The first is that it has a .pl extension. The second is that the first line of the script tells you as much. It's OS-agnostic as long as you have a perl interpreter on your system. Since MythTV is a Linux project, I felt it was unnecessary to specify that it was written on Linux. I specified what the dependencies are. Short of giving you the apt-get lines, I don't see what more you could want. You should be able to figure out how to install mythtv, avidemux, and a perl module.
As for what it does, my intial post in this thread explained what the script does. The first paragraph on the wiki explains what it does. Moreover, you can see the entire script. Again, what do you want? This script has been posted on this forum before and has been posted on the MythTV mailing list for 6 months and no one has ever complained before.
I don't know what your problem is, but try to be a little less of a douchebag when someone offers you something.
|