将Windows系统qBittorrent中的种子免校验转移到飞牛私有云的qBittorrent中 ![](https://youjb.com/images/2024/09/25/image86e9893dedebb408.png) qBittorrent 软件中所有的种子信息都有备份,保存在BT_backup文件夹中,该文件夹一般位于`C:\Users\Administrator\AppData\Local\qBittorrent\BT_backup`目录中。其中包括种子文件`*.torrent`及种子恢复文件`*.fastresume`。 > .fastresume文件是Bencode 编码,可以直接用文本编辑器打开,虽然有乱码,但是不影响查看文件夹相关信息,可以用来确定旧文件夹及查看脚本修改是否生效。当然不能直接修改,直接编辑器修改后编码就被破坏了,所以编辑器批量替换路径也是不行的。 ###1、万事先备份,请先备份BT_backup文件夹 ###2、然后,直接一个脚本解决: ```python import os import re # 备份后的 BT_backup 文件夹路径,linux系统,所以根目录直接是/,如果是 win 系统,应该是类似 C:\格式开头,请根据自己的实际路径修改 torrentsDir = r'/Users/dt27/Downloads/BT_backup/' # 新旧文件夹及其对应关系写在这里, # 格式:b'旧文件夹路径': '新文件夹路径' # 多个文件夹之间用英文逗号,分隔。 # Windows 文件夹这里写两个斜杠\\是因为单独一个斜杠\在代码中有特殊意义,所以要写两个表示转义,不明白的按我这么写就行了。 # 如果不确定旧文件夹,这一行可以直接写fastresumePaths = {} 这样会把所有种子的旧文件夹列出来。 fastresumePaths = {b'D:\\TV\\': b'/vol1/1000/TV', b'D:\\Movie\\': b'/vol1/1000/Movie', b'D:\\Music\\': b'/vol1/1000/Music'} if not fastresumePaths: print('Finding paths...\n') detectedPaths = [] # Loop through torrents directory for file in os.listdir(torrentsDir): if file.endswith('.fastresume'): with open(torrentsDir + file, 'rb') as fastresumeFile: filedata = fastresumeFile.read() #pattern = re.compile(br'save_path(\d+):') #query = pattern.search(filedata) query = re.search(br'save_path(\d+):', filedata) if query is None: print(f'Could not find path in {file}') else: pathLen = int(query.group(1)) path = filedata[query.end():query.end() + pathLen] # check if user entered paths to change or not if fastresumePaths: print(fastresumePaths) if path in fastresumePaths: newPath = fastresumePaths[path] filedata = filedata.replace( bytes(str(pathLen), 'utf-8') + b':' + path, bytes(str(len(newPath)), 'utf-8') + b':' + newPath ) print(f"Replaced {path} with {newPath}") with open(torrentsDir + file, 'wb') as fastresumeFile: fastresumeFile.write(filedata) else: if path not in detectedPaths: detectedPaths.append(path) if fastresumePaths is None or not fastresumePaths: if not detectedPaths: print('No paths were found') else: print('The following paths were found\n') for path in detectedPaths: print(path) print('\nCopy the following code into the "fastresumePaths" variable to replace paths.\n') maxPathLength = len(max(detectedPaths, key=len)) + 4 print(f"# {'Original Path'.ljust(maxPathLength)} New Path") print(f"# {'-'*(maxPathLength)} {'-'*(maxPathLength)}\n") print('fastresumePaths = {') for path in detectedPaths: print(f" {str(path).ljust(maxPathLength)}: {str(path).ljust(maxPathLength)},") print('}\n') ``` 脚本来源:[Replace paths easily in qBittorrent .fastresume (useful when switching from windows to linux)](https://gist.github.com/Roardom/d3b188a3e4be7d9da4ce9a2239878605) 本脚本在 MacOS 中测试无误,其他系统执行脚本时可能会出现报错信息,请根据报错信息自己排查。 一般就是路径格式或字符串格式的问题。