Board index Scripting and Automation How about sharing your CLI scripts?

How about sharing your CLI scripts?

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

FileBot has introduced it's own integrated Groovy script engine so you can easily script things and then share that with people on any platform. So if you have come up with some nice scripts, why not share them with people here?

Script Index:

All scripts and Change Logs are on GitHub:
https://github.com/filebot/scripts

TIP: Scripts listed here can easily be called via -script fn:name. FileBot will automatically fetch and cache the code from GitHub.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 10 Dec 2011, 10:16
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
  1. Unrar completed downloads and delete archive volumes after extraction
  2. Fetch subtitles
  3. Sort/move/rename files into the given folder structure
  4. Notify XBMC about updates
:idea: This script is only an example. Learn from it and rewrite it for your needs. :idea:

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

Post 10 Dec 2011, 10:25
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
  1. Write media info of all video files in the given folder and subfolders to an easily readable CSV file (e.g. open in Excel)
Usage:
filebot -script fn:mi /path/to/media/ "MediaIndex.csv"

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

@Deprecated Whatever it is you're trying to do, these scripts here are probably not a good solution, and the amc script is always the best option for any sort of automation task.

For this tasks there there's actually two different scripts. One that actually hooks into the OS watching folders for changes (requires Java 7) and one that just organized everything in now and then in an predefined interval.

:idea: Almost all downloaded applications support calling a cmdline tools on completed downloads, so you could for example call the amc script, and this way of doing things should always be preferred over the watcher script here. Likewise using the amc script as scheduled task is preferred over using the housekeeping script.

:!: Note that these two scripts here are console-interactive so you must not redirect I/O

:arrow: watcher.groovy
Description:
  1. Hook into the OS and recieve File modification events. Start organizing files once there are no changes for more than 5 seconds
  2. The script supports extracting archives, downloading subtitles and organizing video files. Each feature can be enabled or disabled by setting or not setting the -extract, -get-subtitles and -rename cmdline flags.
Usage:
filebot -script fn:watcher -extract -rename /path/to/completed/ --output /final/destination/ --format "TV Shows/{n}/Season {s}/{n} {sxe} {t}" --db TheTVDB

Download Script:
http://filebot.net/scripts/watcher.groovy


:arrow: housekeeping.groovy
Description:
  1. Watch folder by checking for new files every 5 minutes
  2. The script supports extracting archives, downloading subtitles and organizing video files. Each feature can be enabled or disabled by setting or not setting the -extract, -get-subtitles and -rename cmdline flags.
Usage:
filebot -script fn:housekeeping -extract -rename /path/to/completed/ --output /final/destination/ --format "Movies/{n} {y}/{n} ({y}){" CD$pi"}" --db TheMovieDB

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
  1. Download artwork for all your TV Shows from TheTVDB. Fetch tvshow nfo, series and season artwork and save files according to XBMC standards.
  2. Disable confirmation dialogs via -non-strict option (on headless machines this is the default).

Usage:
filebot -script fn:artwork.tvdb /path/to/tvshows/


Options:
--q name to force search query manually instead of auto-detection
--conflict override to fetch artwork from scratch and not just missing artwork
-non-strict to disable user-interaction and run headless

Notes:
* Episodes are expected to be organized into Show/Season N/Episode XY structure. The TV Show will be auto-detected from files and the folder structure.

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
  1. Download artwork for all your Movies from TheMovieDB. Fetch Movie nfo and all kinds of artwork and save files according to XBMC standards.
  2. Disable GUI tv series confirmation dialogs via -non-strict option (on headless machines this is the default).

Usage:
filebot -script fn:artwork.tmdb /path/to/movies/


Options:
--conflict override to fetch artwork from scratch (not just missing artwork)
-non-strict to disable user-interaction and run headless

Notes:
* Movies are expected to be organized into folders. The movie is determined using the name of the parent folder of each video file.

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

Post 04 Mar 2012, 04:20
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Sort out various movie and tv series files that are all in the same folder.

1. Check each file and figure out whether it is a movie file or an episode file and handle it accordingly.
2. Move / Rename according to the given movie or episode naming scheme.

Note:
Even if there is very little information (e.g. movie name without year, series name and episode title without SxE or original airdate) this script will still work, except there is multiple options (e.g. Serenity.mkv => Serenity (2003), Serenity (2005), etc) in which case you may need to specify -non-strict.

filebot -script fn:sortivo <folder> [-non-strict] [--output path/to/folder]

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

Post 26 Apr 2012, 16:34
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Here's a script that you can use with µTorrent as "Run program when torrent finishes" command to automatically sort out your downloads. Basically it's a combination of sorty, sortivo, artwork.* plus some code for µTorrent specific input.

The utorrent-postprocess / amc script has out grown these little scripts here and has become a key filebot feature by itself. It's got it's own thread here now: viewtopic.php?f=4&t=215&p=1561#p1561
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 21 Jul 2012, 09:50
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
  1. Delete clutter files like artwork, samples, etc in folders that have been left over after moving video files.
  2. Won't touch any file in folders where there is at least one video file.

Usage:
filebot -script fn:cleaner /path/to/media/


Options:
--action test only print files that would be deleted, but don't actually do anything
--def root=y Delete given folder as well if left empty
--def "exts=jpg|nfo|etc" pattern for what extensions will be cleansed
--def "terms=sample|trailer|etc" pattern for for what paths will be cleansed (only applies to files smaller than 100 MB)

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

Post 13 Oct 2012, 04:58
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
Regular-expression based mass-rename utility, FileBot style! Find & Replace is applied to the absolute path and not just the filename so you can restructure your folder hierarchy as well.

Simple Usage:
filebot -script fn:replace --def "e=.eng.srt" "r=.srt" /path/to/files


Advanced Usage:
filebot -script fn:replace --action copy --filter "[.]srt$" --def "e=[.](eng|english)" "r=.en" /path/to/files


Options:
--action test only print files that would be moved/copied
--conflict override allow override destination file if it already exists, otherwise it'll be skipped
--filter pattern process only files matching the given pattern

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
This simple rename script will run through all folders and rename process everything folder by folder. It's pretty much like running filebot -rename <folder> for each folder. There is series/movie detection but it's very basic, so it's recommended to force a specific mode via setting --db <datasource>.

Rename episode or movie files:
filebot -script fn:renall "path/to/media" -non-strict


Rename movie folders:
filebot -script fn:renall "path/to/movies" -non-strict --db TheMovieDB --def target=folder


It's highly recommended to first do a dry-run in TEST MODE and see what would happen. Here's the options for that:
--action test --log info


Options:
--def target=folder rename movie folders as a whole instead of the files inside. This mode requires that each movie is already placed in its own folder.

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

Post 13 Nov 2012, 12:41
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
FileBot keeps an internal history of all rename operations in case you want to revert files to their original names or just want to find out the original name of a given file. Here's a script to help with that.

Print the entire rename history:
filebot -script fn:history

Print rename history for the given files or folders:
filebot -script fn:history "X:/path/to/files"

Print all paths that have been renamed by filebot ready to be passed along to xargs:
filebot -script fn:history --format "${to}" --log off


Options:
--format specify your own line format, e.g. --format "${from}\t${to}" if you want tab-separated paths

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
FileBot keeps an internal history of all rename operations in case you want to revert files to their original names. Run this script on the specified file or folder and revert all files to their original names.

Revert files to their original paths:
filebot -script fn:revert /path/to/files


Options:
--action define revert operation, e.g. --action move (default) will move files back to their original location whereas --action rename will only change the filename back to the original filename but keep the file in it's current folder. You can run the script in test mode via --action test.

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

Post 06 Dec 2012, 20:37
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
Here's a script for automatically updating your MyEpisodes profile. On http://www.myepisodes.com you can keep track of your favorite shows, what episodes you have already aquired/watched and quickly check just how much time you've been wasting on watching TV. If your files are already reasonably well-named you can just run this script and it will add all your shows that are not on your list yet and tick each episode you have as 'acquired'.

Add shows and mark episodes as 'acquired':
filebot -script fn:update-mes "X:/path/to/episodes" --def login=user:pwd addshows=y


Options:
--def addshows=y|n auto-add new shows to your list or just ignore any show that is not on your list
--def tick=acquired|seen define whether episodes should be ticked as 'acquired' or 'watched'

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
If extended attributes are enabled and supported on your platform and filesystem FileBot will store original filename and episode/movie metadata into extended attributes for future reference by FileBot or other applications. This script allows you to view and clear these extended attributes.

View xattr for files:
filebot -script fn:xattr /path/to/files

Clear xattr from files:
filebot -script fn:xattr --action clear /path/to/files


Options:
--action clear Display and then delete xattr from all given files

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

rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
You may find yourself in the situation where you have Anime episodes with absolute numbers and need to convert to SxE numbering for XBMC or other media centers. The trick is to first match/rename using absolute numbers and adding title/date so you can then in a second step match by title/date and rename with SxE information. This script will take care of all of that.

Convert Absolute to SxE numbers:
filebot -script fn:abs2sxe /path/to/anime --log off


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

Post 02 Apr 2014, 10:30
rednoah User avatar
The Source

Posts: 4737
Location: Taipei

Description:
If you want to download subtitles for more than just a single folder then -get-subtitles -r in one batch with many many files can be a bad idea. Instead it is recommended you do -get-subtitles per folder which makes things much more reliable when fetching large amounts of subtitles.

This script will process media folder by folder, ignore all video files where the container already contains subtitles, and it is possible to process only newer files by specifying an age limit.


Fetch subtitles for all files that have recently been created:
filebot -script fn:suball /path/to/media -non-strict --def maxAgeDays=7


Options:
--def maxAgeDays=7 set a max-age for files that will be processed, older files will be ignored


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


Posts: 4
SABnzbd+ Integration

I posted this in the forums but figured I would post here also

Features:
When SABnzbd is finished downloading it moves the file to the show/movie folder and then deletes any files/folders left behind and sends pushover notification upon completion

#!/bin/bash

# SABnzbd Post Processing Script - www.Filebot.net "AMC" Script

FILE_PATH=$1
FILE_NAME=$3

filebot -script \
   fn:amc \
   --output "/path/to/your/media" \
   --log-file amc.log \
   --action move \
   --conflict override -non-strict \
   --def music=n \
   --def xbmc=127.0.0.1 \
   --def plex=127.0.0.1 \
   --def pushover= \
   --def artwork=y \
   --def subtitles=en \
   --def clean=y \
   --def "exts=jpg|nfo|srv|srr|nzb|sfv|idx|sub|txt|part01|part02|par1|par2" \
   --def "terms=sample|trailer|etc" \
   --def "ut_dir=$FILE_PATH" \
   --def "ut_kind=multi" \
   --def "ut_title=$FILE_NAME"


Download Script
http://pastebin.com/download.php?i=cmRVkhwY


Return to Scripting and Automation