Created
October 18, 2015 17:35
-
-
Save danzig666/3b41ab500326d630f553 to your computer and use it in GitHub Desktop.
Move all your torrents in QBittorrent
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
# Copyright (c) 2015, Jimmy Zelinskie. | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# | |
# * Redistributions of source code must retain the above copyright notice, this | |
# list of conditions and the following disclaimer. | |
# | |
# * Redistributions in binary form must reproduce the above copyright notice, | |
# this list of conditions and the following disclaimer in the documentation | |
# and/or other materials provided with the distribution. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# To move the paths of all your torrents at once, we need to replace references | |
# to the paths in all of the .fastresume files located in the BT_BACKUP directory. | |
# These files are bencoded and contain two different paths, one for libtorrent and | |
# the other for qBittorrent. | |
import os | |
import sys | |
from bencode import bdecode, bencode | |
# --- CHANGE THIS --- | |
# I happen to be using cygwin Python. | |
# If you're using native Windows Python, use forward slashes (i.e. 'C:/Windows'). | |
BACKUP_PATH = '/cygdrive/c/Users/Jimi/AppData/Local/qBittorrent/BT_BACKUP' | |
# -- CHANGE THIS --- | |
# These are what you're finding and replacing. | |
# Use forward slashes on Windows. | |
FIND_QBT_PATH = 'F:/Anime/' | |
REPLACE_QBT_PATH = 'F:/' | |
# Don't touch these. | |
# libtorrent expects backslashes in paths for Windows. | |
FIND_SAVE_PATH = os.path.normpath(FIND_QBT_PATH) | |
REPLACE_SAVE_PATH = os.path.normpath(REPLACE_QBT_PATH) | |
def main(): | |
for _, _, files in os.walk(BACKUP_PATH): | |
for name in files: | |
if name.endswith('.fastresume'): | |
path = BACKUP_PATH + '/' + name | |
with open(path, 'r+') as raw: | |
contents = raw.read() | |
try: | |
dct = bdecode(contents) | |
except: | |
continue | |
dct['qBt-savePath'] = dct['qBt-savePath'].replace(FIND_QBT_PATH, REPLACE_QBT_PATH) | |
dct['save_path'] = dct['save_path'].replace(FIND_SAVE_PATH, REPLACE_SAVE_PATH) | |
new_contents = bencode(dct) | |
raw.seek(0) | |
raw.write(new_contents) | |
raw.truncate() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment