adabas - a very simple linux shell script

misc client related stuff

Moderators: AniDB, AniDB API

Locked
exhuma.twn
Posts: 3
Joined: Fri Jan 07, 2005 1:11 pm
Contact:

adabas - a very simple linux shell script

Post by exhuma.twn »

This shell script uses a file containing ed2k-hashes as input and interfaces with anidb.pl using curl.

The parameter parsing is pretty simple and unflexible. It expects the exact number of parameters, and it's not possible to swap them around or leave some out. When writing this I was in a bit of a hurry. But at least it's working :)

Hope I can inspire some scripting-gurus to improve it. Yep. If you want, take it, improve it as much as you want... but please give me _some_ credit ;)

For those that need to know. Copy the source code posted below, paste it into a new file, save it and make it executable. Easiest way in the shell is by typing

Code: Select all

chmod a+x adabas
.

If you execute the script with not enough parameter (i.e. none) you get the help message displayed. I was too lazy to get into "getopt" ;)

This script is still less handy than using ed2kdump directly from the web, but it gives you some scripting possibilities for automation :)

Happy scripting... and here's the code:

Code: Select all

#!/bin/sh
#
# adabas -- a linux shell script for submitting files to the "mylist" at anidb.net
# v 1.0
# Author: Michel Albert (exhuma.twn)
# Thanks to pelican and hhaamu for some perl help
# 
#

# check we have the right number of parameters
if [ $# != 8 ]
then
   echo "Usage:"
   echo "$0 <login> <password> <viewed> <state> <source> <storage> <comment> <hashlist>"
   echo "============================"
   echo "Make sure that strings containing spaces need to be enclosed in quotes!"
   echo
   echo "login    - your anidb login"
   echo "password - your anidb passwd"
   echo "viewed   - 1/0"
   echo "state    - integer 0-5"
   echo "         | 0 = unknown"
   echo "         | 1 = on hdd"
   echo "         | 2 = on cd"
   echo "         | 3 = deleted"
   echo "         | 4 = shared"
   echo "         | 5 = release"
   echo "source   - as on anidb *"
   echo "storage  - as on anidb *"
   echo "comment  - as on anidb *"
   echo "hashlist - a file containing all hashes (it can be created using 'ed2k_hash > filename'"
   echo
   echo "* Remember the quotes!"
   exit 0
fi

#get the login
LOGIN=$1 && shift 1

#get the password
PASSWORD=$1 && shift 1

#get viewed
VIEWED=$1 && shift 1

#get state
STATE=$1 && shift 1

#get source
SOURCE=$1 && shift 1

#get storage
STORAGE=$1 && shift 1

#get comment
COMMENT=$1 && shift 1

#get filename(s)
FILENAME=$1 && shift 1

# thanks to pelican for the first perl bit and hhaamu for the second :)
# this properly encodes each line in the file, and then replaces newlines by %0A
INPUT=`cat $FILENAME | perl -p -e 's![]%/?#\\&<>[^'"'"'{|}~\1-\40\177-\377]!"%" . sprintf("%02X",ord($&))!eg' | perl -p -e 's/\n/%0A/' | sed -e 's/%0A$//'`

# first curl invocation. Here we log in and store the cookie for later
echo "* Logging in..."
curl \
   -D anidb_headers_and_cookies \
   -c newCookies.txt \
   -d "show=main&xuser=${LOGIN}&xpass=${PASSWORD}&xdoautologin=on" \
   http://anidb.ath.cx/perl-bin/animedb.pl \
   &> /dev/null
                
# Now it's time to submit the data using the data specified in the command line
echo "* Submitting data..."
curl \
 -b anidb_headers_and_cookies \
 -c newCookies.txt \
 -d "show=ed2kdump&ed2kdump.viewed=${VIEWED}&ed2kdump.state=${STATE}&ed2kdump.source=${SOURCE}&ed2kdump.storage=${STORAGE}&ed2kdump.comment=${COMMENT}&ed2kdump=${INPUT}" \
 http://anidb.ath.cx/perl-bin/animedb.pl \
 &> /dev/null

# Here are the bits of the ed2kdump form that are important (for reference)
#
#<select name="ed2kdump.viewed" size=1>
#   <option value=0 selected> unwatched
#   <option value=1> watched
#
#State:
#<select name="ed2kdump.state" size=1>
#   <option value="0" selected> unknown
#   <option value="1"> on hdd
#   <option value="2"> on cd
#   <option value="3"> deleted
#   <option value="4"> shared
#   <option value="5"> release
#
#Source:
#   <input type="text" name="ed2kdump.source" size="30" maxlength="100">
#
#Storage:
#   <input type="text" name="ed2kdump.storage" size="30" maxlength="100">
#
#Comment:
#   <textarea name="ed2kdump.other" cols=25 rows=4></textarea>
#
#       <input type="submit" name="ed2kdump.do" value=" ADD "> - <input type="submit" name="ed2kdump.identify" value=" IDENTIFY ">

exhuma.twn
Posts: 3
Joined: Fri Jan 07, 2005 1:11 pm
Contact:

Post by exhuma.twn »

Oh... btw.
If you do improve this script, it would be nice to post the changes here so we can benefit all from your addition ;)
WoLpH
Posts: 11
Joined: Tue Feb 22, 2005 6:31 am

Post by WoLpH »

I'm thinking of changing the script a little, atleast a few extra features would be nice.
Not only making it a little more flexible (some parameters should be optional and have a default value) but also adding a rename feature so it renames the original file to the name of the serie and the episode title (in a predefined format)
I've been thinking of doing this for some time but I'm not sure if I'll use anidb of ann for it.
Since I'm quite busy at the moment it will probably take some time before I will do it but its on my to-do list ;)
exhuma.twn
Posts: 3
Joined: Fri Jan 07, 2005 1:11 pm
Contact:

Post by exhuma.twn »

This is a vey nice idea. I was in the situation of badly named episodes as well many times. I would put more effort into the script, but I am pretty busy right now as well. And the script works, so it's pretty low on my todo list ;)
exp
Site Admin
Posts: 2438
Joined: Tue Oct 01, 2002 9:42 pm
Location: Nowhere

Post by exp »

Hmm,

I'd rather see you using the UDP API then accessing the web interface.
It adds a lot of overhead and a runaway client can't be detected and banned easily.

BYe!
EXP
R4cOOn
Posts: 2
Joined: Fri Apr 29, 2005 11:04 am

Post by R4cOOn »

Thought I'd add my little bit to the script. if you replace the last curl command by the following:

curl \
-s \
-b anidb_headers_and_cookies \
-c newCookies.txt \
-d "show=ed2kdump&ed2kdump.viewed=0&ed2kdump.state=0&ed2kdump.source=&ed2kdump.storage=ed2kdump.comment=&ed2kdump=${INPUT}&ed2kdump.identify=+IDENTIFY+" \
http://anidb.info/perl-bin/animedb.pl \
| gawk 'BEGIN{ nombre=0; print } /<small>.*<\/small>/ {match($0,"<small>.*</small>",a); print substr(a[0], 8,
length(a[0])-15); nombre++ } END{ print "\nNumber of files: "nombre }'


You will be able to print out the anidb filenames of the files. If you just add the "-s" and the last pipe to the original script, you're going to add them and print out the names (which is nice, too).

To answer the previous comment, I'm using Linux and there's no decent client, so I'm using the web interface anyway, this script just makes it easier. The webaom java client doesn't do the renaming without adding the files and it hashes them again to do so.

PS: In case you don't know, there's no need to create a file with teh ed2k hash keys to use the script, you can replace the bit where you put the filename of the file by:

<(echo "<paste of the ed2k links like on the web interface with the line breaks and everything")

and it works just as fine.
R4cOOn
Posts: 2
Joined: Fri Apr 29, 2005 11:04 am

Post by R4cOOn »

Is anyone till fiddling with the script?
I'm going to make some sort of GUI for it, based on Xdialog if I can find some time and I can give the initial layout if someone's got some free time on their hands.

---
R4cOOn
Locked