Hi guys,
I've written a simple command-line script to query tagchimp. You'll need a couple of easily available (under linux) tools: wget and xmlstarlet. Under Ubuntu this was as easy as
sudo apt-get install wget xmlstarletYou pass your search string as an argument on the command line and then you can select one of the resulting options, which gets saved to movietag.xml. Like this example (assuming that you've saved the script with the name "tagchimp")
tagchimp ratThis is the script. I've removed my tagchimp developer query ID, from the tcid variable.
CODE
#!/bin/bash
temp1=`mktemp`
temp2=`mktemp`
tcid=<queryid>
outfile=movietag.xml
# Get data from tagchimp
wget "https://www.tagchimp.com/ape/lookup.php?token=$tcid&type=search&title=$1&totalChapters=1" -O $temp1
# Turn ampersands into their escape character, for valid xml.
# Not sure if this is wget or the chimp's fault
sed -e "s/&/$amp;/g" $temp1 > $temp2
# Check for empty search
messagestr=`xmlstarlet sel -t -m "/items" -v "message" $temp2`
if [ "$messagestr" != "" ]; then
echo "Error: $messagestr"
rm -f $temp1 $temp2
exit 1
fi
# Collect up movie information
idstr=`xmlstarlet sel -t -m "/items/movie" -v "concat('"',movieID,'" ')" $temp2`
kindstr=`xmlstarlet sel -t -m "/items/movie/movieTags/info" -v "concat('"',kind,'" ')" $temp2`
titlestr=`xmlstarlet sel -t -m "/items/movie/movieTags/info" -v "concat('!!',movieTitle,'!! ')" $temp2`
showstr=`xmlstarlet sel -t -m "/items/movie/movieTags/television" -v "concat('"',showName,'" ')" $temp2`
i=0
eval set "$idstr"
for id in "$@"
do
idarr[$i]=$id
i=$(($i + 1))
done
i=0
eval set "$kindstr"
for kind in "$@"
do
kindarr[$i]="$kind"
i=$(($i + 1))
done
i=0
# Note that we used !! around titles, rather than double quotes, in case
# the strings contain double quotes. Fix it here.
titlestr=`echo $titlestr | sed -e 's/\\"/\\\\"/g; s/!!/\\"/g'`
eval set "$titlestr"
for title in "$@"
do
titlearr[$i]="$title"
i=$(($i + 1))
done
i=0
eval set "$showstr"
for show in "$@"
do
showarr[$i]="$show"
i=$(($i + 1))
done
for ((i=0;i<${#kindarr[*]};i++))
do
if [ "${showarr[$i]}" = "" ]; then
selectarr[$i]="${titlearr[$i]} (${kindarr[$i]})"
else
selectarr[$i]="${titlearr[$i]} (${kindarr[$i]} - ${showarr[$i]})"
fi
done
PS3="Choose a title: "
select title in "${selectarr[@]}"
do
[ "$title" = "" ] && echo "Bye!" && break
echo "You chose $title ($REPLY)"
echo "Output selection in $outfile"
xmlstarlet ed -d "/items/movie[movieID!=${idarr[$(($REPLY-1))]}]" $temp2 > $outfile
break
done
rm -f $temp1 $temp2
I want to query tagchimp to add chapter names to some of my movie files and fill in some details in my mythtv database, while using the tagchimp web interface to enter new data. I will hopefully follow this post up with a script to add chapter names to a Matroska file and modify the mythtv database from the movietag.xml file.
I'm no bash script expert, so I'd be glad to hear any advice on the script, although it does what I want it to do so far.