JohnDoee / autotorrent

Matches torrents with files and gets them seeded
MIT License
269 stars 34 forks source link

Skip files instead of stopping script? #51

Open Jerrk opened 3 years ago

Jerrk commented 3 years ago

i'm trying to run this script on about 40,000 torrents that ive gathered over the years and from different storage solutions, change in clients, and restoring from backups, etc. i'm runnig into quite a few errors when running autotorrent.

This error seems to occur when the torrent file is corrupted and it completely stops the script. Removing the torrent and then re-running the script works past this point.

Traceback (most recent call last):
  File "autotorrent-env/bin/autotorrent", line 9, in <module>
    load_entry_point('autotorrent==1.7.1', 'console_scripts', 'autotorrent')()
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/cmd.py", line 210, in commandline_handler
    result = at.handle_torrentfile(os.path.join(current_path, torrent), dry_run)
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 500, in handle_torrentfile
    torrent = self.open_torrentfile(path)
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 568, in open_torrentfile
    return bdecode(f.read())
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/bencode.py", line 67, in bdecode
    raise BTFailure("invalid bencoded value (data after valid prefix)")
autotorrent.bencode.BTFailure: invalid bencoded value (data after valid prefix)

Sometimes there exists a duplicate torrent right next to each other which throws the error below. This also stops the script but i can re-run it without having to delete the duplicate torrent file.

 [OK]        '***************************************' Torrent added successfully
Traceback (most recent call last):
  File "autotorrent-env/bin/autotorrent", line 9, in <module>
    load_entry_point('autotorrent==1.7.1', 'console_scripts', 'autotorrent')()
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/cmd.py", line 210, in commandline_handler
    result = at.handle_torrentfile(os.path.join(current_path, torrent), dry_run)
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 549, in handle_torrentfile
    if self.client.add_torrent(torrent, destination_path, files['files'], fast_resume):
  File "/autotorrent-env/lib/python2.7/site-packages/autotorrent/clients/deluge.py", line 148, in add_torrent
    'seed_mode': fast_resume})
  File "/autotorrent-env/lib/python2.7/site-packages/deluge_client/client.py", line 253, in call
    return self._receive_response(self.deluge_version, self.deluge_protocol_version)
  File "/autotorrent-env/lib/python2.7/site-packages/deluge_client/client.py", line 232, in _receive_response
    raise exception(exception_msg)
deluge_client.client.AddTorrentError: Torrent already in session (*********************).
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/deluge/core/rpcserver.py", line 326, in dispatch
    ret = self.factory.methods[method](*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/deluge/core/core.py", line 483, in add_torrent_file
    return self.torrentmanager.add(
  File "/usr/lib/python3.9/site-packages/deluge/core/torrentmanager.py", line 536, in add
    __, add_torrent_params = self._build_torrent_params(
  File "/usr/lib/python3.9/site-packages/deluge/core/torrentmanager.py", line 446, in _build_torrent_params
    raise AddTorrentError('Torrent already in session (%s).' % torrent_id)
deluge.error.AddTorrentError: Torrent already in session (*********************)

also this error seems to be triggered with the Ω symbol in a torrent filename.

Traceback (most recent call last):
File "/mnt/user/appdata/autotorrent/autotorrent-env/bin/autotorrent", line 11, in
sys.exit(commandline_handler())
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/cmd.py", line 212, in commandline_handler
result = at.handle_torrentfile(os.path.join(current_path, torrent), dry_run)
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 453, in handle_torrentfile
self.link_files(destination_path, files['files'])
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 342, in link_files
if not os.path.isdir(file_path):
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib64/python2.7/genericpath.py", line 49, in isdir
st = os.stat(s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u03a9' in position 95: ordinal not in range(128)

This error is when the script tries to read a torrent file with no contents i.e 0 byte file size.

Traceback (most recent call last):
File "/mnt/user/appdata/autotorrent/autotorrent-env/bin/autotorrent", line 11, in
sys.exit(commandline_handler())
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/cmd.py", line 212, in commandline_handler
result = at.handle_torrentfile(os.path.join(current_path, torrent), dry_run)
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 419, in handle_torrentfile
torrent = self.open_torrentfile(path)
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/at.py", line 487, in open_torrentfile
return bdecode(f.read())
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/autotorrent/bencode.py", line 62, in bdecode
r, l = decode_func[six.indexbytes(x, 0)](x, 0)
File "/mnt/user/appdata/autotorrent/autotorrent-env/lib/python2.7/site-packages/six.py", line 666, in indexbytes
return ord(buf[i])
IndexError: string index out of range

Would be really nice if we could just skip these files and then let the script keep running.

Jerrk commented 3 years ago

it appears the @shoghicp fork https://github.com/shoghicp/autotorrent addresses some of these issues

newadventure079 commented 2 years ago

It also looks like https://github.com/TiarnanRedmond/autotorrent is taking in all the fixes from various forks including @shoghicp