Last active
January 22, 2022 13:53
-
-
Save Hashbrown777/f4b68bccf13472c5e4c5394e84ebb3df to your computer and use it in GitHub Desktop.
Update deluge's total uploaded byte tally via `state/torrents.fastresume`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| const output = open().document; | |
| //generate a script to run over your deluge state file | |
| output.write( | |
| `<pre>#!/bin/bash | |
| mkdir _ | |
| cd _ | |
| #split up the file and name them correctly, disregard the byte-counts | |
| awk \\ | |
| 'BEGIN { RS="[de]40:"; ORS=FS=":" } { if ($1 != "") { for (i = 2; i <= NF; i++) print $i > substr($1, 0, 40) } }' \\ | |
| ../torrents.fastresume | |
| #make sure the file sizes match the old byte-counts | |
| sed \\ | |
| -E \\ | |
| -i \\ | |
| 's/listle+:$/listlee/' \\ | |
| * | |
| while read -r hash uploaded | |
| do | |
| sed \\ | |
| -E \\ | |
| -i \\ | |
| "s/(14:total_uploadedi)[0-9]+(e)/\\1\${uploaded}\\2/" \\ | |
| $hash | |
| done <<EOF | |
| ` | |
| ); | |
| //convert everything to bytes | |
| const fixed = { | |
| GB : ' MB', | |
| MB : ' KB', | |
| KB : '' | |
| }; | |
| const fixing = /^(([0-9]+)(?:\.[0-9]+|))(?:\s+(\S+)|)$/; | |
| function fix(string) { | |
| while ((string = string.match(fixing))[3]) | |
| string = parseFloat(string[1] * 1024) + fixed[string[3]]; | |
| return string[2]; | |
| } | |
| //scrape your baka profile | |
| const infoHash = /(?<=info hash:\s+)[0-9a-z]+/; | |
| for (let entry of $('#inactive .torrent').get()) { | |
| entry = $(entry); | |
| output.write((await ( | |
| await fetch(entry.find('a.title').attr('href')) | |
| ).text()) | |
| .match(infoHash) | |
| [0] | |
| ); | |
| output.write('\t'); | |
| output.write(fix(entry.find('.transfer_up').text())); | |
| output.write('\n'); | |
| //dont trip anti-bot | |
| await new Promise((resolve) => { setTimeout(resolve, 10000); }); | |
| } | |
| output.write( | |
| `EOF | |
| printf 'd' >../torrents.fastresume | |
| for torrent in * | |
| do | |
| #reinject name with new size data | |
| printf '40:%s%s:' $torrent \`cat $torrent | wc -c\` >>../torrents.fastresume | |
| cat $torrent >>../torrents.fastresume | |
| rm $torrent | |
| done | |
| printf 'e' >>../torrents.fastresume | |
| cd .. && rm -r _ | |
| </pre>`); | |
| output.close(); | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment