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 ">