µTorrent for Mac, AMC, and launchd: automatic for the people

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
proustfan
Power User
Posts: 3
Joined: 30 Oct 2014, 05:33

µTorrent for Mac, AMC, and launchd: automatic for the people

Post by proustfan »

I automated filebot's AMC script to work with my µTorrent for Mac OS via launchd, and I wanted to share my steps for make benefit glorious nation of Kazakhstan.

Like the everyone else who uses µTorrent for Mac in these parts, I wanted to make it super self-service. Sadly, the Mac client doesn't support the essential feature "µTorrent -> Run Program -> Run this program when torrent finishes".

So I used launchd to automate it. launchd is the OS X replacement for cron and I wanted to try to go with the flow. launchd will initiate filebot every time a file is modified in your finished torrents directory.

Step 1) In order for this to work, you MUST configure µTorrent to "Move completed downloads to:" some other location, a location that you only use for handing off torrents to filebot and AMC. Otherwise, the script will get run constantly on partially-downloaded files, wasting a ton of resources and failing to move your files. Find this option in µTorrent -> Preferences under the "Directories" section.

Step 2) Work out a command to do exactly what you want with your files in this new location. I recommend starting with the canonical sticky post for AMC in this forum which suggests

Code: Select all

filebot -script fn:amc --output "/path/to/output" --log-file amc.log --action copy -non-strict "/path/to/input" --def excludeList=amc.txt
. It's fine if you either copy or move the torrent (keep in mind that "move" will break seeding) but your log file and your amc.txt file must NOT be stored in the same file as your done torrents. This would create an endless loop.

Step 3) Customize the following configuration file to match your preferences and torrent file locations. Again, your various .log files and amc.txt files MUST NOT go in your new "Move completed downloads to:" directory because that would trigger an endless loop. AMC will run when a file is modified in the directory, and then it will modify a file in that directory, etc forever.

Note that escaping arguments in this xml file is done completely differently than it is done on the command line. Anything that would have been enclosed in double quotes is not instead enclosed in <string></string> tags. This is better if you're using quotes inside your command line, but much worse if you are using xml entities in your command line. I haven't tried testing how that works out. Best of luck.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>org.proustfulness.filebotfortorrents</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/filebot</string>
            <string>-script</string>
            <string>fn:amc</string>
            <string>--output</string>
            <string>/Volumes/TwentyQuestions</string>
            <string>--log-file</string>
            <string>/Volumes/TwentyQuestions/amc.log</string>
            <string>--action</string>
            <string>move</string>
            <string>-non-strict</string>
            <string>/Volumes/TwentyQuestions/Done Torrents/</string>
            <string>--def</string>
            <string>excludeList=/Volumes/TwentyQuestions/amc.txt</string>
            <string>deleteAfterExtract=y</string>
            <string>seriesFormat=/Volumes/TwentyQuestions/Television/{n}/{'S'+s}/{n} - {s00e00} - {t}</string>
        </array>
        <key>WatchPaths</key>
        <array>
            <string>/Volumes/TwentyQuestions/Done Torrents</string>
        </array>
        <key>StandardOutPath</key>
        <string>/Volumes/TwentyQuestions/filebot.log</string>
        <key>WorkingDirectory</key>
        <string>/Volumes/TwentyQuestions</string>
        <key>StandardErrorPath</key>
        <string>/Volumes/TwentyQuestions/filebot.log</string>
        <key>SoftResourceLimits</key>
        <dict>
            <key>Core</key>
            <integer>9223372036854775807</integer>
        </dict>
        <key>HardResourceLimits</key>
        <dict>
            <key>Core</key>
            <integer>9223372036854775807</integer>
        </dict>
    </dict>
</plist>
But that part that says "WatchPaths"? That part makes it so that the script is initiated by launchd every time a file changes inside /Volumes/TwentyQuestions/Done Torrents

Step 4) Configurations for launchd go into ~/Library/LaunchAgents so save that file to a path like this: /Users/proustfan/Library/LaunchAgents/org.proustfulness.filebotfortorrents.plist.

Step 5) Your launchd files will get parsed and used every time you log in, but while you're still testing it you can use

Code: Select all

launchctl load /Users/proustfan/Library/LaunchAgents/org.proustfulness.filebotfortorrents.plist
and then open up Console.app and search for filebot. If it has any trouble, launchd will carp on the console for you. If filebot has any trouble, it will carp to the filebot.log file. (That is where you can see basically what would have been the output on the command line. If there is a problem with the way this launchd script is working, you can end it with

Code: Select all

launchctl unload /Users/proustfan/Library/LaunchAgents/org.proustfulness.filebotfortorrents.plist
then tweak the file and reload it.

This is working pretty excellently for me. My only gripes so far:
  • When I tried using the "clean" option in filebot, it trashed all the music in my done torrents directory. I naively hoped that it would ignore the music and leave it in place since I didn't tell it to do music renaming.
  • When I re-download the same file a second time (because my friend wanted to watch something I'd already seen) it got ignored by amc.txt. I naively hoped that amc.txt only ignored files it copied or couldn't handle, not all the files it's _moved_.
Anyway, I hope this is mildly helpful for someone. I'm so happy about getting this working as nicely as it is.

Love,
Proustfan
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by rednoah »

Great post! Upgrade to Sticky. Upgrade to Power User. For make benefit glorious nation of Kazakhstan. :lol:
:idea: Please read the FAQ and How to Request Help.
superpede
Posts: 2
Joined: 12 Mar 2015, 18:38

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by superpede »

Thank you proustfan!!!
This was just what i was looking for. Worked after modifying the adresses, no problems. Where can I read about implementing the subtitle script to your aml script? So that filebot also finds subs, for new and old media missing subs. Can't really figure out, heads and tails in xml code...
proustfan
Power User
Posts: 3
Joined: 30 Oct 2014, 05:33

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by proustfan »

Hi, superpede.
I don't know what would work for subs. Can you provide a working command line that copies subs the way you want? I could turn that into the XML format. Unfortunately I don't have it working for subs either, but among my preferred content, subs are total garbage and not worth salvaging.
Love,
Proustfan
garyleecn
Donor
Posts: 114
Joined: 19 Nov 2014, 03:48

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by garyleecn »

an easier, more user friendly solution (with paid software hazel though)

so, you have your utorrent downloads files into a directory, say /completed/
and then you can have torrent set up that once it finishes a download, it moves the torrent file to a directory, say /completed torrents/

and then you can have hazel monitor the folder /completed torrents/, once a new .torrent file is added to this folder, you let hazel run a shell script (filebot) on the folder /completed/, and optionally, you can delete the torrent, or add a comment so that it will not run on the same torrent twice.

this is so far the best (and easiest) solution for utorrent (or actually almost any torrent clients). you can set hazel to monitor /completed/ folder, but since the type of files downloaded into this folder (sometime folder, sometimes mkv, sometimes srt from filebot) is constantly changing (sometimes cause weird problems), it's better to have a dedicate torrent folder (even if it's inside /completed/, such as /completed/torrents/) just to activate filebot. so every single torrent task will trigger filebot EXACTLY once.
superpede
Posts: 2
Joined: 12 Mar 2015, 18:38

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by superpede »

Hey Proustfan..

That would be fantastic.

the "normal" script line is:

Code: Select all

filebot -get-missing-subtitles /Volumes/3tb/filebot/Movies/*/
Love Peter
cgacord
Posts: 12
Joined: 13 Jul 2014, 09:13

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by cgacord »

Is it any easier to use folder actions and have it run a script instead of dealing with launchd?

All you would need to do is create a script file that contains the customized filebot call and then create a folder action for the directory that your torrents are moved to which runs the script.

No need to create plist files and no dealing with launchctl.
Meshuu
Posts: 18
Joined: 09 Mar 2016, 15:50

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by Meshuu »

Hi guys, I tried this method to automate the process by translating my custom scripts:

Code: Select all

filebot -script fn:amc --output "/users/alevi/downloads/media" --action move -non-strict "/users/alevi/downloads/completed" --def music=y --log-file amc.log --def excludeList=amc.txt --def deleteAfterExtract=y --def clean=y --def musicFormat=/users/alevi/downloads/media/music/{artist}/"({y}) "{album}/"{pi.pad(2)} - "{t}
After translating the script in this way (I have not included all the items of my script for simplicity):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>org.proustfulness.filebotfortorrents</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/filebot</string>
            <string>-script</string>
            <string>fn:amc</string>
            <string>--output</string>
            <string>/users/alevi/downloads/media</string>
            <string>--log-file</string>
            <string>/users/alevi/downloads/media/amc.log</string>
            <string>--action</string>
            <string>move</string>
            <string>-non-strict</string>
            <string>/users/alevi/downloads/completed</string>
            <string>--def</string>
            <string>excludeList=/users/alevi/downloads/media/amc.txt</string>
            <string>--def</string>
            <string>deleteAfterExtract=y</string>
        </array>
        <key>WatchPaths</key>
        <array>
            <string>/users/alevi/downloads/completed</string>
        </array>
        <key>StandardOutPath</key>
        <string>/users/alevi/downloads/media/filebot.log</string>
        <key>WorkingDirectory</key>
        <string>/users/alevi/downloads/media</string>
        <key>StandardErrorPath</key>
        <string>/users/alevi/downloads/media/filebot.log</string>
        <key>SoftResourceLimits</key>
        <dict>
            <key>Core</key>
            <integer>9223372036854775807</integer>
        </dict>
        <key>HardResourceLimits</key>
        <dict>
            <key>Core</key>
            <integer>9223372036854775807</integer>
        </dict>
    </dict>
</plist>
and having them stored in .plist files. From cmdline I tried to start but unfortunately I get the following warning: Invalid property list.
Can someone help me?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: µTorrent for Mac, AMC, and launchd: automatic for the pe

Post by rednoah »

Using Automator Folder Actions or Finder Services is probably alot easier than dealing with launchd directly:
https://github.com/filebot/plugins/tree ... /automator

Image
:idea: Please read the FAQ and How to Request Help.
ajones7279
Posts: 2
Joined: 30 Apr 2021, 21:40

Re: µTorrent for Mac, AMC, and launchd: automatic for the people

Post by ajones7279 »

Ok, so I've been using this method for years on my Mac Mini with High Sierra without a problem. I recently upgraded to a new Mac Mini M1 with Big Sur and it no longer works. At first, I tried just copying everything over from my old Mac but the script wasn't working at all so I deleted everything related to Filebot and reinstalled from Homebrew. Now, the script started working in that it would recognize a change to my WatchPaths but I get permission denied every time. I've tried adding Filebot.app, filebot.sh, and Terminal to Full Disk Access, with no success. I've tried changing the permissions (chmod 644, 755, x, u+x) and nothing has worked so far. I'm no longer using uTorrent since they've went to the web version but Transmission has the functionality that I need. I don't know what else to try. Any ideas?

Image
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: µTorrent for Mac, AMC, and launchd: automatic for the people

Post by rednoah »

IDK, but /Volumes/Macintosh HD/Users/... is most unusual file path. Did you connect the system drive from some older Mac as external hard drive or something like that?
:idea: Please read the FAQ and How to Request Help.
ajones7279
Posts: 2
Joined: 30 Apr 2021, 21:40

Re: µTorrent for Mac, AMC, and launchd: automatic for the people

Post by ajones7279 »

Not quite. Macintosh HD was the name for the main hard drive on my older Mac Mini so I changed the new one to reflect it, so I wouldn't have to change anything in the plist. I uninstalled and reinstalled everything relating to Filebot to try and start fresh, and now I'm getting this error.

Image

Which is weird because the .Filebot folder definitely exist in my home folder. I did an echo $HOME and it shows the correct folder.
Image
Image

The fn:amc script works when I run it directly from Terminal. I may just try to input it directly into Transmission because this is incredibly frustrating. 😂

The only problem is, I need two different scripts. One for Movies, and one for TV shows, since they're moved to different folders on my external hard drive.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: µTorrent for Mac, AMC, and launchd: automatic for the people

Post by rednoah »

ajones7279 wrote: 02 May 2021, 06:53 Image
According to the screenshot, $HOME is undefined in this particular context. Strange, but easily fixed by doing export HOME="/Users/<name>" before calling filebot. Notably, this particular issue is unrelated to the previous permission issue.
:idea: Please read the FAQ and How to Request Help.
Post Reply