fastresume change directory phyton script help

General support for problems installing or using Deluge
dopedangel
New User
New User
Posts: 3
Joined: Tue Nov 21, 2017 7:34 am

fastresume change directory phyton script help

Postby dopedangel » Tue Apr 16, 2019 9:14 am

I am in the process of changing my setup the main reason I have been hesitating to redo my whole setup is having to recheck all my 500+ torrents which will probably take days. I was looking for a way to get around that and came across this script. And was wondering if any python wizard here would be willing to modify it for deluge.


Original link
https://qbforums.shiki.hu/index.php?topic=4976.0

Code: Select all

import glob
import os
import re


qBt_savePath_exp = re.compile('qBt-savePath\d+')
save_path_exp = re.compile('save_path\d+')
path_length_exp = re.compile('qBt-savePath(\d+)')


print 'Simple tool to replace base path on torrents'
old_text = raw_input('Old String to search: ')
new_text = raw_input('String to insert in place of found string: ')

print 'Replacing ' + old_text + ' with ' + new_text

os.chdir('BT_backup')

for file in glob.glob('*.fastresume'):
    with open(file, 'rb') as f:
        data = f.read()

    if old_text in data:
        print 'Found Item'

        qBt_pos_start = re.search(qBt_savePath_exp, data).start()
        path_length = int(re.search(path_length_exp, data).group(1))

        qBt_pos_stop = re.search(qBt_savePath_exp, data).end() + (path_length + 1)

        qBt_path = data[qBt_pos_start:qBt_pos_stop]

        path = qBt_path[(path_length * -1):]

        front_string = data[:qBt_pos_start]
        rear_string = data[qBt_pos_stop:]

        path = path.replace(old_text, new_text)

        new_path_length = len(path)

        data = front_string + 'qBt-savePath' + str(new_path_length) + ':'
        data += path
        data += rear_string

        sp_pos_start = re.search(save_path_exp, data).start()
        sp_pos_stop = re.search(save_path_exp, data).end() + (path_length + 1)

        front_string = data[:sp_pos_start]
        rear_string[sp_pos_stop:]

        data = front_string + 'save_path' + str(new_path_length) + ':'
        data += path
        data += rear_string

        with open(file, 'wb') as f:
            f.write(data)

Return to “Support”

Who is online

Users browsing this forum: No registered users and 5 guests