Page 1 of 1

Automated Media Center

Posted: 01 Aug 2012, 13:04
by rednoah
Overview:

The amc script will automatically organize your media. It's a simple command-line tool that can be called manually or by other tools on one or many files. It'll fully automatically organize your 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 process them accordingly
  3. Fetch subtitles and transcode them to SubRip / UTF-8
  4. Organize movies, episodes and music files into a new file and folder structure according to the {plex} format naming scheme:
    • Movies will be sorted into {output}/Movies/Name (Year)/Name (Year).ext
    • Episodes 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 Plex, Kodi or Emby to refresh the video library
  7. Send a report about newly added files via Email or PushBullet
There's setup instructions for µTorrent, qBittorrent, rTorrent, Deluge, Transmission, Vuze, JDownloader and Automator. Since filebot is a simple command-line tool you can make it work with any software that can run external programs, or just call it every once in a while with cron.


Setup Instructions:

1. Set Location of Downloaded Files and make sure to move complete downloads into a separate folder.

2. Set Run Program to make your client call filebot on newly completed downloads.

e.g. µTorrent ➔ Run Program ➔ Run this program when torrent finishes:

Code: Select all

filebot -script fn:amc --output "X:/Media" --action duplicate --conflict skip -non-strict --log-file amc.log --def unsorted=y music=y artwork=y "ut_label=%L" "ut_state=%S" "ut_title=%N" "ut_kind=%K" "ut_file=%F" "ut_dir=%D"
3. Change --output to where you want to copy / organize your files. Depending on your client, you may also need to adjust the --def ut_* variables.

4. Done! This took take less than a minute. Now wait and enjoy how things will be organized fully automatically.

Image
µTorrent / Preferences / Directories

Image
µTorrent / Preferences / Run Program / Run this program when torrent finishes


Run from the command-line:
Want to try it out first? Running directly from command-line is even easier and if you set --action test you can do a dry-run and see if everything gets matched up correctly:

Code: Select all

filebot -script fn:amc --output "/path/to/output" --action duplicate -non-strict "/path/to/input" --log-file amc.log --def excludeList=amc.txt
  • If you run this script manually, you can set --mode interactive to enable console-interactive mode.
  • If you run this script automatically in intervals every hour or every day, then you must set --def excludeList or you will get banned.

Options:
--def music=y Process music files
--conflict skip Never overwrite existing files
--conflict auto Do overwrite existing files if new files are better
--def subtitles=en,de,fr Download subtitles
--def artwork=y Fetch artwork and generate nfo files
--def plex=host:token Rescan Plex library (see authentication token)
--def kodi=host:port Rescan Kodi library
--def emby=host:apikey Rescan Emby library
--def pushbullet=apikey Send report via PushBullet
--def pushover=userkey Send notification via Pushover
--def discord=webhook Send notification via Discord
--def gmail=username:password Send report via Gmail (see App Password)
--def mail=host:port:from:username:password Send report via SMTP (NOTE: Linux and macOS users may prefer the send-email-log shell script to capture and send console output)
--def mailto=email Send Email report to this address
--def reportError=y Send Email report on error
--def storeReport=/path/to/folder Save reports
--def extractFolder=/path/to/folder Extract archives to this folder
--def skipExtract=y Skip archives
--def deleteAfterExtract=y Delete archives after extraction
--def clean=y Delete left behind empty folders and clutter files
--def exec="echo {quote f}" Run program on newly processed files
--def unsorted=y Process unidentified files
--def ignore=regex Ignore file paths
--def minFileSize=0 Skip small files (in bytes; 50 MB by default)
--def minLengthMS=0 Skip short videos (in millis; 10 minutes by default)
--def excludeLink=y Skip symlinks and hardlinks where the link count is more than 1
--def excludeList=amc.txt Keep a list of already processed file paths to be skipped in future runs (please enable this if you process the same folder repeatedly)


Change how files will be organized and renamed:
This script uses multiple format expressions, so the simple --format option is not supported. You can override the default naming schemes via --def seriesFormat, animeFormat or movieFormat. Relative paths will be resolved against --output and you can use absolute paths if you want to use multiple drives.

Code: Select all

--def movieFormat="M:/{plex}" seriesFormat="S:/{plex}" animeFormat="T:/{plex}" musicFormat="N:/{plex}"
  • Start with the {plex} format and then modify your custom format bit by bit to fit your needs.
  • Make sure that you understand how format expressions work and what bindings such as {n} or {fn} do exactly.
  • Use @file syntax to read complex arguments from a text file.

Common Problems
  • Location of Downloaded Files (--output) must not end with backslash \ because the value gets passed through via the %D variable, and so the final backslash \ will escape the double-quote " and mess up everything. Please use / as separator and not \ because the latter is also used to escape characters. (see Cmdline and Argument Passing)
  • You can (and should) force Movie / Series / Anime mode or force ignore files via labels, e.g. label as Movie to force TheMovieDB, Series to force TheTVDB, Anime to force AniDB, or other to ignore all files. Alternatively, standard folder names such as Movies / TV Shows / Anime may also be used to force a specific mode.
  • Anime are inherently TV Shows, so Anime will only be detected as Anime and processed with AniDB if the files have Anime-like characteristics.
  • You must not use your input folder %D as --output folder.
  • You must not use the filesystem root (e.g. X:\ or /) as input or --output folder.

Advanced Fine-Tuning
You can (and should) force Movie / Series / Anime mode by setting --def ut_label accordingly, and you can further define your own --filter rules to fine-tune matching to your exact needs, and avoid mismatches. For example, if one show is confused with another due to bad naming or missing data you can simply exclude the bad one, or if you only process recently aired episodes, then you could exclude episodes that have not aired recently from matching.

e.g. if you only process recently aired episodes you can virtually guarantee 100% auto-detection accuracy by adding simple filter rules such as these:

Code: Select all

--filter "age < 5" --def "ut_label=TV"
e.g. if you're a typical user, and find a simple age filter too restrictive, then this slightly augmented age filter rule might be the magic bullet that fixes all your problems:

Code: Select all

--filter "age < 5 || 5 <= model.age.min()" --def "ut_label=TV"
--filter rules are extremely flexible so more complex scenarios, such as applying certain filters only for certain labels or files, is fully supported.


Troubleshooting
If something is not working, please read the Notes above, then run the command manually in a new console window to see what is happening. You CANNOT run the command without replacing the VARIABLES. The variables have to be replaced with actual values first.

e.g.

Code: Select all

filebot -script fn:amc --output "D:/Organized Media" --log-file amc.log --action duplicate --conflict override -non-strict --def "ut_dir=D:\Media\Avatar" "ut_file=" "ut_kind=multi" "ut_title=Avatar" "ut_label=" "ut_state=5"


Logs
Please check the log once in a while:

Code: Select all

filebot -script fn:logs
:idea: The --log-file is located in the application data folder by default. Please read the manual for details.

[Transmission] Setup for Linux or Mac with Transmission

Posted: 06 Feb 2013, 07:28
by rednoah
Since the utorrent-postprocess integration 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.


This guide assumes that you have already installed the filebot command-line tools so make sure filebot -version works.


1. Create On Torrent Completion Script

Create a On Torrent Completion shell script transmission-postprocess.sh that'll call filebot like this and make sure to chmod +rx it:

Code: Select all

curl -O https://raw.githubusercontent.com/filebot/plugins/master/bash/transmission-postprocess.sh
chmod +rx transmission-postprocess.sh
2. Set Transmission to call our shell script on completion

Setup via GUI on Mac:
Open Transmission ► Preferences ► Transfers ► Management and set it to call our script when download completes:
Image

Setup via Terminal on Linux:
Open ~/.config/transmission/settings.json and set it to call our shell script on download complete:

Code: Select all

"script-torrent-done-enabled": true, 
"script-torrent-done-filename": "/path/to/transmission-postprocess.sh",
Transmission Configuration Files:
https://trac.transmissionbt.com/wiki/ConfigFiles

Known Issues:
  • Transmission does not pass along TORRENT_LABEL which can affect detection accuracy

[Deluge] Setup for Linux or Mac with Deluge

Posted: 06 Feb 2013, 09:03
by rednoah
Here's how to set things up with the Deluge BitTorrent Client. Should work on Mac, Linux, BSD, etc.

Create a shell script deluge-postprocess.sh that'll call filebot and make sure to chmod +rx it:

Code: Select all

curl -O https://raw.githubusercontent.com/filebot/plugins/master/bash/deluge-postprocess.sh
chmod +rx deluge-postprocess.sh
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 newly created deluge-postprocess.sh shell script:

Code: Select all

/absolute/path/to/deluge-postprocess.sh
Known Issues:
  • Scripts run as the deluge user so environment variables like $HOME may not work as expected
  • The Deluge Execute plugin does not pass along TORRENT_LABEL which can affect detection accuracy


:!: These instructions DO NOT apply to Microsoft Windows. Integrating FileBot with Deluge for Windows is possible but difficult. Using qBittorrent instead is therefore generally recommended.

[rTorrent] Setup for Linux with rTorrent

Posted: 21 Jul 2013, 05:41
by rednoah
If you're using rTorrent on a headless machine it's just as easy. You just need to edit rtorrent.rc a bit.
  1. Run this command to create a shell script rtorrent-postprocess.sh that'll call filebot and the amc script:

    Code: Select all

    curl -O https://raw.githubusercontent.com/filebot/plugins/master/bash/rtorrent-postprocess.sh
  2. Run this command to make sure that the script is executable:

    Code: Select all

    chmod +rx rtorrent-postprocess.sh
  3. Run this command to edit ~/.rtorrent.rc and add an event.download.finished hook:

    Code: Select all

    echo 'system.method.set_key=event.download.finished,filebot,"execute={'`pwd`/rtorrent-postprocess.sh',$d.get_base_path=,$d.get_name=,$d.get_custom1=}"' >> ~/.rtorrent.rc
Known Issues:
  • The latest revision of rtorrent seems to have introduced breaking changes in how ~/.rtorrent.rc works. Read this thread for details.

[qBittorrent] Setup for Windows, Linux and Mac OS X

Posted: 12 May 2014, 17:30
by rednoah
The qBittorrent setup is pretty similar to µTorrent. Just paste the following command into the Run an external program on torrent completion setting.


Instructions for Windows:

Options ► Downloads ► Run an external program on torrent completion:

Code: Select all

filebot -script fn:amc --output "X:/Media" --action duplicate --conflict skip -non-strict --log-file amc.log --def excludeList=amc.excludes --def unsorted=y music=y artwork=y "ut_label=%L" "ut_title=%N" "ut_kind=multi" "ut_dir=%F"

Instructions for Mac and Linux:

Options ► Downloads ► Run an external program on torrent completion:

Code: Select all

filebot -script fn:amc --output "/path/to/media" --action duplicate --conflict skip -non-strict --log-file amc.log --def excludeList=amc.excludes unsorted=y music=y artwork=y "ut_label=%L" "ut_title=%N" "ut_kind=multi" "ut_dir=%F"
Image

:idea: You may need to use the absolute path to the executable (e.g. /usr/local/bin/filebot) if you get filebot: command not found issues.

:idea: If you are using qBittorrent 3.* then the %variables may need to be adjusted:

Code: Select all

--def "ut_label=none" "ut_title=%n" "ut_kind=multi" "ut_dir=%f"

Help

Posted: 28 Oct 2014, 10:25
by rednoah
If you're having any issues...

1. Make a NEW thread
2. Include log output
3. Include full paths when reporting mismatches

thx :ugeek: