Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Last active January 22, 2022 13:53
Show Gist options
  • Select an option

  • Save Hashbrown777/f4b68bccf13472c5e4c5394e84ebb3df to your computer and use it in GitHub Desktop.

Select an option

Save Hashbrown777/f4b68bccf13472c5e4c5394e84ebb3df to your computer and use it in GitHub Desktop.
Update deluge's total uploaded byte tally via `state/torrents.fastresume`
(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 &lt;&lt;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' &gt;../torrents.fastresume
for torrent in *
do
#reinject name with new size data
printf '40:%s%s:' $torrent \`cat $torrent | wc -c\` &gt;&gt;../torrents.fastresume
cat $torrent &gt;&gt;../torrents.fastresume
rm $torrent
done
printf 'e' &gt;&gt;../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