Skip to content
This repository was archived by the owner on May 29, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
*.mo
*.egg-info
*.egg
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ general

- ``db`` - Path to the database file
- ``store_path`` - Folder where the virtual folders seeded, resides
- ``client_path`` - Folder where the virtual folders seeded, resides
inside the torrent client. Defaults to `store_path`
- ``ignore_files`` - A comma seperated list of files that should be
ignored (supports wildcards)
- ``add_limit_size`` - Max size, in bytes, the total torrent size is
Expand Down
7 changes: 5 additions & 2 deletions autotorrent/at.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ class IllegalPathException(Exception):
pass

class AutoTorrent(object):
def __init__(self, db, client, store_path, add_limit_size, add_limit_percent, delete_torrents, link_type='soft'):
def __init__(self, db, client, store_path, client_path, add_limit_size, add_limit_percent, delete_torrents, link_type='soft'):
self.db = db
self.client = client
self.store_path = store_path
self.client_path = client_path
self.add_limit_size = add_limit_size
self.add_limit_percent = add_limit_percent
self.delete_torrents = delete_torrents
Expand Down Expand Up @@ -525,6 +526,7 @@ def handle_torrentfile(self, path, dry_run=False):
if files['mode'] == 'link' or files['mode'] == 'hash':
logger.info('Preparing torrent using link mode')
destination_path = os.path.join(self.store_path, os.path.splitext(os.path.basename(path))[0])
client_path = os.path.join(self.client_path, os.path.splitext(os.path.basename(path))[0])

if os.path.isdir(destination_path):
logger.info('Folder exist but torrent is not seeded %s' % destination_path)
Expand All @@ -535,6 +537,7 @@ def handle_torrentfile(self, path, dry_run=False):
elif files['mode'] == 'exact':
logger.info('Preparing torrent using exact mode')
destination_path = files['source_path']
client_path = files['source_path']

fast_resume = True
if files['mode'] == 'hash':
Expand All @@ -546,7 +549,7 @@ def handle_torrentfile(self, path, dry_run=False):
logger.info('Removing torrent %r' % path)
os.remove(path)

if self.client.add_torrent(torrent, destination_path, files['files'], fast_resume):
if self.client.add_torrent(torrent, client_path, destination_path, files['files'], fast_resume):
self.print_status(Status.OK, path, 'Torrent added successfully')
return Status.OK
else:
Expand Down
2 changes: 1 addition & 1 deletion autotorrent/clients/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_torrents(self):
"""
raise NotImplementedError

def add_torrent(self, torrent, destination_path, files, fast_resume=True):
def add_torrent(self, torrent, destination_path, file_path, files, fast_resume=True):
"""
Adds a torrent to the torrent client.
"""
Expand Down
2 changes: 1 addition & 1 deletion autotorrent/clients/deluge.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_torrents(self):
result = self.rpcclient.call('core.get_torrents_status', {}, ['name'])
return set(x.lower() for x in result.keys())

def add_torrent(self, torrent, destination_path, files, fast_resume=True):
def add_torrent(self, torrent, destination_path, file_path, files, fast_resume=True):
"""
Add a new torrent to Deluge.

Expand Down
2 changes: 1 addition & 1 deletion autotorrent/clients/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_torrents(self):
self._login_check()
return set(torrent['hash'].lower() for torrent in self._session.get(urljoin(self.url, 'api/v2/torrents/info')).json())

def add_torrent(self, torrent, destination_path, files, fast_resume=True):
def add_torrent(self, torrent, destination_path, file_path, files, fast_resume=True):
"""
Add a new torrent to qBittorrent.

Expand Down
14 changes: 7 additions & 7 deletions autotorrent/clients/rtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_torrents(self):
def _get_mtime(self, path):
return int(os.stat(path).st_mtime)

def add_torrent(self, torrent, destination_path, files, fast_resume=True):
def add_torrent(self, torrent, destination_path, file_path, files, fast_resume=True):
"""
Add a new torrent to rtorrent.

Expand All @@ -151,7 +151,7 @@ def add_torrent(self, torrent, destination_path, files, fast_resume=True):

result = {b'priority': 1, b'completed': int(f['completed'])}
if f['completed']:
result[b'mtime'] = self._get_mtime(os.path.join(destination_path, *f['path']))
result[b'mtime'] = self._get_mtime(os.path.join(file_path, *f['path']))
torrent[b'libtorrent_resume'][b'files'].append(result)

last_position = current_position + f['length']
Expand All @@ -172,19 +172,19 @@ def add_torrent(self, torrent, destination_path, files, fast_resume=True):
logger.info('This torrent is incomplete, setting bitfield')
torrent[b'libtorrent_resume'][b'bitfield'] = bitfield_to_string(bitfield)

torrent_file = os.path.join(destination_path, '__tmp_torrent%s.torrent' % uuid.uuid4())
with open(torrent_file, 'wb') as f:
torrent_file = '__tmp_torrent%s.torrent' % uuid.uuid4()
with open(os.path.join(file_path, torrent_file), 'wb') as f:
f.write(bencode(torrent))

infohash = hashlib.sha1(bencode(torrent[b'info'])).hexdigest()

if 'load.start' in self.get_methods():
cmd = [torrent_file, 'd.directory_base.set="%s"' % os.path.abspath(destination_path)]
cmd = [os.path.join(destination_path, torrent_file), 'd.directory_base.set="%s"' % os.path.abspath(destination_path)]
cmd.append('d.custom1.set=%s' % quote(self.label))
logger.info('Sending to rtorrent: %r' % cmd)
self.proxy.load.start('', *cmd)
else:
cmd = [torrent_file, 'd.set_directory_base="%s"' % os.path.abspath(destination_path)]
cmd = [os.path.join(destination_path, torrent_file), 'd.set_directory_base="%s"' % os.path.abspath(destination_path)]
cmd.append('d.set_custom1=%s' % quote(self.label))
logger.info('Sending to rtorrent: %r' % cmd)
self.proxy.load_start(*cmd)
Expand All @@ -199,6 +199,6 @@ def add_torrent(self, torrent, destination_path, files, fast_resume=True):
else:
logger.warning('Torrent was not added to rtorrent within reasonable timelimit')

os.remove(torrent_file)
os.remove(os.path.join(file_path, torrent_file))

return successful
2 changes: 1 addition & 1 deletion autotorrent/clients/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_torrents(self):
result = self.call('torrent-get', fields=['hashString'])
return set(x['hashString'].lower() for x in result['torrents'])

def add_torrent(self, torrent, destination_path, files, fast_resume=True):
def add_torrent(self, torrent, destination_path, file_path, files, fast_resume=True):
"""
Add a new torrent to Transmission.

Expand Down
4 changes: 3 additions & 1 deletion autotorrent/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ def commandline_handler():
client_options = dict(config.items(client_option))
client_options.pop('client')
client = TORRENT_CLIENTS[client_name](**client_options)
store_path = config.get('general', 'store_path')

at = AutoTorrent(
db,
client,
config.get('general', 'store_path'),
store_path,
(config.get('general', 'client_path') if config.has_option('general', 'client_path') else store_path),
config.getint('general', 'add_limit_size'),
config.getfloat('general', 'add_limit_percent'),
args.delete_torrents,
Expand Down