New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

Remove multiple downloads

Got problems with your B2 or B3? Share and get helped!
Post Reply
axm
Posts: 19
Joined: 05 Apr 2010, 06:44

Remove multiple downloads

Post by axm »

Torrents and other downloads stay until removed individually. I tend to tidy up from while to while and really need mass operations.

In the past I rather would restart (disable/enable downloads) the torrent client after cleaning the torrent folder. I rather would not do that, since I always keep some of the torrents seeding and these need to be rechecked then, which takes quite a lot of time.

So I scripted a little. One script to get all active downloads which produces a file, one download a line. There I delete all the lines I do _not_ want to be removed. A second script takes all remaining lines and stops them.

Code: Select all

#!/bin/bash
session=65faa6af7444f27c471a21f4140513e0
FIELDS=7,17,25
BUBBA=bubba

curl -o - --cookie "PHPSESSID=${session}" "${BUBBA}"/admin/downloads/dolist 2>/dev/null \
  |grep 'name="url"' -A1 -B11 | egrep 'style=""|input type="hidden"'| awk '{printf("%s%s", $0, (NR%3 ? "," : "\n"))}' \
  |tr "<>\"" ";" |cut -d ";" -f ${FIELDS} |sort > downloads.csv

Code: Select all

#!/bin/bash
set -e

session=65faa6af7444f27c471a21f4140513e0
BUBBA=bubba

function getField {
  echo "${1}" |cut -d ";" -f "${2}" 2>&1
}

Now edit downloads.csv if you do not want to remove all downloads.

while read entry; do
  name=$(getField "${entry}" 1)
  uuid=$(getField "${entry}" 3)
  url=$(getField "${entry}" 2)
  echo Stopping: "${name}" with uuid "${uuid}" at url "${url}"
  curl -v --cookie "PHPSESSID=${session}" --data "url=${url}&uuid=${uuid}&do=Cancel" "${BUBBA}"/admin/downloads/remove 2>&1 |grep HTTP | cut -d '<' -f 2
done < downloads.csv
Obviously you have to replace the bubba location in the two scripts. Additionally, I haven't yet bothered to emulate a real login - just log in with a browser and use the value in the cookie produced by that for session (again, both scripts). I might add that later, if I become bothered by that, but since my usage is rather rare ...

I may have had only torrent downloads removed in my first run, so no guarantee that other downloads are tested.

Of course this is just quick and dirty frontend parsing and parts of it will break with the next more than minor update for that. But again, that would be a good opportunity to support mass removals in the web interface, wouldn't it?

PS: The forum does not allow me to post the protocol "http" in the curl location - add that for yourselves (for example in the BUBBA-constant).
RandomUsername
Posts: 904
Joined: 09 Oct 2009, 18:49

Re: Remove multiple downloads

Post by RandomUsername »

Nice.

For my part, I'd like to see http downloads remove themselves automatically once complete.
axm
Posts: 19
Joined: 05 Apr 2010, 06:44

Re: Remove multiple downloads

Post by axm »

From what I have unterstood about it, I suppose you could alter usr/share/web-admin/admin/views/default/downloads/downloads_list_view.php to output an additional last modified date. Then have a cronjob set up with an additional script which deletes new torrents from downloads.csv and stops the rest.

Obviously this would be better implemented internally, but I cannot point you to where to do that.
Post Reply