Skip to content

Instantly share code, notes, and snippets.

@fdgogogo
Created September 7, 2020 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdgogogo/f316441a1a27b046718be00ec8588e9c to your computer and use it in GitHub Desktop.
Save fdgogogo/f316441a1a27b046718be00ec8588e9c to your computer and use it in GitHub Desktop.
Fix the issue 'Error: No data found! Ensure your drives are connected or use "Move Data File To...". To re-download, remove the torrent and re-add it.' caused by disk failure or mistakenly deletion By re-download all the torrents.
# -*- coding: utf-8 -*-
"""
Fix the issue 'Error: No data found! Ensure your drives are connected or use "Move Data File To...". To re-download, remove the torrent and re-add it.'
caused by disk failure or mistakenly deletion By re-download all the torrents.
Make a copy of the "torrents" dir from transmission config dir, the original one will be modified when script is running.
Authored by: Fang Jiaan (fduodev@gmail.com)
"""
import os
torrent_path = '.'
files = os.listdir(torrent_path) # torrents copy dir
files = [os.path.join(torrent_path, f) for f in files]
username = ''
password = ''
auth = '--auth %s:%s' % (username, password) if (username and password) else ''
pp = os.popen('transmission-remote %s -l' % auth)
data = pp.read()
for line in data.splitlines()[1:-1]:
if 'Stopped' not in line:
continue
header = line[:4].strip()
id = header.strip('*')
info = os.popen('transmission-remote %s -t %s -i' % (auth, id)).read()
lines = info.splitlines()
loc = lines[8]
hash = lines[3]
hash = hash.split(' ')[-1][:16]
loc = loc.split(' ')[-1]
torrent = [x for x in files if hash in x][0]
print id, hash, loc, torrent
os.popen('transmission-remote %s -t %s --remove' % (auth, id)).read()
os.popen(
'transmission-remote %s --add "%s" -w %s' % (auth, torrent, loc)).read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment