Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Bash Script For Tagchimp Queries
Guest_bigtoedsloth_*
post Jun 26 2008, 06:37 AM
Post #1





Guests






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 xmlstarlet

You 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 rat

This 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('&quot;',movieID,'&quot; ')" $temp2`
kindstr=`xmlstarlet sel -t -m "/items/movie/movieTags/info" -v "concat('&quot;',kind,'&quot; ')" $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('&quot;',showName,'&quot; ')" $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.
Go to the top of the page
 
+Quote Post
tim
post Jun 26 2008, 09:22 AM
Post #2


Administrator
***

Group: Root Admin
Posts: 313
Joined: 9-April 08
Member No.: 1



QUOTE (bigtoedsloth @ Jun 26 2008, 08:37 AM) *
# 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

This is tagChimp. I haven't properly escaped the XML yet as MetaX chokes on the < > symbols. I sent an email the Rodney (MetaX developer). That will probably be in there when he releases the next version.

To be fair to Rodney, I didn't escape the XML on my end (tagChimp), so he/we never tested it in MetaX. This is my goof.


--------------------
Go to the top of the page
 
+Quote Post
BigToedSloth
post Jun 26 2008, 10:53 PM
Post #3


Newbie
*

Group: Members
Posts: 4
Joined: 26-June 08
From: Adelaide, Australia
Member No.: 38



That's a typo by me! That line should be
CODE
sed -e "s/&/&amp;/g" $temp1 > $temp2
I think ...
Go to the top of the page
 
+Quote Post
veysey
post Nov 22 2009, 07:48 AM
Post #4


Newbie
*

Group: Members
Posts: 1
Joined: 22-November 09
Member No.: 398



QUOTE (BigToedSloth @ Jun 26 2008, 11:53 PM) *
That's a typo by me! That line should be
CODE
sed -e "s/&/&amp;/g" $temp1 > $temp2
I think ...


At the risk of making a seriously zombi-fied thread ... BigToe: Did you ever get around to making that matroska chapter name script?

With what you've done here, it looks like it would be fairly straightforward. So much so, I will do it at somepoint. Need some heuristics for dealing with tagchimp movies that have multiple names for each chapter. Unfortunately, although matroska can handle the other metadata, there are no established conventions ...

Will post back my script to the thread if I can make it work. And if I don't give up and move to mp4 and use metaX!

Cheers and nice job with this script. Works well.
Go to the top of the page
 
+Quote Post
Munger
post Feb 1 2010, 04:04 PM
Post #5


Newbie
*

Group: Members
Posts: 2
Joined: 1-February 10
Member No.: 548



I tried this script, but it fails, presumably because I don't have a tagchimp developer id. I'm currently working on a few scripts to query a local mirror of the imdb IMDB database, which is 1000 times faster than querying over the web. I would register as a developer, but I don't have a public website and won't have one in the foreseeable future.
Go to the top of the page
 
+Quote Post
tim
post Feb 2 2010, 10:06 AM
Post #6


Administrator
***

Group: Root Admin
Posts: 313
Joined: 9-April 08
Member No.: 1



QUOTE (Munger @ Feb 1 2010, 05:04 PM) *
I tried this script, but it fails, presumably because I don't have a tagchimp developer id. I'm currently working on a few scripts to query a local mirror of the imdb IMDB database, which is 1000 times faster than querying over the web. I would register as a developer, but I don't have a public website and won't have one in the foreseeable future.

If the author of the script is distributing the script, they can/should distribute it with their tagChimp token, that's what all the other apps do. Yes, the tokens aren't visible, but that's okay, because the token is only used for lookups.

Tim


--------------------
Go to the top of the page
 
+Quote Post
Munger
post Feb 4 2010, 04:04 PM
Post #7


Newbie
*

Group: Members
Posts: 2
Joined: 1-February 10
Member No.: 548



QUOTE (tim @ Feb 2 2010, 04:06 PM) *
If the author of the script is distributing the script, they can/should distribute it with their tagChimp token, that's what all the other apps do. Yes, the tokens aren't visible, but that's okay, because the token is only used for lookups.

Tim


So there is no way to register as a developer without a web site? I could of course put up a placeholder, but I normally don't do the developer website thing for various contractual reasons.

Tim (Yes, that's my name too :-)
Go to the top of the page
 
+Quote Post
tim
post Feb 4 2010, 05:39 PM
Post #8


Administrator
***

Group: Root Admin
Posts: 313
Joined: 9-April 08
Member No.: 1



QUOTE (Munger @ Feb 4 2010, 05:04 PM) *
So there is no way to register as a developer without a web site? I could of course put up a placeholder, but I normally don't do the developer website thing for various contractual reasons.

Tim (Yes, that's my name too :-)

Shoot me an email at support at tagChimp dot com.

Tim


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 

Lo-Fi Version Time is now: 8th September 2010 - 09:07 AM