Board index Scripting and Automation Automated Media Center

Automated Media Center

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc

Post 01 Aug 2012, 13:04
rednoah User avatar
The Source

Posts: 2090
Location: 北京

Here's a script that you can use with µTorrent as "Run program when torrent finishes" command to automatically sort out your downloads. It'll fully automatically organize newly downloaded TV shows and movies and is smart enough to detect what is what. The script will only touch video/subtitle files and will leave everything else as is.

  1. Unrar archives
  2. Group movies and episodes and then handle them seperately (auto-detect episode-vs-movie file)
  3. Fetch subtitles and transcode to SubRip/UTF-8
  4. Copy and Organize episodes, movies and music files into folders and rename files properly
    • Movies will be sorted into {output}/Movies/Name (Year)/Name (Year) [CD123].ext
    • TV Shows will be sorted into {output}/TV Shows/Name/Season N/Name - S00E00 - Title.ext
    • Music will be sorted into {output}/Music/Artist/Album/Artist - Title.ext
  5. Fetch artwork and generate .nfo files
  6. Notify XBMC (via TCP on port 9090) and/or Plex (via HTTP on port 32400) to rescan it's video library
  7. Log into MyEpisodes and mark newly downloaded episodes as 'acquired'
  8. Send a report about newly added files per email

Setup Instructions:
0. Install FileBot using the .msi installer

1. Setup µTorrent to run FileBot.

µTorrent -> Run Program -> Run this program when torrent finishes:
filebot -script fn:amc --output "X:/path/to/media" --log-file amc.log --action copy --conflict override -non-strict --def music=y subtitles=en artwork=y "ut_dir=%D" "ut_file=%F" "ut_kind=%K" "ut_title=%N" "ut_label=%L" "ut_state=%S"

2. Change --output to where you want to copy/organize your files. Input is provided by µTorrent variables.

3. Done! Setting this up will take less then a minute. Now wait and enjoy how things will be organized fully automatically.

utorrent-run-program.png
µTorrent / Preferences / Run Program / Run this program when torrent finishes
utorrent-run-program.png (7.06 KiB) Viewed 7248 times


Options:
--def music=n Don't process music files
--def subtitles=en,de,fr Download subtitles for the given languages
--def artwork=n Don't fetch artwork/nfo
--def backdrops=y Fetch all available backdrops (not just one as with artwork=y)
--def ignore=regex Ignore filepaths that match the given regular expression
--def xbmc=hostname Tell the given XBMC instance to rescan it's library
--def plex=hostname Tell the given Plex instance to rescan it's library
--def myepisodes=username:password Use the following MyEpisodes account to mark episodes as 'acquired'
--def pushover=userkey Send update notifications to your devices via Pushover
--def gmail=username:password Use the following gmail account to send and recieve reports (username is the username only, without the @gmail.com part)
--def mailto=email Send report to the given email address (optional, email to yourself if not set)
--def clean=y Automatically empty folders and clutter files that may be left behind after moving the video files or temporary extracted files after copying
--def exec=command {file} Run program on newly processed files
--def minFileSize=0 Only process files larger than the given number (in bytes). Default minFileSize is 100 MB.


Change how files will be organized and renamed:
You can override the default naming schemes via --def seriesFormat, animeFormat or movieFormat but make sure you understand how cmdline arguments work since you must escape double quotes via \", ampersands, etc otherwise the cmdline arguments will not be passed to FileBot as you may think. Relative paths will be resolved against --output and you can use absolute paths if you want to use multiple drives.
--def "seriesFormat=TV/{n}/{'S'+s}/{fn}" "animeFormat=Anime/{n}/{fn}" "movieFormat=Movies/{n} {y}/{fn}" "musicFormat=Music/{n}/{fn}"

If your format contains quotes, e.g. {"-$fn"}, and you just copy and paste it, e.g. "movieFormat={"-$fn"}", the quotes in the format will mess with cmdline argument parsing. Hence you MUST ESCAPE DOUBLE QUOTES, e.g. "movieFormat={\"-$fn\"}".


Notes
  • The folder paths to Location of Downloaded Files must not end with backslash \ because the value gets passed through as the %D token. So the final backslash \ will escape the double-quote " and mess up everything
  • It is recommended to use / as separator and not \ since it's also used to escape characters, e.g. --output "X:\" will mess up the cmdline in unexpected ways
  • If you have PATH issues (e.g. 'filebot' command not found) try using the absolute path to the executable, e.g. "C:/Program Files/Filebot/filebot.exe" or "./Applications/Filebot.app/Contents/MacOS/filebot.sh"
  • If you have installed 32-bit Java you will need a 32-bit FileBot install for 7zip and MediaInfo integration to work. If you're on 64-bit, then only install 64-bit Java and 64-bit FileBot.
  • You can force Movie/TV Show/Anime mode or force ignore files via torrent labels, e.g. label movie to force TMDB, tv to force TheTVDB, anime to force AniDB or other to not process this torrent
  • If you use more than one XBMC/Plex you can specify multiple hosts or ips like this xbmc=host1,host2,host3,etc
  • Use --conflict fail to make the script terminate on any conflicts or failures rather than gracefully ignore these errors and continue
  • Using --action symlink|keeplink|hardlink requires at least Java 7
  • Using --action keeplink won't work because µTorrent has a known bug that prevents it from opening and seeding symbolic links
  • fn:amc will automatically fetch the script and auto-update but you can also specify a local path to run your own customized script

Standalone Usage
You can use the script directly from the cmdline like this, by just adding files as arguments instead of the utorrent parameters.
filebot -script fn:amc "/path/to/input/" --output "X:/path/to/output" --action copy -non-strict

Here's a video tutorial for that.


Troubleshooting
If something is not working, just run the command manually in new cmd window and see what happens. You can find each cmdline call with arguments in µTorrents Logger tab so you can just copy it from there.

*** If you need help start a new thread and always include cmdline output! ***

It's always helpful to check the exact command utorrent ends up executing in the Logger tab. It'll look something like this:
[2013-03-05 20:44:24]  Executing: filebot -script fn:amc --output "D:/Organized Media" --log-file amc.log --action hardlink --conflict override -non-strict --def "ut_dir=D:\Media\Avatar" "ut_file=" "ut_kind=multi" "ut_title=Avatar" "ut_label=" "ut_state=5"



Feedback
I'd love to get some feedback on how well this script works for everybody. Should work perfectly for most, but there's always tricky cases that might not be covered yet. Also if you've set the script up to work with deluge, transmission, cron, automator, etc I'd like to hear from you. ;)


View Script:
http://filebot.net/scripts/amc.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2090
Location: 北京

If you're using this script with µTorrent on Windows you might find it annoying that it'll popup a cmd window stealing the focus each time.

This vbscript will execute a given program in a hidden cmd.

invoke.vbs
(178 Bytes) Downloaded 862 times

e.g.
C:\invoke.vbs filebot -script fn:amc --output "X:/path/to/media" --log-file amc.log --action copy --conflict override -non-strict --def "ut_dir=%D" "ut_file=%F" "ut_kind=%K" "ut_title=%N" "ut_label=%L" "ut_state=%S"
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2090
Location: 北京

Since the utorrent-postprocess as described above only works on Windows you might be wondering how to set things up on Linux or Mac with other bittorrent clients. Here's a little tutorial how to set this up with Transmission BitTorrent Client. These instructions are for Ubuntu Linux, you can find a Guide for Mac OSX with lots of screenshots here.

Create a shell script (e.g. transmission-postprocess) that'll call filebot like this and make sure to chmod +rx it:
#!/bin/bash
filebot -script fn:amc --output "$HOME/Videos" --log-file amc.log --action copy --conflict override -non-strict --def artwork=y "ut_dir=$TR_TORRENT_DIR/$TR_TORRENT_NAME" "ut_kind=multi" "ut_title=$TR_TORRENT_NAME"

Open ~/.config/transmission/settings.json and set it to call our shell script on download complete:
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/path/to/transmission-postprocess",

Transmission Configuration Files:
https://trac.transmissionbt.com/wiki/ConfigFiles
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2090
Location: 北京

Here's how to set things up with the Deluge BitTorrent Client. Should work on Mac, Linux, BSD etc

Create a shell script (e.g. deluge-postprocess) that'll call filebot like this and make sure to chmod +rx it:
#!/bin/bash
TORRENT_ID=$1
TORRENT_NAME=$2
TORRENT_PATH=$3
filebot -script fn:amc --output "$HOME/Videos" --log-file amc.log --action copy --conflict override -non-strict --def artwork=y "ut_dir=$TORRENT_PATH/$TORRENT_NAME" "ut_kind=multi" "ut_title=$TORRENT_NAME"

Open Deluge -> Preferences -> Plugins and activate the Execute plugin. Then go to Preferences -> Execute, add a new Torrent Complete event and set it to call our shell script:
deluge-execute.png
Deluge / Preferences / Execute / Torrent Complete
deluge-execute.png (34 KiB) Viewed 15645 times
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 06 May 2013, 10:44

Posts: 1
You are a life saver! XD

Thank you so much!

Post 13 May 2013, 23:33

Posts: 1
I have been using this successfully to rename and move my downloads to a specific location. It was working well, and it still is when i download a torrent manually. however, it no longer works with my RSS feed. When a torrent is downloaded through my feed into the same place as a manual torrent, the filebot script runs but it does not rename or move the file. I'm not sure what is going on. any thoughts? I'm using utorrent. Thanks.

Post 14 May 2013, 03:22
rednoah User avatar
The Source

Posts: 2090
Location: 北京

*** If you need help start a new thread and always include cmdline output! ***

Definitely doesn't have anything to do with RSS feeds or whatnot. It's a simple cmdline tool that processes files.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 20 May 2013, 15:57

Posts: 5
Hint for Synology users: The transmission installation sets up a user "transmission" with his own home dir. This home dir is "/usr/local/transmission/var", thus the config files can be found there:

vi /usr/local/transmission/var/settings.json


This will work only if logged in as root. As admin, you'll have to prefix that with sudo, as most linux users will already know (sudo requires some extra setup on Synology though, you'll have to google for that or pm me).
@rednoah: If you think this is the wrong place for this extra info, feel free to move or delete the posting.


Return to Scripting and Automation