Mac OS - Launch script on torrent completion

Ask for help and report issues with the Mac OS X version of Transmission
Post Reply
crendore
Posts: 3
Joined: Fri Oct 09, 2020 11:21 pm

Mac OS - Launch script on torrent completion

Post by crendore » Fri Oct 09, 2020 11:27 pm

There are several threads on this board about this topic, but most of them are 10+ years old, and incorrect. For example:
viewtopic.php?t=10636

And rather than gravedig that thread or any of the others i'm starting a new thread. I am trying to figure out if it is possible to launch a script automatically when torrents complete downloading.
most threads will suggest modifying

Code: Select all

~/Library/Preferences/org.m0k.transmission.plist
And adding two new keys:

Code: Select all

script-torrent-done-enabled Boolean Yes
script-torrent-done-filename String "/path/to/your/script.sh";
I believe this is incorrect because all the other keys in this plist are camel case not hyphen separated, I believe the keys should be like this:

Code: Select all

ScriptTorrentDoneEnabled Boolean Yes
ScriptTorrentDoneFilename  String "/path/to/your/script.sh";
But even with this change I am not seeing any results when torrents complete my script does not run. Does anyone have this working successfully?

crendore
Posts: 3
Joined: Fri Oct 09, 2020 11:21 pm

Re: Mac OS - Launch script on torrent completion

Post by crendore » Sat Oct 10, 2020 1:46 am

OK I gave up on trying to get this shell script to trigger from transmission, here's a more ghetto solution to auto unrar completed torrents using python and crontab.

You'll need to install

Code: Select all

 pip install transmission-rpc
main script: transmission.py

Code: Select all

from transmission_rpc import Client
import subprocess, os, time

#use a better username and password this is just an example
rpc_client = Client(username="user", password="pass")

def extract_archives(torrent):
	directory = f'{torrent.downloadDir}/{torrent.name}/'
	if os.path.isdir(directory):
		for file in os.listdir(directory):
			if file.endswith(".part"):
				# download not complete yet!
				return False
		for file in os.listdir(directory):
			if file.endswith(".rar"):
				subprocess.Popen(['/usr/local/bin/unrar', 'e', '-o-', file], cwd=directory)
				return True
	else: 
		return True

# load existing torrents from previous run
existing_torrents = []
with open('existing_torrents', 'r') as existing_torrents_file:
	existing_torrents = [line.rstrip() for line in existing_torrents_file] 

# look for any new torrents, extract if completed
for torrent in rpc_client.get_torrents():
	if torrent.hashString not in existing_torrents:
		if torrent.status != "downloading":
			# extract torrents that started in the last 24 hours that haven't been extracted yet
			if torrent.addedDate > (time.time() - 24 * 60 * 60):
				if extract_archives(torrent):
					existing_torrents.append(torrent.hashString)
			else:
				existing_torrents.append(torrent.hashString)

with open('existing_torrents', 'w') as existing_torrents_file:		
	existing_torrents_file.write("\n".join(existing_torrents))
crontab entry:

Code: Select all

* * * * * cd  /path/to/the/place/you/saved/the/script/ && /path/to/your/python/virtual/environment/bin/python /path/to/the/place/you/saved/the/script/transmission.py > /path/to/the/place/you/saved/the/script/autounrar.log

mike.dld
Transmission Developer
Posts: 287
Joined: Wed Dec 25, 2013 10:56 pm

Re: Mac OS - Launch script on torrent completion

Post by mike.dld » Sat Oct 10, 2020 11:41 am

Preferences dialog -> Transfers -> Management tab -> Call Script: When download completes: (at the bottom of the dialog)

crendore
Posts: 3
Joined: Fri Oct 09, 2020 11:21 pm

Re: Mac OS - Launch script on torrent completion

Post by crendore » Mon Oct 12, 2020 6:39 pm

Well shit...i feel really dumb now.

Thanks!

Post Reply