* Jesse F. Hughes <jesse@phiwumbda.org> wrote:
> Georg Neis <georg@fli4l.de> writes:
> > * Jesse F. Hughes <jesse@phiwumbda.org> wrote:
> >> I'd like to edit the file btdownloadxterm.sh so that it first copies
> >> the torrent file to ~/BitTorrent and then calls xterm as it is. This
> >> way, if I don't finish getting the file, I can later start up from the
> >> command line rather than find the torrent via the browser a second
> >> time.
> >>
> >> This should be trivial, but I just don't know how to send
> >> btdownloadxterm.sh the file name for the torrent. If I had that, then
> >> I could just do "cp $1 $filename".
> >
> > Actually, $1 _is_ the filename of the torrent file. Just add the
> > following line (above the last line, of course):
> >
> > cp "$1" "$HOME"/BitTorrent
>
> But it's the filename of the torrent file as it's saved now, which is
> typically in a temporary location. That's not a very good filename
> (even if I throw away the path and keep just the basename).
>
> At the TV Torrents site, the torrent is served by a cgi-script. If I
> choose to save the torrent, then Konqueror chooses a good name for
> it. If I choose to call btdownloadxterm.sh, Konqueror chooses a
> temporary file name for it and sends that file name to the script.
Okay, I understand the problem. I tested with Mozilla Firefox and
it took the proper filename. You could use btshowmetainfo.py to
extract a (hopefully) useful name from the torrent file:
$ btshowmetainfo.py ~/BitTorrent/slackware-9.1-source-d3.torrent
btshowmetainfo 20021207 - decode BitTorrent metainfo files
metainfo file.: slackware-9.1-source-d3.torrent
info hash.....: f67fdc4888fbdfff80c76d3ffd5d212f512efd74
directory name: slackware-9.1-iso
files.........:
slackware-9.1-source-d3.iso (689995776)
slackware-9.1-source-d3.iso.asc (189)
slackware-9.1-source-d3.iso.md5 (62)
archive size..: 689996027 (2632 * 262144 + 33019)
announce url..:
http://transamrit.net:8082/announce
$ btshowmetainfo.py BitTorrent/slackware-9.1-source-d3.torrent \
| grep "^metainfo file.:" | sed 's/^.*: //'
slackware-9.1-source-d3.torrent
Add to btdownloadxterm.sh something like this:
name="`btshowmetainfo.py \"$1\" | grep '^metainfo file.:' | sed 's/^.*: //'`"
cp "$1" ~/BitTorrent/"$name" # you may want to check if there's
# already a file with this name here
Georg